Skip to content

Fix linker flags for building Python package for conda. #2773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions Bindings/Python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,28 @@ macro(OpenSimAddPythonModule)
"${PYTHON_INCLUDE_PATH}"
"${PYTHON_NUMPY_INCLUDE_DIR}")

target_link_libraries(${_libname}
osimTools osimExampleComponents ${PYTHON_LIBRARIES})
# On macOS, the python interpreter might link to the python library
# statically, in which case we do not want to link dynamically to the
# python library. This situation occurs with Anaconda's python.
# In this situation, we must add a linker flag to mark all undefined
# symbols as having to be looked up at runtime, and we ignore
# PYTHON_LIBRARIES.
# https://github.com/opensim-org/opensim-core/issues/2771
# https://stackoverflow.com/questions/25421479/clang-and-undefined-symbols-when-building-a-library
# https://github.com/lisitsyn/shogun/commit/961f6109c2a8abab4941bcdde1a19dfe70c440f1
# https://github.com/shogun-toolbox/shogun/issues/4068
execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c
"import sysconfig; print(sysconfig.get_config_var('LDSHARED'))"
OUTPUT_VARIABLE PYTHON_LDSHARED
OUTPUT_STRIP_TRAILING_WHITESPACE)
if("${PYTHON_LDSHARED}" MATCHES "dynamic_lookup")
set_target_properties(${_libname} PROPERTIES LINK_FLAGS
"-undefined dynamic_lookup")
else()
target_link_libraries(${_libname} ${PYTHON_LIBRARIES})
endif()

target_link_libraries(${_libname} osimTools osimExampleComponents)

# Set target properties for various platforms.
# --------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ v4.2
====
- Add the ActivationCoordinateActuator component, which is a CoordinateActuator with simple activation dynamics (PR #2699).
- Easily convert Matlab matrices and Python NumPy arrays to and from OpenSim Vectors and Matrices. See Matlab example matrixConversions.m and Python example numpy_conversions.py.
- Fix a segfault that occurs when using OpenSim's Python Package with
Anaconda's Python on a Mac.

v4.1
====
Expand Down