Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cross-compile with clang using mingw on linux

I was trying to compile under linux for windows. I have installed binutils multilib for linux and w64-mingw. If I compile with x86_64-w64-mingw-gcc everything work, but if I use clang with -target x86_64-w64-mingw or x86_64-windows-gnu compiler give me lots of warnings and a include error for windows.h.

What is the problem? Clang does not support mingw binutils?

P.S. I also are interested in cross-compilig for freebsd, where can I found binutils for targeting freebsd?

Thank you very much in advance :)

like image 947
NickF_93 Avatar asked Mar 11 '15 18:03

NickF_93


2 Answers

-target isn't enough, you also need to specify the include directories, i.e.:

clang -target i686-w64-mingw32 -nostdinc -fno-exceptions -isystem /opt/compiler/llvm-3.6/bin/../lib/clang/3.6.0/include -isystem /opt/compiler/mingw-w64/i686-w64-mingw32/include -isystem /opt/compiler/mingw-w64/i686-w64-mingw32/include/c++/4.9.2 -isystem /opt/compiler/mingw-w64/i686-w64-mingw32/include/c++/4.9.2/backward -isystem /opt/compiler/mingw-w64/i686-w64-mingw32/include/c++/4.9.2/i686-w64-mingw32

You may find my project useful: https://github.com/tpoechtrager/wclang - that tool is doing all the nasty include directory searching for you.

like image 104
Thomas Avatar answered Sep 22 '22 06:09

Thomas


My ELLCC project packages clang with libraries and include files that can target multiple targets, including various Linux targets and Windows using MinGW-64 includes and libraries. I have a slightly modified version of clang, which I call ecc, that supports configuration files to specify where to get include files, how to link, etc. A typical config file for clang/mingw looks like this. I've modified clang's -target option to check for an applicable config file and use it if it exists.For example, to target 64 bit Windows, you use the command line

ecc -target x86_64-w64-mingw32 hello.c

To compile the same program for e.g. an ARM Linux system, you can use a command line like

ecc -target arm-linux-engeabihf hello.c

A complete list of the supported targets is available here. Pre-compiled binary packages for various Linux hosts and Windows are available. The packages include binutils and GDB that support all the targets.

like image 44
Richard Pennington Avatar answered Sep 23 '22 06:09

Richard Pennington