[cfe-dev] clang: How to compile a simple program to a DLL

Victor Martin Ulloa pelotoescogorciao at yahoo.es
Thu Nov 5 19:53:15 PST 2009


I want to compile and link this function

__attribute__((dllexport)) int __cdecl myAdd ( const int a, const int b )
{
   return a+b;
}

into a myAdd.dll ( yes, a dynamic library ).

For that, I'm using the following commands:

clang-cc.exe -v -emit-llvm-bc -o myAdd.bc myAdd.c
llvm-ld.exe -native -link-as-library -o myAdd.dll myAdd.bc

but when I open the myAdll.dll with the Win32 Dependency Walker ( depends.exe ) it says it's not a valid DOS/Windows PE file...

What I'm doing wrong, pls? How can I use cland and LLVM to compile a .c into a Win32 DLL in a way that could be called after by other program using GetProcAddress()/C function pointer?

thx.





      




More information about the cfe-dev mailing list