Depending on the project needs, there may be different versions of the QT program to run on the same machine, This experiment is qt4.8.5 and qt5.3.1 developed by the same machine, the machine can not follow any version of QT, of course, two versions of QT development must be the same as the number of machines, for example, 32-bit or 64-bit.
Two versions of QT program I use dynamic compilation (static compilation Method please Niang), so need to run the program needed to put the dynamic library to the program can be linked to the place, the program can link the dynamic library path see: Linux Dynamic Library search path. Here directly to the conclusion: Dynamic Library search Path search sequence is:
1. The dynamic library search path specified when compiling the target code;
2. Environment variable LD_LIBRARY_PATH the specified dynamic library search path;
3. The dynamic library search path specified in the configuration file/etc/ld.so.conf;
4. The default dynamic library search path/lib;
5. The default dynamic library search path/usr/lib.
Considering that a machine is running multiple versions of QT, and it is not necessary for a machine to install a certain version of QT, the dynamic library required for different QT versions of the program is best placed in the dynamic library path specified in the build target code, so the path is independent, because if the dynamic library is placed in/lib and/usr/ LIB, then other versions of the QT program will also go to this place to search for dynamic libraries, there may be conflicts. Therefore, my qt4.8.5 and qt5.3.1 programs here specify the dynamic library path as Lib under the directory where the project is located at compile time.
First, for qt4.8.5 specific operation as follows:
1) Modify the project file (. Pro file), plus a line libs + =-l./lib, note that there can be no space after-L, the dynamic library path that you specify (you can freely specify), and then save the file.
2) in the terminal to the directory where you work, execute the command qmake Xxx.pro, where Xxx.pro is your project file, command after the completion of the execution of makefile, with VI or other tools to open makefile, and then search libs, you can see that our libs here has been added to the. Pro file you just configured. LIB, as shown in the figure (-l./lib):
3) Execute make to get the executable file XXX.
Test method: Through the LDD command to see the XXX dependent dynamic library pointing to where, the command is as follows:
LDD Untitled | Grep-i Qt, #这里的untitled为刚才make出来的可执行文件
The result of the command execution is:
Libqtgui.so.4 =/usr/local/trolltech/qt-4.8.5/lib/libqtgui.so.4 (0x00007f289a88e000)
Libqtcore.so.4 =/usr/local/trolltech/qt-4.8.5/lib/libqtcore.so.4 (0x00007f289a3a0000),
It can be seen that the compiled executable file of the dynamic library is pointing to/usr/local/trolltech/qt-4.8.5/lib/, this path is the installation path of QT, the personal guess is that you use Qtcreator to write the QT program has been the default add this dynamic library search path, This is qtcreator already configured with this path, see Qtcreator Tools-->options-->build & run-->kits-->qt Version for details.
First we copy these dependent libraries to the lib of our executable's sibling directory, we first use the terminal to go to the directory where our QT works, execute the following commands:
MkDir Lib #创建lib目录, the directory name must be the same as the directory name we specified after the new libs + =-L in the pro file
Cp/usr/local/trolltech/qt-4.8.5/lib/libqtgui.so.4./lib #把依赖的库拷贝到lib里面
Cp/usr/local/trolltech/qt-4.8.5/lib/libqtcore.so.4./lib
We simulate a machine that does not have QT installed by masking the dynamic library path pointed to by the current executable, and executes the following command:
Cd/usr/local/trolltech/qt-4.8.5;mv Lib Lib-bak,
After renaming Lib, we re-executed the LDD untitled | Grep-i QT, the result of the command is as follows:
Libqtgui.so.4 =/lib/libqtgui.so.4 (0x00007f89a6631000)
Libqtcore.so.4 =/lib/libqtcore.so.4 (0x00007f89a6142000),
It can be seen that the executable file at this point automatically points the dynamic library path to the./lib that we executed at compile time, and runs the executable.
Finally, when we publish the file, we want to copy Lib to the current directory of the executable file, and copy the required library into Lib, and publish the executable file with Lib.
Second, for qt5.3.1:
Here I use the same method as qt4.8.5, create the Lib directory in the directory where the project files are located, and then add libs + =/lib to the. Pro file, then Qmake Xxx.pro again, then make, then LDD XXX | Grep-i qt, then, copy all so files from the command execution to the Lib in the directory where the project is located, and then block out LDD XXX | Grep-i qt Command execution results in the QT installation path corresponding to the LIB, that is, the corresponding Lib to change the name, and then run our make out of the executable program, and then prompt for errors, error while loading shared libraries: Libqt5widgets.so.5:cannot open Shared object file:no such file or directory, then I use LDD to view the dynamic library link case, LDD version531 | Grep-i Qt, (version531 for Make out executable program), the result is as follows:
Libqt5widgets.so.5 = not Found
Libqt5gui.so.5 = not Found
Libqt5core.so.5 = not Found
But I look at the project directory in the directory of the LIB, there are these files, but a soft connection, but this soft link to the file I have been copied in the Lib, do not know why or hint can not find, no way, I only through the environment variable Ld_library_ path Specifies the dynamic library search path to LIB, and executes the following command:
Export Ld_library_path=./lib
At this point, run the executable again, and then make an error, prompting the following:
This application failed-to-start because it could not find or load the Qt platform plugin "XCB".
Reinstalling the application may fix this problem.
Aborted
This error, I searched on the Internet, the cause of this error is qt5 new features caused, the final solution in the project directory to create the platforms directory, and then put the installation Qt5 directory of the Lib directory of the same level directory of plugins/ Platforms inside the libqxcb.so copy to the newly created platforms directory, rerun the executable file, can run normally, at this time I set the LD_LIBRARY_PATH environment variable to empty also normal.
http://blog.csdn.net/u013281495/article/details/50540798
Running different versions of QT programs at the same time under Linux