You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When tiring to compile a test project that uses PyBind11 on a Windows computer using G++, meson is able to compile the program. However, if you try to import the resulting module in python, the program will error out with a DLL error:
>>> import adder
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed while importing adder: The specified module could not be found.
#include<pybind11/pybind11.h>intadd(int a, int b){
return a + b;
}
PYBIND11_MODULE(adder, module){
module.doc() = "this is an example";
module.def("add", &add);
}
install pybind11 using meson wrap install pybind11
run meson setup build to create a build directory
examine the setup log and ensure that meson has detected the G++ compiler
pybind11| C++ compiler for the host machine: c++ (gcc 11.3.0 "c++ (Rev1, Built by MSYS2 project) 11.3.0")
run meson compile -C build to compile the project
cd build into the build directory
run python to open an interactive shell.
try to import the module "adder" using import adder
Expected behavior
Python imports the adder module successfully and a python shell user is able to call the add function provided by the library
system parameters
Build: Native
Operating System: Windows 11
Python version: 3.9.7
Meson version: 0.62.1
Ninja version: 1.10.2.git.kitware.jobserver-1
Other notes & Workarounds
Using MSVC instead of GCC fixes the issue.
The issue appears to be related to the linking of DLL libraries, examining the .pyd file that is created with dependency walker shows a few missing DLL files, but I have been unable to find these files on the internet
The text was updated successfully, but these errors were encountered:
Further research has led me to discover that this happens because the windows version of Python is built with MSVC, and therefore can't link anything compiled with GCC, which is not a bug.
@atw1020, for the record, this is not totally exact, you can build python packages on windows with Gcc but you might want to static link gcc provided libs as much as possible like here: https://github.com/SciQLop/CDFpp/blob/master/meson.build#L38-L47
This is distributed on PyPi and built with Gcc on windows. Note also that you might only be able to build in release mode :/.
For such issues, Dependency Walker is a good friend.
I tried release mode to try to get it to link statically but it still gives the DLL error, using static linking flags could also help though, thanks for the example!
Describe the bug
When tiring to compile a test project that uses PyBind11 on a Windows computer using G++, meson is able to compile the program. However, if you try to import the resulting module in python, the program will error out with a DLL error:
To Reproduce
C:.
└───subprojects
└───meson.build
└───module.cpp
Contents of meson.build:
Contents of module.cpp:
meson wrap install pybind11
meson setup build
to create a build directorymeson compile -C build
to compile the projectcd build
into the build directorypython
to open an interactive shell.import adder
Expected behavior
Python imports the
adder
module successfully and a python shell user is able to call theadd
function provided by the librarysystem parameters
Build: Native
Operating System: Windows 11
Python version: 3.9.7
Meson version: 0.62.1
Ninja version: 1.10.2.git.kitware.jobserver-1
Other notes & Workarounds
The text was updated successfully, but these errors were encountered: