How to add many libraries in Qt Creator (via project file) - c++

I have directory with many third-party libs (100 libs) and have directory with include files. How can I add all external libs in my project (in project file)?
I try that:
Myproject.pro
LIBS += -L'C:/Program Files/PCL 1.9.1/lib/'
INCLUDEPATH += 'C:/Program Files/PCL 1.9.1/include'
DEPENDPATH += 'C:/Program Files/PCL 1.9.1/include'
but that not work for me. Through Project->Add library-> External... I can add just one lib and it's so long to choose every lib to add.
Also if use that:
LIBS += -L'C:/Program Files/PCL 1.9.1/lib/' -lpcl_common_debug -lpcl_features_release -lpcl_kdtree_release...
It's so long, and I'm sure, should be short way to do it, like just add directory with libs and directory with include directory. Despite that simple thing, I can't find it at any.
I use qt 5.
Also, if you worked with pcl lib, I will glad to listen how to add this lib with all dependencies. Thanks

Nothing to it. Do it manually in the qmake project file after you’ve seen the pattern hinted at by the “Add Library” dialog box. The -L path only needs to be provided once. Then come the names of libraries with the -l prefix. As far as the build scripts go, it’s trivial stuff. You can begin to complain after your .pro file has more than a few hundred lines :)
I mean, let’s be serious: what’s a dozen or two -l name entries? It really is nothing. It should take you more time to ask such a. question than to actually add the libraries to the project.
Alternatively, use cmake, and assuming that the library has a cmake support module, it’ll all turn trivial as the module will pull in the needed dependencies. I’d advise against using qmake for any new development. It’s extremely unfortunate that Qt Creator still offers qmake templates as a default option. They have no place in anything but legacy code. Go cmake or go bust. I mean it.

Related

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
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

Static linking against non-binary libs

I want to make use of two libraries QCustomPlot and Eigen with Qt Creator on OS X.
Both do not need to be installed and work fine if I just put them into my project folder and add them to the project. They do not have to be installed, "you can use the header files right away".
However I want them to be more independet than that, located outside the project to be used by other projects as well and I don't want their headers and source files to appear with my project files. But I do not know how to link them statically.
INCLUDEPATH += /../../Eigen/Eigen \ and
Add Library... -> External Library
apperently does not work, second one because their is no library file to open.
I have no experience with libraries and tend to find this topic highly complicated.
For the template only include library INCLUDEPATH should be sufficient as noted in comments. Generally, you can do it by manually modifying YourProject.pro file like:
LIBS += -L$$PWD/path_relative_to_pro_file/lib -lmylibfile1 -lmyflibfile2
INCLUDEPATH += $$PWD/path_relative_to_pro_file/lib/include
And your library file names end with .lib.
In case if you want your project to be recompiled because of external library change:
DEPENDPATH += $$PWD/path_relative_to_pro_file/lib
DEPENDPATH += $$PWD/path_relative_to_pro_file/lib/include

Why does Qt add 'PWD' to libraries that are NOT referenced relatively?

Whenever I add a library in the .pro file of a Qt project (in Qt 5.2) it adds a $$PWD before the path of the libraries and include path. For example
INCLUDEPATH += $$PWD/C:/opencv/opencv-msvc2013/install/include
and
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/C:/opencv/opencv-msvc2013/install/x64/vc12/lib/
My question is
why does Qt start the path with the PWD (Present Working Directory) keyword if its providing an absolute path to the libraries? What logic/good programming practice is this convention following?
And most importantly why it does not result in an error? How does Qt know when to search relative to a working directory and when not to? (Since both cases start with the PWD keyword)
PS : I removed the $$PWD keywords and my code worked just fine as well.
In case both the project and the library are in the same drive, that would not happen and the relative path is generated automatically. But on Windows if you add a library which is in another drive, it would add $$PWD followed by an absolute path.
This sounds like a bug and it has been reported here but it's still unresolved.

Including external libraries to Qt

I am actually new at Qt and would be grateful if someone could explain how to deal with external C++ libraries in theses 3 cases and what is the easiest way to get a library working with Qt (if you could just point me out to some places where I can read about it):
- source .h and header .cpp files both available
- source .h and DLL
- source .h and .a files
I usually use the following procedure:
1- Cmake to generate make files
2- Building using Mingw:
Cd c:/test
qmake test.pro
mingw32-make
3- Including project to Qt:
INCLUDEPATH += C:/test/build/include
LIBS += C:\test\build\x64\mingw\lib\file.dll.a \ ...
I usually use Cmake first then qmake to build, but sometimes one is not working or often Qt option is not available in Cmake. I always read carefully the instructions. In general, how an experience programmer would make decisions on how to include a library?
You do not need cmake and qmake together -- One is enough. I mainly work with qmake when i'm in Qt Creator since it is well integrated with the IDE. Generally what you are doing is correct. You include headers under HEADERS +=, sources under SOURCES +=, libraries under LIBS += and the path to the include files under INCLUDEPATH +=.
Instead of manually adding the external library to the .pro file u can do one thing.
Right click on your main project, then select "add library" option then it will ask for
1. External library
2. Internal Library
3. System Library
then select External library , and rest all thing is done by the Qt Creator i.e it will automatically add the path to the .pro file and link the library to your project.

How to add a folder with multiple libs and a folder with multiple headers into your project with Qt?

So my problem is next: I need to connect to my project Boost, FFMpeg, OpenCV and OpenAL. I have putted all .lib files for tham into some C://libs/ and headers and additional source into C://headers/ and C://src/ so I have this 3 folders I will need to cnnect to my project... I am so very new to qt and I am starting to read books on it and stuff but by now I have not found info on connectimg additional libs and source folders for projects...
And If you happen to know how to do what I am asking fore I have one more question - I have a folder called C://dlls/ with dlls I need to be placed into folder with .exe file how to add such to .pro file?
I found something like
unix:LIBS += -L/usr/lib -lboost_regex
win32:LIBS +=C:/Qt/2010.02.1/qt/lib/libboost_regex.lib
but here they connect a file - not folder and only a lib - no headers=(
For the header files, add the path to the folders to the INCLUDEPATH variable:
INCLUDEPATH += C:/headers/
For the libraries, add them to your LIBs as in your example. You may need to do this one-by-one, or you could set something up for qmake to process the directory and add the given files.
LIBS +=C:/Qt/2010.02.1/qt/lib/libboost_regex.lib
For the source files, if the libraries are properly compiled, you shouldn't need to reference them in your code project. If you do, add them to the sources list like your other code to be compiled.
For the dlls, that is more of an installation problem than a compile problem. However, you might be able to give qmake a post-link command to run to copy the dlls into the same folder as the target executable.