Quantcast
Channel: Qt DevNet forums: Installation and Deployment
Viewing all articles
Browse latest Browse all 2113

How can I properly force my Qt Application to loads shared libraries from Certain Directory when it loads?

$
0
0
I made my QtApplication (name: QtProjectWork ) in Qt5.2.1 and I compiled the binaries for 64 bit GCC running on LinuxMint. In my application I have used number of features such as CommandLineParser that are only avaliable on Qt > 5.2.0 In my programming environment I have installed the QtCreator and I have no problem in compiling and running the application and the required Qt shared libraries are directly loaded from the Qt5.2.1 installation path directory. so running following command returns: $ ldd QtProjectWork libQt5Network.so.5 => /opt/Qt/5.2.1/gcc_64/lib/libQt5Network.so.5 (0×00007ff2a78f5000) libQt5Core.so.5 => /opt/Qt/5.2.1/gcc_64/lib/libQt5Core.so.5 (0×00007ff2a7227000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0×00007ff2a6fe7000) libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0×00007ff2a6ce4000) …. The problem that I have is since I am going to deploy the code on other LinuxSystem which has no QtCreator installed and the user does not have enough privileges to update or install the libraries so once I hand out the code to the user I have to include the shared libraries with the executables. So I made a “Qtlibs” directory inside the QtProjectWork binary directory and put all the required libraries inside Qtlibs directory with their respective symbolic links (using ln -s and relative path) , so the Qtlibs contents are as follow: lrwxrwxrwx 1 btgarden btgarden 19 apr 1 10:43 libQt5Core.so -> libQt5Core.so.5.2.1 lrwxrwxrwx 1 btgarden btgarden 19 apr 1 10:55 libQt5Core.so.5 -> libQt5Core.so.5.2.1 -rwxr-xr-x 1 btgarden btgarden 5030256 mar 31 13:34 libQt5Core.so.5.2.1 lrwxrwxrwx 1 btgarden btgarden 19 apr 1 10:43 libQt5DBus.so -> libQt5DBus.so.5.2.1 lrwxrwxrwx 1 btgarden btgarden 19 apr 1 10:56 libQt5DBus.so.5 -> libQt5DBus.so.5.2.1 -rwxr-xr-x 1 btgarden btgarden 534744 feb 4 15:30 libQt5DBus.so.5.2.1 lrwxrwxrwx 1 btgarden btgarden 22 apr 1 10:43 libQt5Network.so -> libQt5Network.so.5.2.1 lrwxrwxrwx 1 btgarden btgarden 22 apr 1 10:56 libQt5Network.so.5 -> libQt5Network.so.5.2.1 -rwxr-xr-x 1 btgarden btgarden 1391448 feb 4 15:30 libQt5Network.so.5.2.1 In order to force the application to firstly load the shared libraries from the Qtlib directory I added following lines to very beginning of my application main.cpp: [Note:some part of the code is taken from http://stackoverflow.com/questions/20398461/deployment-of-qt-apps-under-linux] int main(int argc, char *argv[]) {       setlocale(LC_ALL,"C");     QCoreApplication a(argc, argv);     // Fixing LIBRARY PATH in LINUX     QString appFilePath = QCoreApplication::applicationFilePath();     QStringList paths = QCoreApplication::libraryPaths();     QCoreApplication::addLibraryPath(QString("%1/%2").arg(appFilePath).arg("Qtlibs"));     paths = QCoreApplication::libraryPaths();  // Ensures first path to search is in $APP_PATH/Qtlibs     QCoreApplication::setLibraryPaths(paths);// refreshing library paths if needed ! But this approach does not work and when I execute the $ ldd QtProjectWork I get same result as before. It does not load shared libraries from Qtlibs directory :-( . I have read different websites regarding shared libraries workarounds, and on has suggested to use a shell script (in linux) and “export LD_CONFIG_PATH=. “ which I rather not to use it (due to my multi-platform approach). I do not know if I have to use a.setLibraryPaths(paths) instead of (static method) QCoreApplication::setLibraryPaths(paths) !? or how can I solve the problem. Thanks in Advance

Viewing all articles
Browse latest Browse all 2113

Trending Articles