Search code examples
qt-creatorqmake

Linking library in QTCreator with QMake?


I'm a relatively new user of QTCreator, I've used the standard and QT libraries before but this is the first project I'm trying to add a exterior library and I'm having problems.

I'm trying to use the Point Cloud Library and as far as I can tell I installed it correctly in usr/lib yet when I try to do this simple tutorial the includes won't work:

#include <boost/thread/thread.hpp>
#include <pcl/common/common_headers.h>
#include <pcl/features/normal_3d.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/console/parse.h>

Gives me this error:

/home/george/Documents/QT/EditorPCL-build-desktop-Qt_4_8_1_in_PATH__System__Release/../EditorPCL/editor.cpp:7: error: pcl/common/common_headers.h: No such file or directory

Now I added the libraries through the GUI so syntactically I think the QMake file is correct but I don't have any ideea what's wrong.

Here is the relevant portion of the QMake file:

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../usr/lib/      -lpcl_visualization
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../usr/lib/   -lpcl_visualizationd
else:symbian: LIBS += -lpcl_visualization
else:unix: LIBS += -L$$PWD/../../../../../usr/lib/ -lpcl_visualization

INCLUDEPATH += $$PWD/../../../../../usr/lib
DEPENDPATH += $$PWD/../../../../../usr/lib

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../usr/lib/release/ -lpcl_common
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../usr/lib/debug/ -lpcl_common
else:symbian: LIBS += -lpcl_common
else:unix: LIBS += -L$$PWD/../../../../../usr/lib/ -lpcl_common

INCLUDEPATH += $$PWD/../../../../../usr/lib
DEPENDPATH += $$PWD/../../../../../usr/lib

 win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../usr/lib/release/ -lpcl_apps
 else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../usr/lib/debug/ -lpcl_apps
 else:symbian: LIBS += -lpcl_apps
 else:unix: LIBS += -L$$PWD/../../../../../usr/lib/ -lpcl_apps

 INCLUDEPATH += $$PWD/../../../../../usr/lib
 DEPENDPATH += $$PWD/../../../../../usr/lib 

Solution

  • Your error is thrown by the compile while it is trying to find headers.

    ... error: pcl/common/common_headers.h: No such file or directory
    

    That tells me that it is not finding the proper include path. Looking at your QMake file, I see you are setting your include path to

    INCLUDEPATH += $$PWD/../../../../../usr/lib
    

    On most Linux/Unix (and even Windows) systems, the includes are not in the subdirectory lib, but instead they are in the subdirectory include.

    Additionally, I do not like how you specified your both your LIBPATH and INCLUDEPATH. They will work if both the PWD and the installed location of the files never move. A better suggestion (at least for Unix/Linux) is to use the pkg-config utility. You might want to read the article Using pkg-config with Qmake and see if it will help.