[LLVMdev] Making dll's on MinGW.

Óscar Fuentes ofv at wanadoo.es
Fri Feb 1 12:53:29 PST 2008


As the LLVM build does not create dll's on Windows, two problems arises:

 1. Static linking creates big executables.

 2. Link time is long.

We can create dll's on MinGW using a feature of binutils that mimics .so
files on GNU/Linux.

The process is very simple. On a MSYS or Cygwin shell (make sure MinGW
binaries are on the path before Cygwin's). Read all message before
rolling up your sleeves.

I'm using LLVM 2.1, g++ 4.2.1-dw2 (mingw32-2), ld 2.18.50.20080109.

 1. Go to the /lib directory of your LLVM install.

 2. Make a subdirectory there. Let's call it `temp'.

 3. Copy to `temp' all LLVM object files that you need on your project
 (LLVMX86.o, LLVMExecutionEngine.o and LLVMJIT.o for me).

 4. cd to `temp'.

 5. Execute this:  for f in ../lib*.a ; do ar x $f ; done

    If you are working on the LLVM's debug install, do:

rm Debugger.o ProgramInfo.o RuntimeInfo.o SourceFile.o SourceLanguage*.o

 6. Then:
   g++ -shared --export-all-symbols -o LLVM.dll *.o -lpsapi -ldbghelp

   This may require several minutes and use approx. 0.5 GB.

   If you are working on LLVM's debug install, it is a good idea to name
   the dll LLVMd.dll or something to differentiate it from the release
   build.

 7. This creates LLVM.dll. Move it to LLVM's /lib directory. Put a copy
 somewhere on your PATH.

 8. On your application's makefile, remove all references to files on
 LLVM's /lib directory (libraries, LLVMX86.o, etc) and just use -lLLVM.

This way we have a single big dll that we use just like an .so file on
GNU/Linux. Link times decreases dramatically (using the debug build,
link time decreases to ~10%).

Caveats: For some reason, while doing this process for the debug intall
of LLVM, the creation of the dll fails with this:

d:/dev/lib/llvm-2.1-d/lib/m $ g++ -shared --export-all-symbols -o LLVMd.dll *.o -lpsapi -ldbghelp
ProgramInfo.o: In function `~SourceFileInfo':
d:/dev/lib/llvm-2.1/lib/Debugger/ProgramInfo.cpp:123: multiple definition of `llvm::SourceFileInfo::~SourceFileInfo()'
MachineModuleInfo.o:d:/dev/lib/llvm-2.1/include/llvm/CodeGen/MachineModuleInfo.h:865: first defined here
collect2: ld returned 1 exit status

This is "fixed" by ignoring libLLVMDebugger.a or its contents on step 5,
as indicated. SourceFileInfo does not declare a destructor, but one is
defined in ProgramInfo.cpp. I don't know wath is going here.

It would be good to create dll's "the Windows way", which works for VC++
too, but this requires modification of the source code. I expect to
address this on a future message.

HTH.

-- 
Oscar



More information about the llvm-dev mailing list