如何使用clang和distcc在不同架构的从属服务器上编译(例如Mac / Linux)

时间:2017-08-17 05:29:07

标签: c++ clang distcc

我想使用distcc将代码从我的Mac编译到一堆Linux主机,但我无法弄清楚如何制作所有内容"排队"。我已经成功地使用了从Mac到Mac的distcc,所以我对如何进行设置有一个大概的了解。

我正在使用Clang 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
    >;

我不明白,如果我做了一些根本错误的事情,或者是否有一些我想知道的小事,那就是让Linux编译器采取不同的行动。

我确保将Linux上的Clang放在同一个命名目录中,现在我只收到-fblocksunused during compilation -stdlib=libc++个问题。

我可以编译所有内容(虽然有警告)但是当它链接时,我得到:

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

2 个答案:

答案 0 :(得分:1)

添加-target标志可以解决所有问题!在我的情况下,对于Mac OS X v10.11(El Capitan),目标三元组是:

-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帮助解决这个问题!

答案 1 :(得分:1)

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

Cross-compilation using Clang