wlav / cppyy

Other
400 stars 41 forks source link

cppyy_compile with different flags #56

Closed alexandrumc closed 2 years ago

alexandrumc commented 2 years ago

I tried today to call Qt (the example from here https://www.qt.io/blog/2018/06/15/scripting-in-c) but when I cppyy_compile("#include <QtWidgets/qapplication.h>") I get

In file included from input_line_19:1:
In file included from /usr/include/x86_64-linux-gnu/qt5/QtWidgets/qapplication.h:43:
In file included from /usr/include/x86_64-linux-gnu/qt5/QtWidgets/qtwidgetsglobal.h:43:
In file included from /usr/include/x86_64-linux-gnu/qt5/QtGui/qtguiglobal.h:43:
/usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:1187:4: error: "You must build your code with position independent code if Qt was built with -reduce-
relocations. "         "Compile your code with -fPIC (-fPIE is not enough)."
#  error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\

It would be nice to be able to able to pass, say, -fPIC as a flag for compilation.

wlav commented 2 years ago

You can, just add it to the EXTRA_CLING_ARGS envar. Also, that error message is wrong, so you could simply bypass it with #define __PIC__.

alexandrumc commented 2 years ago

Good to know, thanks! Worked on Linux. However, on Windows, when I try to load, for example, Qt6Core.dll, I get this:

> cppLoadLibrary("Qt6Core.dll")
cling::DynamicLibraryManager::loadLibrary() [C:\Dev\workspace\sil-cling\vcpkg\installed\x64-windows\bin\Qt6Core.dll -> C:\Dev\workspace\sil-cling\vcpkg\installed\x64-windows\bin\Qt6Core.dll]: LoadLibrary: returned 126: The specified module could not be found.
"Qt6Core.dll"

Process Monitor says that it finds all the dependencies it needs.

cppLoadLibrary is just calling https://github.com/wlav/cppyy-backend/blob/master/clingwrapper/src/clingwrapper.cxx#L2833

The error message seems to come from here: https://github.com/root-project/cling/blob/master/lib/Interpreter/DynamicLibraryManager.cpp#L380

wlav commented 2 years ago

Make sure that the targets match: i.e. that both your clingwrapper build and Qt install are for either 32b or 64b builds, not a mix of them, and that both are either debug or release and MT or not, not a mix of them (each would lead to loading different C++ standard libraries).

You can also try to open the file with Python's ctypes instead. That sometimes gives better error messages:

>>> import ctypes
>>> d = ctypes.CDLL("Qt6Core.dll")

You may need to provide the full path to Qt6Core.dll here.

(I understand you're not using Python here, but this should provide a cross-check on missing symbols etc.)

wlav commented 2 years ago

Presumed resolved after no updates/further questions for 2 months. Feel free to reopen or start a new issue if no the case.

alexandrumc commented 2 years ago

Yes, it was solved but I forgot to update the issue. Thank you.