dylib issues with multiple Qt versions installed
-
So I have multiple versions of Qt installed (the 2 of interest are Qt4.8 and Qt5.11).
Both versions were installed using homebrew, so they're installed in /usr/local/Cellar/qt/4.8.7.2 and 5.11.2 respectively.
I can build my project using either version perfectly fine (via cmd line or Qt Creator). I can run either version using Qt Creator, but when I try to run the Qt4 build via cmd line, I get the following error:
dyld: Library not loaded: /usr/local/opt/qt/lib/QtSvg.framework/Versions/4/QtSvg Referenced from: /Users/brad/labcode/qt4/libs/release/momadataview.app/Contents/MacOS/./momadataview Reason: image not found [1] 54979 abort ./momadataview
As you can see, it attempts to load the library located at /usr/local/opt/qt/lib. However, my /usr/local/opt is a symlink to the qt5 version.
Here is the otool -L output:
momadataview: /usr/local/opt/qt/lib/QtSvg.framework/Versions/4/QtSvg (compatibility version 4.8.0, current version 4.8.7) /usr/local/opt/qt/lib/QtGui.framework/Versions/4/QtGui (compatibility version 4.8.0, current version 4.8.7) /usr/local/opt/qt/lib/QtCore.framework/Versions/4/QtCore (compatibility version 4.8.0, current version 4.8.7) /usr/local/opt/qt/lib/QtXml.framework/Versions/4/QtXml (compatibility version 4.8.0, current version 4.8.7) /usr/local/opt/qt/lib/QtNetwork.framework/Versions/4/QtNetwork (compatibility version 4.8.0, current version 4.8.7) /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 104.1.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.50.4) /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 356.0.0)
If I simply change the /usr/local/opt/qt symlink to point to the qt4 version, then it runs perfectly fine as expected.
So, I guess I have a few questions:
- When is this dylib linking resolved and where is it getting this info from? I tried looking in some of the mkspecs, but I couldn't find anything that stuck out.
- Is there an easy fix for this? Ideally, when I build with qt4, the resolved dylibs should be the ones in the qt4 dir.
- Why does it run fine via Qt Creator? Is there extra settings in Qt Creator that's somehow resolving the incorrect dylib linking? Note that I don't use shadow building, so building via Qt Creator or cmd line generates files at the same location.
Thanks!!
-
Hi,
Qt Creator modifies the environment so it uses the Qt version configured in the Kit you use for the project.
Use otool to check the Id of your dependencies. You likely have one or the other that doesn't use a full path. You can use the
DYLD_LIBRARY_PATH
environment variable to set additional folders to search for dependencies. -
Hi,
Qt Creator modifies the environment so it uses the Qt version configured in the Kit you use for the project.
Use otool to check the Id of your dependencies. You likely have one or the other that doesn't use a full path. You can use the
DYLD_LIBRARY_PATH
environment variable to set additional folders to search for dependencies. -
You can use macdeployqt before starting it from the command line.