Wednesday, April 10, 2013

Compile using pkg-config

pkg-config makes it easier to compile your source when you need to link libraries. For example, building a Qt application that has OpenGL support requires the following build command:

g++ source.cpp -DQT_SHARED -I/usr/include/qt4 -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4/QtGui  -lQtOpenGL -lQtGui -lQtCore  

With pkg-config that becomes:

g++ source.cpp `pkg-config --libs --cflags QtCore QtOpenGL `

Note the use of back-quotes  ``  to do in-line substitution. 

pkg-config can be integrated into eclipse through a pluggin and is also supported by qmake. Just add the following to your .pro file:

CONFIG += link_pkgconfig
PKGCONFIG +=  name_of_library

No comments:

Post a Comment