如何使用clang和distcc编译不同体系结构的从站(例如mac/linux)

问题描述:

我想使用distcc将我的Mac中的代码编译到一堆Linux主机,但我无法弄清楚使一切“排队”。我已经成功地使用了从Mac到Mac的distcc,所以我对如何设置东西有一个总体思路。如何使用clang和distcc编译不同体系结构的从站(例如mac/linux)

我使用的是铛4.0,并已安装并在Mac和Linux上工作。下面的命令编译罚款不distcc开头,但加入的distcc后,我得到了以下问题:

distcc /Users/xaxxon/Downloads/clang+llvm-4.0.0-x86_64-apple-darwin/bin/clang++ -I/usr/local/include -I/Users/xaxxon/v8toolkit/./include -I/Users/xaxxon/v8/include -stdlib=libc++ -g -Werror=return-type -g -std=gnu++1z -o CMakeFiles/v8toolkit_static.dir/src/v8toolkit.cpp.o -c /Users/xaxxon/v8toolkit/src/v8toolkit.cpp 

我不知道被什么拾起了编译器在Linux上,我也不知道该怎么找出。有可能它会选择gcc而不是clang。

我首先考虑的是这样的:

clang: warning: argument unused during compilation: '-stdlib=libc++' 

我的第一个错误是:

In file included from /Users/xaxxon/v8toolkit/src/v8toolkit.cpp:5: 
In file included from /usr/include/assert.h:44: 
In file included from /Users/xaxxon/Downloads/clang+llvm-4.0.0-x86_64-apple-darwin/bin/../include/c++/v1/stdlib.h:94: 
/usr/include/stdlib.h:250:20: error: blocks support disabled - compile with -fblocks or pick a deployment target that supports them 
int atexit_b(void (^)(void)) __attribute__((availability(macosx,introduced=10.6))); 

下一个错误,我得到(成为第一个错误,如果我手动添加-fblocks到编辑命令(这是本地Mac版本不需要)是:

/Users/xaxxon/Downloads/clang+llvm-4.0.0-x86_64-apple-darwin/bin/../include/c++/v1/__tuple:289:13: error: unknown type name '__type_pack_element' 
    typedef __type_pack_element<_Ip, _Types...> type; 
      ^
/Users/xaxxon/Downloads/clang+llvm-4.0.0-x86_64-apple-darwin/bin/../include/c++/v1/__tuple:289:32: error: expected member name or ';' after declaration specifiers 
    typedef __type_pack_element<_Ip, _Types...> type; 
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^ 
/Users/xaxxon/Downloads/clang+llvm-4.0.0-x86_64-apple-darwin/bin/../include/c++/v1/__tuple:356:43: error: use of undeclared identifier '__type_pack_element' 
     typename _ApplyFn::template __apply<__type_pack_element<_Idx, _Types...>>... 
             ^
/Users/xaxxon/Downloads/clang+llvm-4.0.0-x86_64-apple-darwin/bin/../include/c++/v1/__tuple:357:6: error: expected a type 
    >; 

我不明白我是否在做s从根本上说是错误的,或者如果我错过了一些让Linux编译器的行为不同的小东西。

谢谢你的任何提示或建议。

编辑:我只是确保在Linux上有相同的命名目录,现在只能得到-fblocksunused during compilation -stdlib=libc++问题。

EDIT2:我能得到的一切编译(尽管有警告),但是当它链接,我得到:

ld: warning: ignoring file CMakeFiles/v8toolkit_shared.dir/src/debugger.cpp.o, file was built for 
unsupported file format (0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 
0x00 0x00 0x00 0x00 0x00 0x00) which is not the architecture being linked 
(x86_64): CMakeFiles/v8toolkit_shared.dir/src/debugger.cpp.o 

添加-target标志修复一切!在我的情况下,埃尔卡皮坦,目标三重是:

-target x86_64-apple-darwin15.6.0 

为构建命令:

distcc /Users/xaxxon/Downloads/clang+llvm-4.0.0-x86_64-apple-darwin/bin/clang++ -Dv8toolkit_shared_EXPORTS -I/usr/local/include -I/Users/xaxxon/v8toolkit/./include -isystem /Users/xaxxon/v8/include -stdlib=libc++ -g -Werror=return-type -target x86_64-apple-darwin15.6.0 -g -fPIC -std=gnu++1z -o CMakeFiles/v8toolkit_shared.dir/src/v8toolkit.cpp.o -c /Users/xaxxon/v8toolkit/src/v8toolkit.cpp 

你可以得到当前主机的目标键入clang -v

$ clang -v 
clang version 4.0.0 (tags/RELEASE_400/final) 
Target: x86_64-apple-darwin15.6.0 <<==== THIS LINE HERE 
Thread model: posix 
InstalledDir: /Users/xaxxon/Downloads/clang+llvm-4.0.0-x86_64-apple-darwin/bin 

下面的CMake行将抓取(并打印)当前机器的三元组:

# Get the target triple for the current host by calling clang -v and then stripping out the Target: value from its output. CMake regex syntax is quite limited. 
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -v ERROR_VARIABLE CLANG_VERSION_INFO) 
string(REGEX REPLACE ".*Target:[\r\n\t ]*([^\r\n\t]*).*Thread model.*" "\\1" TARGET_TRIPLE ${CLANG_VERSION_INFO}) 
message(STATUS "TARGET TRIPLE: '${TARGET_TRIPLE}' END") 

非常感谢@duskwuff和oftc.net #llvm求助!

只要指定-target标志,甚至可以交叉编译,因为clang是本地交叉编译器。

https://clang.llvm.org/docs/CrossCompilation.html