3

我想使用 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
4

2 回答 2

2

只要指定-targetflag,甚至可以交叉编译,因为Clang是一个原生的交叉编译器。

使用 Clang 进行交叉编译

于 2017-11-08T00:07:13.340 回答
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 帮助解决这个问题!

于 2017-08-17T06:07:14.920 回答