I downloaded a library for processing DicOM FILES .
The tree of library is :
|--include
|-----dicom.h
|-----dicomcfg.h
|--lib
|--------dicomsdl.lib
But I do not know how to use and built-in Qt Creator .
If anyone can help me I will be very grateful.
I'll assume you use qmake as your build system.
To link your "external" library you need following changes in your .pro file:
#path to includes directory of your library, qmake will try to find includes there
INCLUDEPATH += /path/to/library/include
#path to pre-compiled library directory
LIBS += -L/path/to/precomp/library
#link your pre-compiled library, -l<library name> w/o .so, .a, .lib, lib- prefix
LIBS += -ldicomsdl
Maybe you'll need to build the library from source with your compiler. There could be some troubles if compilers don't match.
Related
I am developing a C++ app with Qt that depends on the GNU Scientific Library (GSL).
So far, I have linked GSL in the .pro file using LIBS += /path/to/my/GSL/location -l<name_of_the_library> and it works, but it depends on where I installed GSL.
I'd like the .pro file not to depend on the user-specific GSL path, and possibly include the precompiled libraries (for different OSes) in the project folder.
Is this possible?
In this case it works on all platforms. You have to separate the directory from the library name
LIBS += -L/path/to -lpsapi
In this case You store your lib files in the project directory.
LIBS += -L"$$_PRO_FILE_PWD_/3rdparty/libs/" -lpsapi
look at this for more: https://doc.qt.io/qtcreator/creator-project-qmake-libraries.html
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
I need the boost library for a project on my Raspberry Pi 2. I use QTCreator for coding but I cant add the Library. I tried to add this to the .pro file of my project in QTCreator:
LIBS += -L/usr/include/boost -lboost_chrono
I installed the boost Library using:
sudo apt-get install libboost1.55-all
If I try to compile my code I get the "boost/chrono.hpp no such file or directory".
I read somewhere that I have to compile the Library first using the same compiler as QtCreator (usually mingw) but I have no clue how to do that.(Im a beginner with the raspberry and the linux system in general)
Thx for your help
LIBS += -L
This adds a path to the linker. Your error is related to a path in the include. You should add the boost path via
INCLUDEPATH +=
As mentioned here: How to add include path in Qt Creator?
I'm trying to compile a simple program using the GeoIP2 lite API. I've compiled the GeoIP Lite program and it created the library files. The .la file is in /mydir/libmaxminddb-0.5.3/src
I modified my .pro file to include:
LIBS += /mydir/libmaxminddb-0.5.3 -lmaxminddb
but when I compile my project errors with "Cannot find -lmaxminddb"
Can someone tell me what's wrong? I've tried changing directories, adding a "lib" prefix to the maxminddb, and more, but I can't figure it out.
(I'm trying to link against libmaxminddb.a which is pointed to by libmaxminddb.la)
I believe in autoconf and friends the -l flags go in the LDFLAGS variabe, not LIBS.
I found elsewhere that with Qt Creator you can right click the project and add an external library. When I do so, I see the .pro file adds:
LIBS
INCLUDEPATH
DEPENDPATH
So that's what you need to add!
That should be LIBS += -L/mydir/libmaxminddb-0.5.3 -lmaxminddb. Note the extra -L in front of the directory name.
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.