[cfe-dev] Cross compiling for windows with clang

Reid Kleckner rnk at google.com
Sat May 18 07:51:03 PDT 2013


Since you're using the mingw linker, you should probably target mingw.  Try
using i386-pc-mingw32 as the triple.  I think using win32 as the os assumes
you want the Visual Studio toolchain by default, and I don't recall what
else controls it.


On Sat, May 18, 2013 at 10:29 AM, Stephen Kelly <steveire at gmail.com> wrote:

>
> 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.
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130518/85924945/attachment.html>


More information about the cfe-dev mailing list