makefile使用-fPIC重新编译 [英] makefile recompile with -fPIC

查看:2629
本文介绍了makefile使用-fPIC重新编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我想在make中构建一些东西。我通过cmake生成文件,转到适当的文件夹中的构建文件,并且:

  make 
扫描依赖项的目标Spenvis
[33%]构建CXX对象源/ CMakeFiles / Spenvis.dir / pySpenvisCSV.cc.o
[66%]构建CXX对象源/ CMakeFiles / Spenvis.dir / SpenvisCSV.cc。 o
[100%]构建CXX对象源/ CMakeFiles / Spenvis.dir / SpenvisCSVCollection.cc.o
链接CXX共享库libSpenvis.so
/ usr / bin / ld:/ usr / local / lib64 / libpython2.7.a(abstract.o):对于`.rodata.str1.8'重定位R_X86_64_32不能在创建共享对象时使用;重新编译-fPIC
/usr/local/lib64/libpython2.7.a:无法读取符号:错误值
collect2:ld返回1退出状态
make [2]:** * [source / libSpenvis.so]错误1
make [1]:*** [source / CMakeFiles / Spenvis.dir / all]错误2
make:*** [all]错误2

对于make / cmake,我有点新手。我不确定从这里去哪里。我已经查看了几个建议,但我不确定哪些与我的特定问题相关,以及如何实施建议的修复程序在第一位。



Halp! / p>

在python_utilities目录中有两个CMakeLists.txt文件。我会包括两者。一个来自spenvis_csv / source:

 #确保编译器可以找到包含文件
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)


解决方案

您正在链接到 static python库,我相信,通常不会使用-fPIC构建,因此它的代码不会可迁移。另一方面,您的Spenvis目标是一个共享库,并且将使用-fPIC构建,但是在非PIC代码中的链接不会像这样工作。这是链接器对你说的。



如果有可能,你可以链接到共享版本的python库(即libpython.so.2.7或某事类似,取决于你的系统命名它)?我会希望CMake默认情况下链接到共享库,所以我想知道是否:




  • 您缺少共享

  • 您已经包含了一些CMake选项,可以指定它们更喜欢在静态库中链接。

  • >



如果您使用的是 FindPythonLibs CMake模块,我本来希望给你的共享python库在PYTHON_LIBRARIES变量,如果它在您的系统上可用。如果您更新问题以包含CMakeLists.txt文件,则可能有助于确定问题。


So, I'm trying to build something in make. I produced the files via cmake, went to the appropriate folder for the build file, and:

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

I'm a bit of a novice as far as make/cmake goes. I'm uncertain where to go from here. I've looked at several suggestions, but I'm uncertain which are relevant to my particular problem and how to implement the suggested fixes in the first place.

Halp!

There are two CMakeLists.txt files within the python_utilities directory. I'll include both. One from 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})

And then the second much shorter one:

cmake_minimum_required (VERSION 2.6)
set (Boost_NO_BOOST_CMAKE=ON)
project (PYSPENVIS)
add_subdirectory ("source") 

解决方案

You are linking against the static python library which, I believe, is typically not going to be built with -fPIC so it's code won't be relocatable. Your Spenvis target, on the other hand, is a shared library and will be built with -fPIC, but linking in non-PIC code isn't going to work like this. This is what the linker is saying to you.

If it is possible, can you link against the shared version of the python library (i.e. libpython.so.2.7 or something similar, depending on how your system names it)? I would have expected CMake to prefer linking to the shared library by default, so I'm wondering if either:

  • You are missing the shared libpython library on your system (unlikely, but possible).
  • You've included some CMake options which tell it to prefer linking in static libraries.
  • You've explicitly given CMake the static python library to link in somehow.

If you are using the FindPythonLibs CMake module, I would have expected that to be giving you the shared python library in the PYTHON_LIBRARIES variable, if it is available on your system. If you update your question to include your CMakeLists.txt file, that may help identify the problem.

这篇关于makefile使用-fPIC重新编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆