[cfe-dev] Cross compiling for windows with clang

Stephen Kelly steveire at gmail.com
Sat May 18 07:29:36 PDT 2013


I have now also tried to cross compile to windows with clang.

 $ clang -v -target i386-pc-win32 -c main.c 

doesn't have any built in include paths, but I can supply them as copied 
from the output of i686-w64-mingw32-gcc -v -c main.c.

 $ clang -v -target i386-pc-win32 -I/usr/lib/gcc/i686-w64-
mingw32/4.6/include -I/usr/lib/gcc/i686-w64-mingw32/4.6/include-fixed -
I/usr/lib/gcc/i686-w64-mingw32/4.6/../../../../i686-w64-mingw32/include -c 
main.c
ignoring nonexistent directory "/usr/bin/../lib/clang/3.2/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 
10.0/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 
9.0/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 
9.0/VC/PlatformSDK/Include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 
8/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 
8/VC/PlatformSDK/Include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/i686-w64-mingw32/4.6/include
 /usr/lib/gcc/i686-w64-mingw32/4.6/include-fixed
 /usr/lib/gcc/i686-w64-mingw32/4.6/../../../../i686-w64-mingw32/include
End of search list.

seems to work fine. Should clang not add the windows paths to the search 
list if host != Windows? It tries to use link.exe to link too, which 
obviously doesn't work:

 $ clang -v -target i386-pc-win32 main.o 
 Ubuntu clang version 3.2-1~exp9ubuntu1 (tags/RELEASE_32/final) (based on 
LLVM 3.2)
 Target: i386-pc-win32
 Thread model: posix
 "link.exe" -out:a.out -defaultlib:libcmt -nologo main.o
 clang: error: unable to execute command: No such file or directory
 clang: error: linker command failed due to signal (use -v to see 
invocation)

however, I can link it with i686-w64-mingw32-gcc main.o and execute it in 
wine.


Next up, a dll:

 stephen at hal:/tmp$ cat lib.h 

 #ifdef BUILDING_EXAMPLE_DLL
 #define EXAMPLE_DLL __declspec(dllexport)
 #else
 #define EXAMPLE_DLL __declspec(dllimport)
 #endif

 int EXAMPLE_DLL myveryeasymethod(void);

 stephen at hal:/tmp$ cat lib.c 

 #include "lib.h"

 int myveryeasymethod(void)
 { return 42; }


Compiling with -DBUILDING_EXAMPLE_DLL works fine.

 $ i686-w64-mingw32-gcc -shared lib.o -Wl,--out-implib,libexample_dll.a -o 
example_dll.dll 
 Warning: .drectve `/EXPORT:_myveryeasymethod' unrecognized

That warning does not appear when the file is compiled with gcc. There is a 
similar warning when building c++:

 $ i686-w64-mingw32-g++ -shared lib.o -Wl,--out-implib,libexample_dll.a -o 
example_dll.dll
 Warning: .drectve `/EXPORT:myveryeasymethod()' unrecognized

What do these mean? Should I file a bug report?

Thanks,

Steve.





More information about the cfe-dev mailing list