I want to compile and run a simple example with Pybind11.
I have two files example.cpp and CMakeLists.txt in my current directory and I use the MSYS2 MinGW x64 shell.
Here is example.cpp
#include <pybind11/pybind11.h>
int add(int i, int j) {
return i + j;
}
PYBIND11_MODULE(example, m) {
m.doc() = "pybind11 example plugin"; // optional module docstring
m.def("add", &add, "A function that adds two numbers");
}
Here is CMakeLists.txt
cmake_minimum_required(VERSION 3.3)
project(example)
find_package(Python COMPONENTS Interpreter Development)
find_package(pybind11 CONFIG)
# pybind11 method:
pybind11_add_module(example example.cpp)
I have installed pybind11 with the command
pacman -S mingw-w64-x86_64-pybind11
Then I run
mkdir buildmingw
cd buildmingw
cmake .. -G "MinGW Makefiles"
Then the build files are written correctly to buildmingw. Lauching now make fails
mingw32-make
The output is then
[ 50%] Building CXX object CMakeFiles/example.dir/example.cpp.obj
In file included from D:/Software/Python/include/pyport.h:227,
from D:/Software/Python/include/Python.h:38,
from /mingw64/include/pybind11/detail/common.h:266,
from /mingw64/include/pybind11/attr.h:13,
from /mingw64/include/pybind11/detail/class.h:12,
from /mingw64/include/pybind11/pybind11.h:13,
from D:InformatikNachhilfeInfoUniKadalaSchmittC++PythonBindC++example.cpp:1:
/mingw64/include/time.h:12:2: error: #error Only Win32 target is supported!
12 | #error Only Win32 target is supported!
| ^~~~~
I also tried to issue the ming32-make command from the MSYS2 MinGW x86 shell, but get exactly the same error message. (So something with erro in /mingw64/include/pybind11/detail/common.h:266 )
I also just checked whether I have a C++ compiler installed under mingw32 with this command
pacman -Ss mingw-w64-i686-gcc
which gave the output
mingw32/mingw-w64-i686-gcc 13.2.0-6 (mingw-w64-i686-toolchain)
GNU Compiler Collection (C,C++,OpenMP) for MinGW-w64
mingw32/mingw-w64-i686-gcc-ada 13.2.0-6
GNU Compiler Collection (Ada) for MinGW-w64
mingw32/mingw-w64-i686-gcc-fortran 13.2.0-6
GNU Compiler Collection (Fortran) for MinGW-w64
mingw32/mingw-w64-i686-gcc-libgfortran 13.2.0-6
GNU Compiler Collection (libgfortran) for MinGW-w64
mingw32/mingw-w64-i686-gcc-libs 13.2.0-6 [installed: 12.2.0-6]
GNU Compiler Collection (libraries) for MinGW-w64
mingw32/mingw-w64-i686-gcc-lto-dump 13.2.0-6
Dump link time optimization object files (mingw-w64)
mingw32/mingw-w64-i686-gcc-objc 13.2.0-6
GNU Compiler Collection (ObjC,Obj-C++) for MinGW-w64
However on packages.msys.org I can only find
mingw-w64-x86_64-pybind11
mingw-w64-ucrt-x86_64-pybind11
mingw-w64-clang-x86_64-pybind11
I just read about Different MSYS2 environments and how to pick one, but don’t really know how I can compile my Pybind11 project with mingw32
Any help appreciated!