简体   繁体   English

使用linux上的mingw与clang交叉编译

[英]cross-compile with clang using mingw on linux

I was trying to compile under linux for windows. 我试图在linux下为windows编译。 I have installed binutils multilib for linux and w64-mingw. 我已经为linux和w64-mingw安装了binutils multilib。 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. 如果我用x86_64-w64-mingw-gcc编译一切正常,但是如果我使用clang -target x86_64-w64-mingw或x86_64-windows-gnu编译器给我很多警告和windows.h的包含错误。

What is the problem? 问题是什么? Clang does not support mingw binutils? Clang不支持mingw binutils?

PS I also are interested in cross-compilig for freebsd, where can I found binutils for targeting freebsd? PS我也对freebsd的cross-compilig感兴趣,我在哪里可以找到针对freebsd的binutils?

Thank you very much in advance :) 非常感谢你提前:)

-target isn't enough, you also need to specify the include directories, ie: -target是不够的,你还需要指定include目录,即:

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. 您可能会发现我的项目很有用: https//github.com/tpoechtrager/wclang - 该工具正在执行所有令人讨厌的包含目录搜索。

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. 我的ELLCC项目包与库有关,包括可以针对多个目标的文件,包括使用MinGW-64包含的各种Linux目标和Windows以及库。 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 . 我有一个稍微修改过的clang版本,我称之为ecc ,它支持配置文件以指定获取包含文件的位置,如何链接等.clang / mingw的典型配置文件如下所示 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 我修改了clang的-target选项以检查适用的配置文件并使用它(如果存在)。例如,要以64位Windows为目标,使用命令行

ecc -target x86_64-w64-mingw32 hello.c

To compile the same program for eg an ARM Linux system, you can use a command line like 要为例如ARM Linux系统编译相同的程序,可以使用命令行

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 . 各种Linux主机和Windows预编译的二进制包可用 The packages include binutils and GDB that support all the targets. 这些软件包包括支持所有目标的binutils和GDB。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM