繁体   English   中英

用-fPIC重新编译makefile

[英]makefile recompile with -fPIC

因此,我正在尝试构建一些东西。 我通过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而言,我还是个新手。 我不确定从这里去哪里。 我已经看过一些建议,但是我不确定哪些与我的特定问题以及如何首先实施建议的修复有关。

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") 

您正在链接到静态 python库,我相信,该库通常不会使用-fPIC构建,因此其代码无法重定位。 另一方面,您的Spenvis目标是一个共享库,将使用-fPIC进行构建,但是链接非PIC代码将无法正常工作。 这就是链接器对您说的。

如果可能,是否可以链接到python库的共享版本(即libpython.so.2.7或类似的名称,具体取决于您的系统命名方式)? 我本来希望CMake在默认情况下更喜欢链接到共享库,所以我想知道是否:

  • 您缺少系统上的共享libpython库(不太可能,但有可能)。
  • 您已经包括了一些CMake选项,这些选项告诉它更喜欢静态库中的链接。
  • 您已明确为CMake提供了静态python库以某种方式链接。

如果您使用的是FindPythonLibs CMake模块,那么我希望可以在系统上可用的PYTHON_LIBRARIES变量中为您提供共享的python库。 如果您更新问题以包括CMakeLists.txt文件,则可能有助于发现问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM