Shiboken - Problem linking to shiboken2.abi3.lib
vberlier last edited by
Hi! I'm using Qt 5.15.2 with MinGW on windows and I'm trying to create python bindings for a C++ widget with shiboken2. I have a problem with the last linking step for generating the
g++doesn't find some of the symbols in
shiboken2.abi3.lib. Here is the command that CMake is trying to run:
[9/9 6.0/sec] Linking CXX shared module custom_widget.pyd FAILED: custom_widget.pyd cmd.exe /C "cd . && C:\Qt\Tools\mingw810_64\bin\g++.exe -g -shared -o custom_widget.pyd -Wl,--major-image-version,0,--minor-image-version,0 CMakeFiles/custom_widget.dir/custom_widget_autogen/mocs_compilation.cpp.obj CMakeFiles/custom_widget.dir/custom_widget/custom_widget_module_wrapper.cpp.obj CMakeFiles/custom_widget.dir/custom_widget/customwidget_wrapper.cpp.obj liblib_custom_widget.dll.a C:/Users/berli/projects/epita-pfee/PocShiboken/.venv/Lib/site-packages/shiboken2/shiboken2.abi3.lib C:/Users/berli/projects/epita-pfee/PocShiboken/.venv/Lib/site-packages/PySide2/pyside2.abi3.lib C:/Users/berli/AppData/Local/Programs/Python/Python39/libs/python39.lib C:/Qt/5.15.2/mingw81_64/lib/libQt5Widgets.a C:/Qt/5.15.2/mingw81_64/lib/libQt5Gui.a C:/Qt/5.15.2/mingw81_64/lib/libQt5Core.a -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
And here is what the error looks like:
CMakeFiles/custom_widget.dir/custom_widget/custom_widget_module_wrapper.cpp.obj: In function `_QList_QVariant__CppToPython__QList_QVariant_': C:\Users\berli\projects\epita-pfee\build-PocShiboken-Desktop_Qt_5_15_2_MinGW_64_bit-Debug/custom_widget/custom_widget_module_wrapper.cpp:64: undefined reference to `Shiboken::Conversions::copyToPython(SbkConverter const*, void const*)' CMakeFiles/custom_widget.dir/custom_widget/custom_widget_module_wrapper.cpp.obj: In function `_QList_QVariant__PythonToCpp__QList_QVariant_': C:\Users\berli\projects\epita-pfee\build-PocShiboken-Desktop_Qt_5_15_2_MinGW_64_bit-Debug/custom_widget/custom_widget_module_wrapper.cpp:84: undefined reference to `Shiboken::Conversions::pythonToCppCopy(SbkConverter const*, _object*, void*)' CMakeFiles/custom_widget.dir/custom_widget/custom_widget_module_wrapper.cpp.obj: In function `is__QList_QVariant__PythonToCpp__QList_QVariant__Convertible': C:\Users\berli\projects\epita-pfee\build-PocShiboken-Desktop_Qt_5_15_2_MinGW_64_bit-Debug/custom_widget/custom_widget_module_wrapper.cpp:91: undefined reference to `Shiboken::Conversions::convertibleSequenceTypes(SbkConverter const*, _object*)' ... [many more lines]
As you can see
shiboken2.abi3.libis part of the link command and appears to be linked in the expected order. To be sure I also checked that the symbols are present in
shiboken2.abi3.libusing the microsoft linker
link /dump /exports shiboken2.abi3.lib.
I also tried this with the MSVC kit and I have the same issue, only the error message from the microsoft linker is less detailed so I'm using the MinGW kit for the moment.
I'd really like to figure out why
g++doesn't seem to take
shiboken2.abi3.libinto account. I can also upload the whole project somewhere if it can help, it's a very simple demo.
Hi and welcome to devnet,
Just a wild guess but I would say that the library was built with MSVC and C++ libraries from MSVC cannot be used with MinGW.
What error did you get with visual studio ?
vberlier last edited by
@SGaist Thanks for the suggestion. You were right
shiboken2.abi3.libis probably not compatible with MinGW. It turns out that the error message I got when using the MSVC linker was not the same. With MSVC the problem was that it couldn't link against the c++ DLL containing my custom widget. It's kind of weird but I had to remove SHARED from the
add_libraryoptions. Now it's working fine.
It might be that you are linking to a static library (just a wild guess here).