Skip to content

Commit 081fbd6

Browse files
committed
Get the libpython library name from Python
CMake's find_library can return a static library in some conditions (certainly if the shared object isn't present; I'm not sure if there are other conditions as well), which we don't support (and fails). This improves the libpython detection by getting the shared library name directly from Python rather than letting CMake guess (by prepending `lib` and appending library suffixes). This should, at least, prevent the embedded build from failing as in issue pybind#1159 -- instead it should either find the proper shared library, or else result in a compilation failure from the missing library.
1 parent 5c7a290 commit 081fbd6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

tools/FindPythonLibsNew.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ print(struct.calcsize('@P'));
8585
print(s.get_config_var('LDVERSION') or s.get_config_var('VERSION'));
8686
print(s.get_config_var('LIBDIR') or '');
8787
print(s.get_config_var('MULTIARCH') or '');
88+
print(s.get_config_var('LDLIBRARY'));
8889
"
8990
RESULT_VARIABLE _PYTHON_SUCCESS
9091
OUTPUT_VARIABLE _PYTHON_VALUES
@@ -112,6 +113,7 @@ list(GET _PYTHON_VALUES 6 PYTHON_SIZEOF_VOID_P)
112113
list(GET _PYTHON_VALUES 7 PYTHON_LIBRARY_SUFFIX)
113114
list(GET _PYTHON_VALUES 8 PYTHON_LIBDIR)
114115
list(GET _PYTHON_VALUES 9 PYTHON_MULTIARCH)
116+
list(GET _PYTHON_VALUES 10 _PYTHON_LIBRARY_NAME)
115117

116118
# Make sure the Python has the same pointer-size as the chosen compiler
117119
# Skip if CMAKE_SIZEOF_VOID_P is not defined
@@ -165,7 +167,7 @@ else()
165167
# Probably this needs to be more involved. It would be nice if the config
166168
# information the python interpreter itself gave us were more complete.
167169
find_library(PYTHON_LIBRARY
168-
NAMES "python${PYTHON_LIBRARY_SUFFIX}"
170+
NAMES ${_PYTHON_LIBRARY_NAME}
169171
PATHS ${_PYTHON_LIBS_SEARCH}
170172
NO_DEFAULT_PATH)
171173

0 commit comments

Comments
 (0)