I'm developing a python module that is written in C++ but callable from python via bindings written via pybind11
. I'm trying to cross-compile for M1 Macs from an Intel Mac using Apple's XCode Toolchain.
Interestingly, for some users the package works, whereas other users experience the error below:
ImportError: dlopen(/Users/frieda/miniconda3/envs/behavior/lib/python3.8/site-packages/banditpam.cpython-38-darwin.so, 0x0002): symbol not found in flat namespace '_omp_get_max_threads'
How can I statically link OpenMP so that it ships with the python wheel?
What I've tried:
From a similar SO question for Boost, I think something is going wrong with a libstdc++
vs. libc++
library, which I think can be fixed by statically linking the OpenMP library in our package. How can this be done, for each of clang
and gcc
in our setup.py
? I've tried various linker flags such as -static-libgomp
but they don't seem to work.
Do I also need to include the -fPIC
flag?
Caveat: this comment recommends against linking OpenMP statically. Is there a better way to expose OpenMP functions via python bindings to our users?
EDIT: The setup.py
is here; I'm building via cibuildwheel
on the Github Runners to cross-compile from a Github Intel Mac to an M1 Mac (Github M1 Mac Runners are not easily accessible); see here.
Users on M1 Mac are able to install the built wheel, but some of them get the runtime error above when import
ing the library. The offending line is here.