Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LIBS vs PRE_TARGETDEPS in .pro files of Qt

I am a newbie with in Qt & started appreciating the framework that qmake provides in .pro files. Primary objective of my question is to understand in detail the difference between qmake variables "LIBS" & "PRE_TARGETDEPS" with static linking of libraries.

My Qt App uses a bunch of C++ static libraries that it depends on. Again, the static libraries have interdependencies between themselves. Each library has a .pro file included in it to support qmake way of building. And of course the app also has a .pro file.

Now in the static libraries, if libStaticA is dependent on libStaticB where both are C++ libraries. And both of them have a .pro file each. Is it enough to mention the dependency in libStaticA.pro with +LIBS & -l like below ? +LIBS += -L/path_To_libStaticB/ -llibStaticB

Or is it enough to mention the dependency with PRE_TARGETDEPS like below +PRE_TARGETDEPS += /path_To_libStaticB/libStaticB.a

Or should I mention both ? +PRE_TARGETDEPS += /path_To_libStaticB/libStaticB.a +LIBS += /path_To_libStaticB/libStaticB.a

What is the relevance of LIBS & PRE_TARGETDEPS ?

PS: My development machine is osx. Thanks in advance for any explanations to clarify my understanding here

like image 772
Rubin Avatar asked Jun 16 '16 17:06

Rubin


People also ask

What is Qt .pro file?

pro) File. I'm sure you already know about the Qt Project File since we have mentioned it countless times throughout the book. A .pro file is actually the project file used by qmake to build your application, library, or plugin.

What pro and PRI file in Qt?

pri files is exactly the same as the format of the . pro files. The main difference is one of intent; a . pro is what most people would expect to run qmake on directly, while a .

Where is .pro file in Qt?

In the Qt Creator application, choose menu File->Open File or Project, navigate to the project folder and choose the . pro file to open.


1 Answers

LIBS:

Specifies a list of libraries to be linked into the project. If you use the Unix -l (library) and -L (library path) flags, qmake handles the libraries correctly on Windows (that is, passes the full path of the library to the linker). The library must exist for qmake to find the directory where a -l lib is located.

PRE_TARGETDEPS:

Lists libraries that the target depends on. Some backends, such as the generators for Visual Studio and Xcode project files, do not support this variable. Generally, this variable is supported internally by these build tools, and it is useful for explicitly listing dependent static libraries.

Qt uses the PRE_TARGETDEPS variable to store dependencies for statically linked libraries. It forces your library to get relinked everytime you build your application.
If you don't have this variable specified and you update and rebuild your library, your program will still use the old library.

For your question, if you use static libraries, you should (almost) always use both, LIB and PRE_TARGETDEPS.

Quote: Qmake variable reference
Also interesting: Adding libraries to Qt Projects

like image 73
OneStackOverflowUser Avatar answered Sep 20 '22 06:09

OneStackOverflowUser