[英]Shared library on Linux and -fPIC error
我正在嘗試使用使用Cmake創建的Makefile在Linux中編譯共享庫,但是運行make我獲得以下錯誤:
Linking CXX shared library libcpp-lib.so
/usr/bin/ld: /home/davide/Desktop/boost_1_55_0/stage/lib/libboost_system.a(error_code.o): relocation R_X86_64_32 against .rodata.str1.1 can not be used when making a shared object; recompile with -fPIC
/home/davide/Desktop/boost_1_55_0/stage/lib/libboost_system.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[2]: *** [libcpp-lib.so] Error 1
make[1]: *** [CMakeFiles/cpp-lib.dir/all] Error 2
make: *** [all] Error 2
我在CMakeLists.txt中提供以下命令,以便說我想要一個共享(.so)庫:
add_library(cpp-lib SHARED ${CPP_FILES})
為了避免上面顯示的-fPIC錯誤,還需要指定什么?
非常感謝提前
需要使用-fPIC編譯boost庫:請看一下: 如何使用boost.python中的-fPIC編譯靜態庫
嘗試在項目中通過cmake by添加編譯器標志:
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.