c++linuxqtpodofo

How to include external libraries in Qt


I want some basic explanation about how external libraries are added to a Qt C++ project in a Linux environment I've installed a library called podofo in two ways : - Installed it with apt-get install libpodofo - Installed the source code and build it

Afterwards i added in the .pro file of my Qt Project : LIBS += -lpodofo

How do i choose whether he works with the first or the second one ? How am i supposed to add an external library with a lot of .jar files in my project ?

I figured it might be something in the run environment but i still don't get it. I tried changing it but it seemed better to just copy libraries manually in the file Qt is installed in.


Solution

  • Like most libraries on Linux, podofo installs a pkg-config file. The file is named libpodofo-0.pc. qmake has built-in support for that, so all you need to do is add this to your project file:

    PKGCONFIG += libpodofo-0
    

    (Note that for this to work, you might need to add link_pkgconfig to your CONFIG line.)

    Do not add anything to LIBS. qmake will call pkg-config and add the needed compiler and linker flags automatically. Specifically, it will add the correct -l flags for linking, and the correct -I flag for compiling (usually -I/usr/include/podofo). So when you include the podofo headers in your code, don't use #include <podofo/podofo.h>. Use #include <podofo.h> to keep your code portable when building on systems that might be using a different directory name to install the podofo headers.

    Make sure that the pkg-config tool is actually installed on your system though. pkg-config --version should print something like 0.29.1. If instead the command is not found, then install the pkg-config package of your Linux distribution.