我有一个类似于Celdor的问题,但我认为我的问题更多是关于链接和路径。我在Python 2.7中使用boost.python,并且具有以下文件配置:
- Project
-CMakeLists.txt
|
+--- src
-solver.cpp
-solver_ext.cpp
|
+--- include
-solver.hpp
|
+--- build
我的CMakeLists.txt如下:
cmake_minimum_required(VERSION 2.8)
project(foo)
find_package(PythonLibs 2.7 REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
find_package(Boost 1.61.0 COMPONENTS python REQUIRED)
include_directories(${Boost_INCLUDE_DIR} include)
add_library(solver SHARED src/solver.cpp)
add_library(solver_ext SHARED src/solver_ext.cpp)
target_link_libraries(solver_ext ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} solver)
set_target_properties(solver_ext PROPERTIES PREFIX "")
install(TARGETS solver_ext DESTINATION ~/devel/install/python)
install(TARGETS solver DESTINATION ~/devel/install/lib/foo)
我的PYTHONPATH是
~/devel/install/python:/usr/local/lib/python2.7/site-packages:/usr/local/lib/python2.7/dist-packages
和我的LD_LIBRARY_PATH
~/devel/install/python
一切都会编译。 现在的问题是,当我在python中调用 importsolver_ext 时,找不到libsolver.so或Solver_est.so并给我一个错误:
ImportError: ./solver_ext.so: undefined symbol: _YN6Solver4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
如果我在Project / build目录中调用 import resolver_ext ,则一切正常,因为这两个库也都安装在这里。所以我想这是一个路径问题,但是即使我将libsolver.so和solver_ext.so都放在〜/ devel / install / python 目录中,或者当我已将〜/ devel / install / lib / foo 添加到我的LD_LIBRARY_PATH。
我敢肯定我遗漏了一些非常明显的东西,但是如果有人能指出我正确的方向,我将非常高兴。
谢谢。