如何使用 clang 和 distcc 在不同架构的从机上编译(例如 Mac/Linux)
How to use clang and distcc to compile on a slave of a different architecture (e.g. Mac/Linux)
我想使用 distcc 将代码从我的 Mac 编译到一堆 Linux 主机,但我不知道如何制作所有东西 "line up"。我已经成功地使用了从 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,现在我只遇到了 -fblocks
和 unused 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
添加 -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 帮助解决这个问题!
只要指定-target
标志,甚至可以交叉编译,因为Clang是原生交叉编译器。
我想使用 distcc 将代码从我的 Mac 编译到一堆 Linux 主机,但我不知道如何制作所有东西 "line up"。我已经成功地使用了从 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,现在我只遇到了 -fblocks
和 unused 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
添加 -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 帮助解决这个问题!
只要指定-target
标志,甚至可以交叉编译,因为Clang是原生交叉编译器。