问题描述
我从Mac OS X系统尝试交叉编译一个简单的C ++ 11程序,但是 clang ++
甚至找不到简单的标头:
From a mac os x system I am trying to cross compile a simple C++11 program but clang++
fails to find even simple headers:
test.cc
#include <string>
int main(int argc, char *argv[])
{
return 0;
}
这是错误
$ clang++ --std=c++11 --stdlib=libc++ test.cc -target i386-win32 -o test
clang: warning: argument unused during compilation: '--stdlib=libc++'
test.cc:1:10: fatal error: 'string' file not found
#include <string>
^
1 error generated.
在没有 -target
的情况下编译就很好论据。
It compiles just fine without the -target
argument.
我也尝试了不使用-stdlib = libc ++
参数,但这没有帮助。
I also tried without the --stdlib=libc++
argument and that didn't help.
编辑
事实证明,仅添加标志就不能真正交叉编译到Windows:
EDITTurns out you can't really cross compile to windows just by adding a flag:
$ clang++ -std=c++11 -v test.cc -target i386-win32 -o test
Apple LLVM version 7.0.0 (clang-700.0.72)
Target: i386--windows-msvc
Thread model: posix
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple i386--windows-msvc -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name test.cc -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -target-cpu pentium4 -target-linker-version 253.2 -v -dwarf-column-info -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.0 -internal-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.0/include -internal-isystem C:/Program Files/Microsoft Visual Studio 10.0/VC/include -internal-isystem C:/Program Files/Microsoft Visual Studio 9.0/VC/include -internal-isystem C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include -internal-isystem C:/Program Files/Microsoft Visual Studio 8/VC/include -internal-isystem C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/drninjabatman/Scratch -ferror-limit 19 -fmessage-length 181 -mstackrealign -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 -fdelayed-template-parsing -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/j_/56ztdh452d95t2wtk6zx0j6w0000gn/T/test-42e69a.o -x c++ test.cc
clang -cc1 version 7.0.0 based upon LLVM 3.7.0svn default target x86_64-apple-darwin14.5.0
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:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.0/include
End of search list.
test.cc:1:10: fatal error: 'string' file not found
#include <string>
^
1 error generated.
推荐答案
clang是一个出色的交叉编译器,但正如您所指出的那样除非您有其余所需的东西,否则交叉编译器几乎没有用。至少您需要
clang is an excellent cross compiler but as you rightly point out, a cross compiler is of little use unless you have the rest of the stuff needed. At minimum you'll need
- 目标库的头文件
- 已编译的库对于目标
- 能够将目标文件和库链接到可执行文件的链接器
您可以在几个地方找到所有这些东西。如果您需要预打包的一组工具,可以查看。 ELLCC是基于clang的交叉编译工具链。它包括
There are several places that you can find all of these things. If you'd like a set of tools pre-packaged, you could take a look at ELLCC. ELLCC is a cross compilation tool chain based on clang. It includes
- ecc-基于clang的ARM,Mips,PowerPC和x86编译器
- 用于Linux和Windows的头文件和预编译的C和C ++标准库
- 一组配置为处理所有目标的binutils(汇编器,链接器等)
这可以让您做自己想做的事情:
This allows you to do exactly what you want:
% ecc -target x86_64-w64-mingw32 test.cc -o test.exe
% file test.exe
test.exe: MS-DOS executable PE for MS Windows (console), Mono/.Net assembly
% ecc -target aarch64-linux-eng test.cc -o test
% file test
test: ELF 64-bit LSB executable, version 1 (SYSV), statically linked, not stripped
%
按照链接以获取在Linux,Windows或Mac OS X上运行的预编译工具。
Follow the download link to get pre-compiled tools that run on Linux, Windows, or Mac OS X.
这篇关于Clang ++找不到任何stdlib标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!