[LLVMdev] LLVM as a DLL

Morten Ofstad morten at hue.no
Wed May 14 07:56:32 PDT 2008


Óscar Fuentes wrote:
> Owen Anderson <resistor at mac.com> writes:
> 
>> On May 13, 2008, at 6:38 PM, Óscar Fuentes wrote:
>>> Last time I checked, building LLVM on Windows (MinGW or MSVC) did not
>>> produce dlls.

... Because dlls are in many ways different from unix shared libraries, so it's not as easy as you think. First of all, 
dlls need you to specify with __declspec(dllexport) which symbols to export and with __declspec(dllimport) which symbols 
to import. Usually you do this by making a macro LLVM_EXPORTS which is defined when you build your dll and then prefix 
all exported functions in header files with LLVM_API.

#ifdef LLVM_EXPORTS
#define LLVM_API __declspec(dllexport)
#else
#define LLVM_API __declspec(dllimport)
#endif

This will uglify the LLVM codebase significantly, but is the most used approach. Another way is to create .def files 
which define explicitly what is exported, but these need to be automatically generated or they will quickly get out of 
sync with the source.

m.



More information about the llvm-dev mailing list