Clang ++无法找到任何stdlib头文件

时间:2015-10-10 17:03:41

标签: cross-compiling header-files clang++

从mac os x系统我试图交叉编译一个简单的C ++ 11程序,但clang++找不到简单的标题:

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参数,它编译得很好。

我也试过没有--stdlib=libc++论证,但没有帮助。

修改 事实证明,只要添加一个标志,你就无法真正交叉编译到Windows:

$ 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.

1 个答案:

答案 0 :(得分:2)

clang是一个优秀的交叉编译器,但正如你正确指出的那样,除非你需要其他东西,否则交叉编译器几乎没用。至少你需要

  • 目标库的头文件
  • 已为目标
  • 编译的库
  • 能够将目标文件和库链接到可执行文件的链接器

有几个地方可以找到所有这些东西。如果您想预先打包一套工具,可以查看ELLCC。 ELLCC是一个基于clang的交叉编译工具链。它包括

  • ecc - 基于clang的ARM,Mips,PowerPC和x86
  • 编译器
  • 用于Linux和Windows的头文件和预编译的C和C ++标准库
  • 一组配置为处理所有目标的binutils(汇编程序,链接程序等)

这使您可以完全按照自己的意愿行事:

% 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
%

按照download链接获取在Linux,Windows或Mac OS X上运行的预编译工具。