tags:

views:

43

answers:

3

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
+1  A: 
CONFIG += link_pkgconfig
PKGCONFIG += opencv

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

Ken Bloom
I think this is on the right lines but it doesn't quite work. I'll update the question.
MVG
Maybe the site I got it from was wrong. I haven't tested it myself.
Ken Bloom
rasjani
@rasjani: Thanks. A lot of the time, I'm just good at googling. Thanks for filling in the details.
Ken Bloom
+1  A: 

Something like this in your qmake file should do

LIBS += `pkg-config --libs opencv`

Edit: Hmm, Ken Bloom's answer might be more portable, but erhm not documented?

nicomen
This works! Build tools are the work of the devil.
MVG
A: 

I'm brand new to stackoverflow so I cannot comment yet... Ken's answer worked great. I just had to remove the spaces on either side of the += first.

CONFIG+=link_pkgconfig PKGCONFIG+=opencv
Aaron Blondeau