I'm trying to build a python wrapper of a shared C++ library using pybind11, with MinGW 32 bits.
It seems pybind11 enabled LTO, see the configure result from CMake bellow:
The C compiler identification is GNU 9.2.0
The CXX compiler identification is GNU 9.2.0
Check for working C compiler: C:/MinGW/bin/gcc.exe
Check for working C compiler: C:/MinGW/bin/gcc.exe -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Detecting C compile features
Detecting C compile features - done
Check for working CXX compiler: C:/MinGW/bin/g++.exe
Check for working CXX compiler: C:/MinGW/bin/g++.exe -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
Found PythonInterp: D:/Anaconda3/python.exe (found suitable version "3.7.1", minimum required is "3.7")
Found PythonLibs: D:/Anaconda3/libs/Python37.lib
pybind11 v2.4.dev4
Performing Test HAS_FLTO
Performing Test HAS_FLTO - Success
LTO enabled
lapack lib: blas;lapack
Configuring done
The c++ library, and a test.exe based on it are successfully built.
But I got "plugin needed to handle lto object" problem when linking to the python wrapper. So even though it results in a .pyd file, python tells me no module found when I tried to import it.
[ 95%] Linking CXX shared library libExampleCXX.dll
[ 95%] Built target ExampleCXX
Scanning dependencies of target test
[ 96%] Building CXX object test/CMakeFiles/test.dir/src/test_ExampleCXX.cpp.obj
[ 97%] Linking CXX executable test.exe
[ 97%] Built target test
Scanning dependencies of target Examplepy
[ 98%] Building CXX object Examplepy/CMakeFiles/Examplepy.dir/src/Examplepy.cpp.obj
[100%] Linking CXX shared module Examplepy.cp37-win32.pyd
C:\MinGW\bin\ar.exe: CMakeFiles/Examplepy.dir/src/Examplepy.cpp.obj: plugin needed to handle lto object
[100%] Built target Examplepy
I found there is actually "liblto_plugin-0.dll" in the path C:\MinGW\libexec\gcc\mingw32\9.2.0, but I'm not sure it's the right one, and don't know how to make it found...
Some settings (I guess might relate to the problem):
CMAKE_AR C:/MinGW/bin/ar.exe
CMAKE_NM C:/MinGW/bin/nm.exe
CMAKE_CXX_COMPILER_AR C:/MinGW/bin/gcc-ar.exe
CMAKE_CXX_COMPILER_RANLIB C:/MinGW/bin/gcc-ranlib.exe
CMAKE_INSTALL_LIBEXECDIR libexec
Thanks for your help.