我正在尝试在centos 6上构建一个静态链接的可执行文件clang。我正在使用从源代码编译的gcc4.8.3。
如果我使用cmake选项-DLLVM_BUILD_STATIC=ON
进行编译,则错误为:
CMake Error at cmake/modules/CheckAtomic.cmake:52 (message):
Host compiler appears to require libatomic, but cannot find it.
Call Stack (most recent call first):
cmake/config-ix.cmake:307 (include)
CMakeLists.txt:590 (include)
如果我直接向CMAKE_EXE_LINKER_FLAGS添加-static
标志,则错误为:
ld: dynamic STT_GNU_IFUNC symbol `strcmp' with pointer equality in
`/usr/lib/../lib64/libc.a(strcmp.o)' can not be used when making
an executable; recompile with -fPIE and relink with -pie
如果我直接将-fPIE
添加到CMAKE_CXX_FLAGS,将-Wl,-pie
添加到CMAKE_EXE_LINKER_FLAGS,则错误为:
CMake Error at cmake/modules/CheckAtomic.cmake:52 (message):
Host compiler appears to require libatomic, but cannot find it.
Call Stack (most recent call first):
cmake/config-ix.cmake:307 (include)
CMakeLists.txt:590 (include)
检查llvm_build / CMakeFiles / CMakeError.log中的错误消息,我发现cmake使用以下代码检查原子。
#include <atomic>
std::atomic<float> x(0.0f);
int main() { return (float)x; }
编译此代码的命令是:
/home/hailin/gcc-4.8.3-boost-1.55/rtf/bin/g++ -std = c ++ 11 -fPIC -fPIE -Wl,-pie
-DHAVE_CXX_ATOMICS_WITH_LIB -std = c ++ 11 main.cpp
/home/hailin/gcc-4.8.3-boost-1.55/rtf/lib/gcc/x86_64-unknown-linux-gnu/4.8.3 /../../../../ x86_64- unknown-linux-gnu / bin / ld:/usr/lib/../lib64/crt1.o:在创建共享对象时,不能使用针对`__libc_csu_fini'的重定位R_X86_64_32S;用-fPIC重新编译 /usr/lib/../lib64/crt1.o:错误添加符号:错误值 collect2:错误:ld返回1退出状态
如果删除标记-Wl,-pie
,则错误将消失。