diff options
author | Ryan Volz <rvolz@mit.edu> | 2019-10-31 17:02:07 -0400 |
---|---|---|
committer | atrnati <54334261+atrnati@users.noreply.github.com> | 2020-02-07 09:12:15 -0600 |
commit | 488a33cd9c6781816784f6d38527d16d3077e5ba (patch) | |
tree | 38c2555716381744be2b8b47e86493fde64b7ca4 /host/python/CMakeLists.txt | |
parent | ec96cc37a245b1f1ddd8348d86ac9636b2f7228a (diff) | |
download | uhd-488a33cd9c6781816784f6d38527d16d3077e5ba.tar.gz uhd-488a33cd9c6781816784f6d38527d16d3077e5ba.tar.bz2 uhd-488a33cd9c6781816784f6d38527d16d3077e5ba.zip |
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
Diffstat (limited to 'host/python/CMakeLists.txt')
-rw-r--r-- | host/python/CMakeLists.txt | 11 |
1 files changed, 10 insertions, 1 deletions
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 $<TARGET_FILE:pyuhd> ${CMAKE_CURRENT_BINARY_DIR}/uhd/$<TARGET_FILE_NAME:pyuhd>) |