所以,我试图在make中构建一些东西。我通过cmake生成文件,转到构建文件的相应文件夹,然后:
make
Scanning dependencies of target Spenvis
[ 33%] Building CXX object source/CMakeFiles/Spenvis.dir/pySpenvisCSV.cc.o
[ 66%] Building CXX object source/CMakeFiles/Spenvis.dir/SpenvisCSV.cc.o
[100%] Building CXX object source/CMakeFiles/Spenvis.dir/SpenvisCSVCollection.cc.o
Linking CXX shared library libSpenvis.so
/usr/bin/ld: /usr/local/lib64/libpython2.7.a(abstract.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib64/libpython2.7.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[2]: *** [source/libSpenvis.so] Error 1
make[1]: *** [source/CMakeFiles/Spenvis.dir/all] Error 2
make: *** [all] Error 2
就make / cmake来说,我有点新手。我不确定从哪里开始。我已经查看了几个建议,但我不确定哪些与我的特定问题相关,以及如何首先实施建议的修复。
HALP!
python_utilities目录中有两个CMakeLists.txt文件。我将包括两者。一个来自spenvis_csv / source:
# Make sure the compiler can find include files
include_directories (${PYSPENVIS_SOURCE_DIR})
# get boost
set(Boost_USE_STATIC_LIBS OFF)
#set(Boost_USE_MULTIEADED ON)
find_package(Boost COMPONENTS
python
REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
# get python
include(FindPythonLibs)
set(PythonLibs_USE_STATIC_LIBS OFF)
find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
link_directories(${PYTHON_LIBRARIES})
#
add_library(Spenvis SHARED pySpenvisCSV.cc SpenvisCSV.cc SpenvisCSVCollection.cc)
TARGET_LINK_LIBRARIES(Spenvis ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
然后是第二个更短的一个:
cmake_minimum_required (VERSION 2.6)
set (Boost_NO_BOOST_CMAKE=ON)
project (PYSPENVIS)
add_subdirectory ("source")
答案 0 :(得分:0)
您正在链接静态 python库,我相信它通常不会使用-fPIC构建,因此它的代码不可重新定位。另一方面,您的Spenvis目标是共享库,将使用-fPIC构建,但非PIC代码中的链接不会像这样工作。这就是链接器对你说的话。
如果可能,你可以链接python库的共享版本(即libpython.so.2.7或类似的东西,具体取决于你的系统如何命名)?我希望CMake默认情况下更喜欢链接到共享库,所以我想知道是否:
如果您正在使用FindPythonLibs CMake模块,我希望在PYTHON_LIBRARIES变量中为您提供共享python库(如果它在您的系统上可用)。如果您更新问题以包含CMakeLists.txt文件,则可能有助于识别问题。