CMake安装后的Python ImportError

时间:2018-04-01 23:43:46

标签: python c++ cmake boost-python

我从CMake开始,使用Boost Python时遇到了以下问题。一个示例'hello world'程序需要boost和python库。在运行cmake之前,我创建了'build'目录,这就是我运行cmake的地方。我能够生成一个共享库并在该目录中使用它(使用python),但是当我输入make install并且我的库放在源目录中时,python无法读取它会引发错误:

  

ImportError:libboost_python.so.1.64.0:无法打开共享对象文件:没有这样的文件或目录

cmake_minimum_required( VERSION 2.8 )

project( test )
enable_language(CXX)

set( LIB_NAME pylib )

# ---------------------------
# Find Boost Python library
# ---------------------------
find_package(Boost COMPONENTS python REQUIRED)

if( Boost_FOUND )
   message( STATUS "-> Boost_INCLUDE_DIRS: " ${Boost_INCLUDE_DIRS} )
   message( STATUS "-> Boost_LIBRARY_DIRS: " ${Boost_LIBRARY_DIRS} )
   message( STATUS "-> Boost_LIBRARIES: " ${Boost_LIBRARIES} )

   include_directories(${Boost_INCLUDE_DIRS})
endif()

# ---------------------------
# Find Python library
# ---------------------------
find_package( PythonLibs REQUIRED )
if( PythonLibs_FOUND )
   message( STATUS "-> PYTHON_INCLUDE_DIRS: " ${PYTHON_INCLUDE_DIRS} )
   message( STATUS "-> PYTHON_LIBRARY_DIRS: " ${PYTHON_LIBRARY_DIRS} )
   message( STATUS "-> PYTHON_LIBRARIES: " ${PYTHON_LIBRARIES} )

   include_directories(${PYTHON_INCLUDE_DIRS})
endif()

set( SRC hello.cpp )

add_library( ${LIB_NAME} SHARED ${SRC} )

target_link_libraries( ${LIB_NAME} 
   ${PYTHON_LIBRARIES}
   ${Boost_LIBRARIES} 
)

set_target_properties( ${LIB_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON )
set_target_properties( ${LIB_NAME} PROPERTIES SUFFIX .so )
set_target_properties( ${LIB_NAME} PROPERTIES PREFIX "" )

install( TARGETS ${LIB_NAME} 
   LIBRARY DESTINATION ${PROJECT_SOURCE_DIR}
)

0 个答案:

没有答案