Problem with linking to alternative boost install

已完成

I am getting a link error when I try to link to my alternative boost installation directory. I built boost using static and multi-threading. It finds the boost headers fine, but I get an error message:

[ 40%] Built target LibProject
[ 60%] Linking CXX executable MainProject
/usr/bin/ld: /X/boost_1_65_1/stage/lib/libboost_system.a(error_code.o): relocation R_X86_64_32S against `.bss' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status

Here is the code I am using in my CMakeLists.txt in my CLion project:

set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_NO_SYSTEM_PATHS TRUE)
if (Boost_NO_SYSTEM_PATHS)
    set(BOOST_ROOT "/X/boost_1_65_1")
    set(BOOST_INCLUDE_DIRS "/X/boost_1_65_1")
    set(BOOST_LIBRARY_DIRS "/X/boost_1_65_1/stage/lib")
endif (Boost_NO_SYSTEM_PATHS)
find_package(Boost REQUIRED COMPONENTS system filesystem)

0
Avatar
Permanently deleted user

I fixed this by changing the compiler to be clang in the Clion Settings dialog. I had compiled Boost with clang.

 

-D CMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++

0

请先登录再写评论。