possible lead I am too stupid to understand
I am trying to build a pybind11 module with CMake on Windows:
#include <iostream>
#include <pybind11/pybind11.h>
void say_hello(){
std::cout << "Hello, from c++!\n";
}
PYBIND11_MODULE(example, m) {
m.def("say_hello", &say_hello);
}
cmake_minimum_required(VERSION 3.10.0)
project(example VERSION 0.1.0 LANGUAGES C CXX)
find_package(Python COMPONENTS Interpreter Development REQUIRED)
find_package(pybind11 REQUIRED)
pybind11_add_module(example example.cpp)
dumpbin /dependents build/example.cp311-win_amd64.pyd
Dump of file build\example.cp311-win_amd64.pyd
File Type: DLL
Image has the following dependencies:
libgcc_s_seh-1.dll
KERNEL32.dll
msvcrt.dll
libstdc++-6.dll
python311.dll
import example
example.say_hello()
# >>> ImportError: DLL load failed while importing example
What am I doing wrong? In case there is a solution to my problem, how can I make it reliable on other systems?
EDIT: works flawlessly on linux, obv
Adding the following line:
in the
CMakeLists.txtfile currently solves my problem on my Windows machine. The-staticflag tells the compiler to link the DLLs statically, meaning directly inside the .pyd binary file.Most likely I had a problem with those DLLs dependencies...