[cmake] Force ".so" suffix for pybind11 module libraries on macOS
The issue is discussed in this old thread on stackoverflow: https://stackoverflow.com/questions/2488016/how-to-make-python-load-dylib-on-osx
Somehow Python refuses to import dynamic libraries with the suffix .dylib
(I get an import error) which is the common suffix for shared libs in macOS. Telling CMake to use .so
instead as suggested in the stackoverflow thread works for me.
The Python libs on for my Python 3.7 from homebrew all have .so
endings just like in the stackoverflow answer.
Fixes #201 (closed)
Merge request reports
Activity
added buildsystem label
assigned to @andreas.dedner
Sorry I totally missed this - I think this corresponds with what @samuel.burbulla has reported and also tested? I think there are additional flags that also need to be set for MAC?
@samuel.burbulla could you check this MR and would it be possible to also add the flags needed for linking?
It seems like from my local setup that I needed to pass the following additional flags
-I/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/include/python3.7m -dynamic -fwrapv
The first one is annoying but without that it was somehow not able to link against Python. I'm not sure how to fix this in a nice way.
- Resolved by Samuel Burbulla
@samuel.burbulla told me that he needed to add
-Wl,-undefined,dynamic_lookup
@tkoch that the
-I
flag mean that cmake is not correctly finding the include paths for Python? Which cmake version are you using?
The set_property change seems to work for my setup.
The flags don't. I don't need the flags @tkoch mentioned. What I used so far is
-Wl,-undefined,dynamic_lookup
But this produces a few unused warnings when building dune-common.
@tkoch Any idea why we need these different flags?
Edited by Samuel Burbulla- Resolved by Samuel Burbulla
Actually, it can also be found in the official documentation:
https://pybind11.readthedocs.io/en/stable/compiling.html#building-manually
Does anyone have an idea how to include this flag without producing the warnings for the targets that do not link against pybind11?
Edited by Samuel Burbulla
added 1 commit
- c2807095 - [cmake] Add -undefined dynamic_lookup flag for pybind11 targets on macOS.
- Resolved by Samuel Burbulla
This works for me and does not produce unnecessary warnings.
@tkoch Can you check?
mentioned in merge request dune-fem/dune-fem!364 (merged)
- Resolved by Samuel Burbulla
I don't think we are linking against the PythonLib at least I can't find where it is done - it does not seem to be added through
dune_target_enable_all_packages
- but I might be missing something. Looking at mymake
output for_common.so
I see-lquadmath -llapack -lblas -pthread -lmpich ../../../lib/libdunecommon.a -llapack -lblas
mentioned in commit dune-fem/dune-fem@a14acad2
@andreas.dedner Can this be merged or is something missing?
added 41 commits
-
c2807095...2917908b - 39 commits from branch
master
- 02be2c75 - [cmake] Force ".so" suffix for pybind11 module libraries on macOS
- eefd7050 - [cmake] Add -undefined dynamic_lookup flag for pybind11 targets on macOS.
-
c2807095...2917908b - 39 commits from branch
mentioned in commit bccda895
mentioned in issue #201 (closed)