Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Problem linking to libQt5*.so (Linux)



  • Hi,

    I'm trying to use a module (not written by me) on Python 3.7 that contains some libQt5*.so files that supposedly were copied over (more like "spliced") from a pre-built Qt5 package (v5.12.7), while having my own distro installation of Qt5 in /usr/lib (v5.15.0).

    The module in question is the Python API of the Cambridge Structure Database, named "ccdc".
    ccdc doesn't require PySide2 or PyQt5 but has its own libpythonapi_support.so.1.0.0 which reaches out to the functions in the libQt5*.so files that it can find in the system.
    Other than the fact that it's closed source, I think the internal details of ccdc are not important.
    ie. I can't rewire libpythonapi_support.so.1.0.0 from the source.

    The problem I'm having is that the import command which loads libpythonapi_support.so.1.0.0 ends up mixing up the two paths and later ends up crashing with a segfault.
    I had to use gdb to find where exactly the paths get mixed up. The call stack is pretty big, so I'm pasting only the top part which seems relevant.

    (gdb) bt
    #0  0x00007ffff1ecdbc5 in QXcbScreen::topLevelAt(QPoint const&) const () from /home/david/.local/lib/python3.7/site-packages/ccdc/_lib/libQt5XcbQpa.so.5
    #1  0x00007ffff589f475 in ?? () from /usr/lib/libQt5Gui.so.5
    #2  0x00007ffff584d983 in QWindowSystemInterface::handleScreenAdded(QPlatformScreen*, bool) () from /usr/lib/libQt5Gui.so.5
    #3  0x00007ffff1eee803 in QXcbConnection::initializeScreens() () from /home/david/.local/lib/python3.7/site-packages/ccdc/_lib/libQt5XcbQpa.so.5
    #4  0x00007ffff1ec2628 in QXcbConnection::QXcbConnection(QXcbNativeInterface*, bool, unsigned int, char const*) () from /home/david/.local/lib/python3.7/site-packages/ccdc/_lib/libQt5XcbQpa.so.5
    #5  0x00007ffff1ec6b66 in QXcbIntegration::QXcbIntegration(QStringList const&, int&, char**) () from /home/david/.local/lib/python3.7/site-packages/ccdc/_lib/libQt5XcbQpa.so.5
    #6  0x00007ffff222362d in QXcbIntegrationPlugin::create(QString const&, QStringList const&, int&, char**) () from /home/david/.local/lib/python3.7/site-packages/ccdc/_lib/plugins/platforms/libqxcb.so
    #7  0x00007ffff586c527 in QGuiApplicationPrivate::createPlatformIntegration() () from /usr/lib/libQt5Gui.so.5
    #8  0x00007ffff586d9e1 in QGuiApplicationPrivate::createEventDispatcher() () from /usr/lib/libQt5Gui.so.5
    #9  0x00007ffff54a2406 in QCoreApplicationPrivate::init() () from /usr/lib/libQt5Core.so.5
    #10 0x00007ffff5870a20 in QGuiApplicationPrivate::init() () from /usr/lib/libQt5Gui.so.5
    #11 0x00007ffff5f6e68a in QApplicationPrivate::init() () from /usr/lib/libQt5Widgets.so.5
    #12 0x00007ffff68784bf in PythonAPI::application_services() () from /home/david/.local/lib/python3.7/site-packages/ccdc/_lib/libpythonapi_support.so.1.0.0
    #13 0x00007ffff691dfce in PyInit__UtilitiesLib () from /home/david/.local/lib/python3.7/site-packages/ccdc/_lib/_UtilitiesLib.so
    #14 0x00007ffff7e06ef3 in _PyImport_LoadDynamicModuleWithSpec (spec=spec@entry=0x7ffff6996710, fp=fp@entry=0x0) at ./Python/importdl.c:159
    #15 0x00007ffff7e04bfb in _imp_create_dynamic_impl (module=<optimized out>, file=<optimized out>, spec=0x7ffff6996710) at Python/import.c:2174
    ...
    

    Going from frame #12 to #11, the call suddenly changes path to /usr/lib/libQt5Widgets.so.5 where it should have called /home/david/.local/lib/python3.7/site-packages/ccdc/_lib/libQt5Widgets.so.5

    Question: Does anyone know how to get Python to load the correct ccdc/_lib/libQt5*.so files, preferably without uninstalling the package that provides the /usr/lib/libQt5*.so files?
    I'm guessing it has to do with setting some environment variable or using some kind of tool that comes with Qt5 to "select" the installation you're using.
    FYI, prepending the python3.7 command with LD_LIBRARY_PATH=/home/david/.local/lib/python3.7/site-packages/ccdc/_lib gives the same error ... which is strange because python3.7 shouldn't know about anything in /usr/lib if it's run that way.

    Thanks in advance-
    David


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    One thing you can try is to use LD_PRELOAD to preload the custom Qt version you have.



  • LD_PRELOAD=/home/david/.local/lib/python3.7/site-packages/ccdc/_lib/libQt5Concurrent.so:/home/david/.local/lib/python3.7/site-packages/ccdc/_lib/libQt5Core.so:/home/david/.local/lib/python3.7/site-packages/ccdc/_lib/libQt5DBus.so:/home/david/.local/lib/python3.7/site-packages/ccdc/_lib/libQt5Gui.so:/home/david/.local/lib/python3.7/site-packages/ccdc/_lib/libQt5Network.so:/home/david/.local/lib/python3.7/site-packages/ccdc/_lib/libQt5OpenGL.so:/home/david/.local/lib/python3.7/site-packages/ccdc/_lib/libQt5Positioning.so:/home/david/.local/lib/python3.7/site-packages/ccdc/_lib/libQt5PrintSupport.so:/home/david/.local/lib/python3.7/site-packages/ccdc/_lib/libQt5Sql.so:/home/david/.local/lib/python3.7/site-packages/ccdc/_lib/libQt5Svg.so:/home/david/.local/lib/python3.7/site-packages/ccdc/_lib/libQt5Widgets.so:/home/david/.local/lib/python3.7/site-packages/ccdc/_lib/libQt5XcbQpa.so:/home/david/.local/lib/python3.7/site-packages/ccdc/_lib/libQt5Xml.so python3.7
    
    Python 3.7.8 (default, Jul 20 2020, 18:03:39) 
    [GCC 10.1.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import ccdc
    >>>
    

    Worked like magic. 😲
    Thanks a lot, @SGaist !


Log in to reply