Qt 中.prl文件是为表明依赖库关系而创建的:
Often when linking against a library, qmake relies on the underlying platform to know what other libraries this library links against, and lets the platform pull them in. In many cases, however, this is not sufficient. For example, when statically linking a library, no other libraries are linked to, and therefore no dependencies to those libraries are created. However, an application that later links against this library will need to know where to find the symbols that the static library will require. qmake attempts to keep track of the dependencies of a library, where appropriate, if you explicitly enable tracking.
.prl文件来源:
The first step is to enable dependency tracking in the library itself. To do this you must tell qmake to save information about the library:
CONFIG += create_prl
This is only relevant to the lib template, and will be ignored for all others. When this option is enabled, qmake will create a file ending in .prl which will save some meta-information about the library. This metafile is just like an ordinary project file, but only contains internal variable declarations. When installing this library, by specifying it as a target in an INSTALLS declaration, qmake will automatically copy the .prl file to the installation path.
.prl文件使用:
The second step in this process is to enable reading of this meta information in the applications that use the static library:
CONFIG += link_prl
When this is enabled, qmake will process all libraries linked to by the application and find their meta-information. qmake will use this to determine the relevant linking information, specifically adding values to the application project file's list of DEFINES as well as LIBS. Once qmake has processed this file, it will then look through the newly introduced libraries in the LIBS variable, and find their dependent .prl files, continuing until all libraries have been resolved. At this point, the Makefile is created as usual, and the libraries are linked explicitly against the application.
The .prl files should be created by qmake only, and should not be transferred between operating systems, as they may contain platform-dependent information.
使用.prl文件注意事项:
在使用Qt4.8.6静态库时,发现编译后的静态库lib\***.prl文件中QMAKE_PRL_LIBS项,包含编译时的相对全路径,例如:
QMAKE_PRL_LIBS = gdi32.lib comdlg32.lib oleaut32.lib imm32.lib winmm.lib winspool.lib ws2_32.lib ole32.lib user32.lib advapi32.lib msimg32.lib shell32.lib d:\\Qt_StaticSrc\\qt-everywhere-opensource-src-4.8.6\\lib\\QtCore.lib kernel32.lib uuid.lib
导致qmake生成的makefile.debug中包含有
LIBS =...., d:\\Qt_StaticSrc\\qt-everywhere-opensource-src-4.8.6\\lib\\QtCore.lib ....
编译提示“找不到d:\\Qt_StaticSrc\\qt-everywhere-opensource-src-4.8.6\\lib\\QtCore.lib ”。
解决方法:
打开QT库对应***.prl文件,将
QMAKE_PRL_LIBS = gdi32.lib comdlg32.lib oleaut32.lib imm32.lib winmm.lib winspool.lib ws2_32.lib ole32.lib user32.lib advapi32.lib msimg32.lib shell32.lib d:\\Qt_StaticSrc\\qt-everywhere-opensource-src-4.8.6\\lib\\QtCore.lib kernel32.lib uuid.lib
改为
QMAKE_PRL_LIBS = gdi32.lib comdlg32.lib oleaut32.lib imm32.lib winmm.lib winspool.lib ws2_32.lib ole32.lib user32.lib advapi32.lib msimg32.lib shell32.lib $$[QT_INSTALL_LIBS]\\QtCore.lib kernel32.lib uuid.lib
保存,重新qmake编译即可。