簡體   English   中英

如何使用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主機上,但是我不知道如何使所有內容“對齊”。 從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位於相同的命名目錄中,現在僅unused during compilation -stdlib=libc++問題時得到-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是本機交叉編譯器。

使用Clang交叉編譯

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM