Works fine in Qt Creator, but not so much outside
-
This is probably another ignorant rookie question. I did try searching the forum before posting, but every time I hit back out of a topic my search results were gone I was back to a blank search bar.
I have a "project":https://sourceforge.net/projects/vimat/ that I've been working on in Qt Creator 2.7.1 using Qt 4.8 on Ubuntu 12.04. It is a subdirs project which I chose because I thought it would make it easier to create apps for multiple platforms from the same library of code. I did run into a little problem with the build order a few days ago and I wonder if that is still my problem now.
The minimal GUI app that I have within the project compiles and runs perfectly well inside Qt Creator. When I shut my IDE down and attempt to execute the binary, I am getting this: "./vimatGUIApp: error while loading shared libraries: libvimatLibrary.so.1: cannot open shared object file: No such file or directory." Although I am not sure why it is building multiple versions of the same library (probably a dumb mistake on my part), when I navigate through the project's file structure I find that this file does indeed exist. I've seen many people posting issues with 3rd party libraries or libraries external to their own project. This is a problem with my own library. Any ideas?
-
Hi,
You can try copying searched libraries to your app location or use "QCoreApplication::addLibraryPath()":http://qt-project.org/doc/qt-5.0/qtcore/qcoreapplication.html#addLibraryPath and/or "QCoreApplication::setLibraryPaths()":http://qt-project.org/doc/qt-5.0/qtcore/qcoreapplication.html#setLibraryPaths
Hope it help. Regards. -
According to the details on Nautilus file browser, the .so.1.0.0 file seems to be the actual shared libraries while all the others (.so.1.0, .so.1, .so) are links. Even though they are links, they are all the same size. There must be code in there that is lost when I copy, because the file size is reduced from 17 kB to 24 bytes. When I copy the files into my app folder the links become broken.
UPDATE: I realize after posting a reply that addLibraryPath is a part of QCoreApplication and not QLibrary. I was following the links looking for example usage. So, is it as easy as adding:
QCoreApplication::addLibraryPath("../myLibrary");
and/or
QCoreApplication::setLibraryPaths({"../myLibrary", "../myOtherLibrary"});
right before the main function?
-
Please check the article for "Deploying an Application on X11 Platforms":http://qt-project.org/doc/qt-4.8/deployment-x11.html to see how you can deploy and run your app without Qt Creator on Ubuntu and other Linux distributions.
-
Woe is me.
This is what I added to the main.cpp in my app:
@ QApplication a(argc, argv);
a.addLibraryPath("../vimatLibrary"); a.addLibraryPath("../vimatDB"); QStringList paths; paths << "../vimatLibrary" << "../vimatDB"; a.setLibraryPaths(paths);@
After cleaning and building, I'm still getting the same error at the command line when I try to run the program. Did I do it wrong?
UPDATE: Thanks Leon. I didn't see your post until after I finished my own. I will start exploring that right now.
-
I was reading the aforementioned "Deploying an Application on X11 Platforms" article and they're referring to the Plug & Paint libraries as plugins. Does this mean I have to convert my C++ libraries into Qt Plugins? It seems that, for a program that runs fine inside the IDE, this is a lot of extra work to build an executable. Is there nothing more obvious or simple that I'm overlooking? Is removing the basic functionality from the app and putting it in a plain C++ library to be called upon by the app an atypical project structure for Qt applications?
-
You need to either install your libraries into a place where they are available systemwide (usually /usr/local/lib, or if you are packaging /usr/lib). Check /etc/ld.so.conf and the files it includes for a complete list.
Alternatively you can set the environment variable LD_LIBRARY_PATH to point to your libraries. Copying the libraries next to the executable does not work on Linux.
QCoreApplication::addLibraryPath() does not help to find libraries that are loaded by the linker as this code runs long after the linker is done loading the libraries. This effects plugins and libraries loaded with QLibrary only.
-
Thank you very much for the help here. I think I'm going to temporarily restructure my project to use classes within the app folder and come back to the idea of using libraries later. I highly doubt anyone would want my libraries installed on their operating system. It seems like an advanced topic that I'm not quite ready for yet. My wife tells me I can be trying at times, but everyone here has been patient and helpful. I appreciate it.
-
I guess it all depends on how you are going to deploy your application to other ubuntu users. If you wrap them up into a nice .deb package then putting libraries into /usr/lib is basically expected.