From 488a33cd9c6781816784f6d38527d16d3077e5ba Mon Sep 17 00:00:00 2001 From: Ryan Volz Date: Thu, 31 Oct 2019 17:02:07 -0400 Subject: python: Do not link against python lib for building an extension module. This fixes a segmentation fault when trying to use the python module on OSX when built with conda (unsure why it doesn't arise otherwise). Instead of linking against the python library, it is proper to not link against the library and, for OSX builds, add linker options for "-undefined" and "dynamic_lookup". This is precisely what the CMake FindPython module does for linking against the Python::Module target. See https://blog.tim-smith.us/2015/09/python-extension-modules-os-x and https://bugs.python.org/issue36721 --- host/python/CMakeLists.txt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'host/python') diff --git a/host/python/CMakeLists.txt b/host/python/CMakeLists.txt index 0b31e4f3a..7ca247f18 100644 --- a/host/python/CMakeLists.txt +++ b/host/python/CMakeLists.txt @@ -42,7 +42,16 @@ target_include_directories(pyuhd PUBLIC ${PYBIND11_INCLUDE_DIR} ) -target_link_libraries(pyuhd ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} uhd) +if(WIN32) + target_link_libraries(pyuhd ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} uhd) +else() + # for extension module, proper to NOT link against python library and instead + # add dynamic lookup link option on OSX + target_link_libraries(pyuhd ${Boost_LIBRARIES} uhd) + if(APPLE) + target_link_options(pyuhd PRIVATE "LINKER:-undefined,dynamic_lookup") + endif(APPLE) +endif(WIN32) # Copy pyuhd library to the staging directory add_custom_command(TARGET pyuhd POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_CURRENT_BINARY_DIR}/uhd/$) -- cgit v1.2.3