1

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.

1 Answers1

1

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.

Nikos C.
  • 50,738
  • 9
  • 71
  • 96
  • I have compilation errors "**undefined reference to PoDoFo::PdfRect...** " I didn't find any libpodofo-0.pc though. And this doesn't specify which version of podofo will be used in my code does it ? – MsSkillz007 Jun 27 '19 at 11:59
  • It will use the version you installed. What Linux distro are you using? – Nikos C. Jun 27 '19 at 12:24
  • I'm using Ubuntu 18.04.2 – MsSkillz007 Jun 27 '19 at 12:28
  • @MsSkillz007 Have you installed `libpodofo-dev`? `sudo apt install libpodofo-dev`. After that, type `pkg-config --cflags libpodofo-0`. What does it print? – Nikos C. Jun 27 '19 at 12:52
  • At first i only installed libpodofo0.9.5, i've just installed the libpodofo-dev package and the command you asked for prints : **-I/usr/include/podofo** I still have the same errors while compiling though. It seems like the library is not well linked. – MsSkillz007 Jun 27 '19 at 13:35
  • @MsSkillz007 Do a clean step in the project and then run qmake again. Then check the generated `Makefile` in the build directory, specifically the line that begins with `LIBS =`. Is `-lpodofo-0` listed in there? – Nikos C. Jun 27 '19 at 13:45
  • I did a clean all and run qmake. In the Makefile in the line LIBS i have : `LIBS = $(SUBLIBS) -L/(repertory where Qt is installed)/gcc_64/lib -lQt5Widgets -otherlibraries` – MsSkillz007 Jun 27 '19 at 14:49
  • @MsSkillz007 Is pkg-config disabled in your project file, perhaps? At the beginning of it, is there a line that has `no-pkg-config` in it? – Nikos C. Jun 27 '19 at 15:03
  • @MsSkillz007 Also, as a test, add this to the pro file: `PKGCONFIG += asdf`. Then run qmake. Does it abort with an error that says `Project ERROR: asdf development package not found`? – Nikos C. Jun 27 '19 at 15:06
  • I think i needed to add `CONFIG += link_pkgconfig` i did that now it takes into account the PKGCONFIG flag. Now i have a cannot find -lpodofo-0 error. When i run the command `pkg-config --libs libpodofo-0` it prints -lpodofo-0.I also added a PKG_CONFIG_PATH in the run environment `/usr/lib/pkgconfig`. But always the same error cannot find -lpodofo-0 – MsSkillz007 Jun 28 '19 at 08:27
  • 1
    @MsSkillz007 It seems podofo installs a broken pkg-config file. The library is named `libpodofo` but the .pc file lists it with a `-0` in it. If you edit `/usr/lib/pkgconfig/libpodofo-0.pc` and replace ` -lpodofo-0` with ` -lpodofo` in the `Libs:` line, it should work. You should also file a bug report for this: https://help.ubuntu.com/community/ReportingBugs – Nikos C. Jun 28 '19 at 09:50