[SOLVED] Wrong header file included in project

  • Hello,

    I'm having a problem with my project file in QtCreator and haven't been able to figure it out.

    I have a directory with a project, that uses a hardware device and its libraries; as I don't have always the hardware available, I've make a project with some dummy object in a different directory to test my code. I have used this solution before without a problem, but for some reason is not working in this case.

    My directories look like this:
    @DiagnosticBox <--- This directory is used when the hardware is present
    -labjack.h and labjack.cpp

    • adminpanel.h and adminpanel.cpp
    • connectiondialog.h and connectiondialog.cpp
    • labjackUD.h <---- This is the library header of the hardware

    -labjack.h and labjack.cpp <---- This class is a dummy class, with no hardware dependencies@

    My .pro file is:

    QT += core gui network

    TARGET = testDiagnosticBox
    INCLUDEPATH += ./DiagnosticBox/

    TEMPLATE = app

    SOURCES += main.cpp
    labjack.cpp \

    HEADERS += mainwindow.h
    labjack.h \

    FORMS += mainwindow.ui

    The problem is that, when I try to compile the project testDiagnosticBox I receive the error

    @...\DiagnosticBox\labjack.h:5: error: LabJackUD.h: No such file or directory@

    Meaning that even though is not listed in my SOURCES or HEADERS, qmake is using the file in DiagnosticBox and not the one in testDiagnosticBox, is that the expected behavior ? How can I avoid that ? Should it not be taking the file in testEncoderBox ?

  • The labjack.h file is included in some other files of your project.
    I guess it is included without directory name like @#include "labjack.h"@

    And if that file with "#include "labjack.h" is located in DiagnosticBox then compiler takes labjack.h from the same directory.
    The variables SOURCES and HEADERS are for qmake only a compiler reads included files according its own options and that options are defined by INCLUDEPATH.
    To avoid it you need to specify different INCLUDEPATH for your test library.

  • Thanks a lot andreyc, I was assuming that HEADERS and SOURCES where somehow also used by the compiler.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.