Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking libraries to a QT project using pkg-config output

Tags:

c++

qt

qmake

This is a bit of a newbie question. I am trying to add the OpenCV libraries to a QT project.

This question says the link flags are given by

pkg-config --libs opencv 

If I paste the command line output into the project file like:

LIBS += -L/usr/local/lib -lml -lcvaux -lhighgui -lcv -lcxcore 

then everything compiles fine, but now this isn't portable. How can I simply reference the output of the command?

Update: Tried Ken Bloom's suggestion, but it won't compile. The actual generated compiler commands are

# How it should be, at least on my machine g++ -o QOpenCVTest main.o qopencvtest.o moc_qopencvtest.o -L/usr/lib -L/usr/local/lib -lml -lcvaux -lhighgui -lcv -lcxcore -lQtGui -lQtCore -lpthread  # with CONFIG and PKGCONFIG g++ -o QOpenCVTest main.o qopencvtest.o moc_qopencvtest.o -L/usr/lib -lQtGui -lQtCore -lpthread 
like image 611
MVG Avatar asked Aug 19 '10 00:08

MVG


People also ask

How do I add an external library to QT?

For all libraries, select the target platforms for the application, library, or plugin. Specify whether the library is statically or dynamically linked. For a statically linked internal library, Qt Creator adds dependencies (target_link_libraries when using CMake or PRE_TARGETDEPS when using qmake) in the project file.

What is .pro file in Qt?

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 is qmake file?

QMake is a build system that generates Makefiles for GNU Make or project build files for Microsoft Visual Studio. It is part of the Qt software framework by Trolltech. While it is commonly used to construct Qt-based software, any project can benefit from it.

What is Pkgconfig in Linux?

pkg-config is a helper tool used when compiling applications and libraries. It helps you insert the correct compiler options on the command line so an application can use gcc -o test test. c `pkg-config --libs --cflags glib-2.0` for instance, rather than hard-coding values on where to find glib (or other libraries).


1 Answers

CONFIG += link_pkgconfig PKGCONFIG += opencv 

(I got this answer from http://beaufour.dk/blog/2008/02/using-pkgconfig.html)

like image 155
Ken Bloom Avatar answered Sep 28 '22 09:09

Ken Bloom