1.
在Mac OS X上.dylib和.so之间的区别在于它们的编译方式。对于.so文件,您使用-shared;对于.dylib,您使用-dynamiclib。.so和.dylib都可以作为动态库文件互换,并且都具有DYLIB或BUNDLE的类型。
https://www.imooc.com/wenda/detail/596644
g++ -o librain.so -shared -fPIC src/boost_rain.cpp -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -lboost_python27 -lpython
cmake
add_library(librain MODULE ${LIBSRC})
https://cmake.org/cmake/help/v3.0/command/add_library.html
2.
安装
brew install boost
brew install boost-python
brew install pybind11
1)输出${PYTHON_LIBRARIES}
MESSAGE(STATUS "=====" ${PYTHON_LIBRARIES})
2)
which python | xargs ls -al
/usr/local/bin/python -> ../Cellar/python@2/2.7.16_1/bin/python
3)CMakeLists.txt
include_directories(SYSTEM ${Boost_INCLUDE_DIR})
include_directories(SYSTEM ${PYTHON_INCLUDE_DIR})
include_directories(/include
${CMAKE_CURRENT_LIST_DIR}/src)
MESSAGE(STATUS "=====" ${Boost_INCLUDE_DIR})
MESSAGE(STATUS "=====" ${PYTHON_INCLUDE_DIR})
set(My_LIBRARIES "/usr/local/Cellar/boost-python/1.71.0/lib/libboost_python27.dylib")
set(PYTHON_LIBRARIES "/usr/local/Cellar/python@2/2.7.16_1/Frameworks/Python.framework/Versions/2.7/Python")
MESSAGE(STATUS "=====" ${PYTHON_LIBRARIES})
file(GLOB LIBSRC ${CMAKE_CURRENT_LIST_DIR}/src/example.cpp)
add_library(example MODULE ${LIBSRC})
set_target_properties(example PROPERTIES PREFIX "")
target_link_libraries(example ${My_LIBRARIES} ${PYTHON_LIBRARIES})
file(GLOB LIBSRC ${CMAKE_CURRENT_LIST_DIR}/src/boost_rain.cpp)
add_library(librain MODULE ${LIBSRC})
set_target_properties(librain PROPERTIES PREFIX "")
target_link_libraries(librain ${My_LIBRARIES} ${PYTHON_LIBRARIES})
3.
Fatal Python error: PyThreadState_Get: no current thread
tool -L example.so
example.so:
/usr/local/opt/boost-python/lib/libboost_python27.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 902.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.100.1)
https://zhuanlan.zhihu.com/p/33668024