Header file not found but added as library in project file and as header file



  • Good day

    please note: I have decided to take up a project I last worked on a year ago (including C++ dev, so I may be missing something really stupid)

    I previously used QTCreator 5.7.1, but upgraded to the latest 5.9.1, so I had to change all my build locations to the new 5.9.1 output location.

    Overview of libraries and project

    Various libraries named:

    • gen_common
    • gen_serv
    • misc_common
    • misc_cli
    • cli_gui

    to mention a few that are used. Each has its own .h and .cpp files.

    misc_common.h is added as an external library to misc_cli.
    misc_cli is added as a library to cli_gui.

    Problem:
    Compiling misc_cli (with misc_common and other libraries added) is successful
    Compiling cli_gui (with misc_cli and other libraries added) fails with an error:

    Error:

    /home/cybex/Projects/project-i/client/cli_gui/cli_gui_log.h:13: In file included from ../cli_gui/cli_gui_log.h:13:0,
    /home/cybex/Projects/project-i/client/cli_gui/cli_gui_main.h:12: from ../cli_gui/cli_gui_main.h:12,
    /home/cybex/Projects/project-i/client/cli_gui/main.cpp:3: from ../cli_gui/main.cpp:3:
    /home/cybex/Projects/project-i/libraries/misc_cli/misc_cli.h:9: error: misc_common.h: No such file or directory
     #include "misc_common.h"
              ^~~~~~~~~~~~~~~
    

    Compile output:

    /opt/Qt5.9.1/5.9.1/gcc_64/bin/uic ../cli_gui/cli_gui_log.ui -o ui_cli_gui_log.h
    /opt/Qt5.9.1/5.9.1/gcc_64/bin/uic ../cli_gui/cli_gui_main.ui -o ui_cli_gui_main.h
    /opt/Qt5.9.1/5.9.1/gcc_64/bin/uic ../cli_gui/cli_dlg_set.ui -o ui_cli_dlg_set.h
    g++ -c -pipe -g -Wall -W -D_REENTRANT -fPIC -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I../cli_gui -I. -I../../libraries/misc_cli -I../../libraries/gen_cli -I../../libraries/gen_common -I../../libraries/netman -I../../libraries/netman -I../../libraries/data_mananger -I../../libraries/data_mananger -I../../libraries/build-misc_common-Desktop_Qt_5_9_1_GCC_64bit-Debug -I../../libraries/build-misc_common-Desktop_Qt_5_9_1_GCC_64bit-Debug -I/opt/Qt5.9.1/5.9.1/gcc_64/include -I/opt/Qt5.9.1/5.9.1/gcc_64/include/QtWidgets -I/opt/Qt5.9.1/5.9.1/gcc_64/include/QtGui -I/opt/Qt5.9.1/5.9.1/gcc_64/include/QtNetwork -I/opt/Qt5.9.1/5.9.1/gcc_64/include/QtCore -I. -isystem /usr/include/libdrm -I. -I/opt/Qt5.9.1/5.9.1/gcc_64/mkspecs/linux-g++ -o main.o ../cli_gui/main.cpp
    In file included from ../cli_gui/cli_gui_log.h:13:0,
                     from ../cli_gui/cli_gui_main.h:12,
                     from ../cli_gui/main.cpp:3:
    ../../libraries/misc_cli/misc_cli.h:9:10: fatal error: misc_common.h: No such file or directory
     #include "misc_common.h"
              ^~~~~~~~~~~~~~~
    compilation terminated.
    make: *** [Makefile:2098: main.o] Error 1
    20:24:46: The process "/usr/bin/make" exited with code 2.
    Error while building/deploying project cli_gui (kit: Desktop Qt 5.9.1 GCC 64bit)
    The kit Desktop Qt 5.9.1 GCC 64bit has configuration issues which might be the root cause for this problem.
    When executing step "Make"
    20:24:46: Elapsed time: 00:00.
    

    misc_cli header:

    #ifndef MISC_CLI_H
    #define MISC_CLI_H
    
    #include <QColor>
    #include <QString>
    #include <QList>
    
    #include "misc_cli_global.h"
    #include "misc_common.h"
    
    using namespace misc_common;
    
    namespace misc_cli {
    
    class MISC_CLISHARED_EXPORT misc_cli
        {
    
    //structs 
    //enums
    //variable declarations 
    public:
            misc_cli();
        };
    
    
    }
    
    #endif // MISC_CLI_H
    

    cli_gui_log header:

    #include <QLineEdit>
    #include <QDebug>
    #include <QtGui>
    #include <QPushButton>
    #include <QMessageBox>
    #include <QDesktopWidget>
    #include <QCheckBox>
    
    #include "misc_cli.h"
    #include "data_mananger.h"
    
    Q_DECLARE_LOGGING_CATEGORY(log_client_gui_log)
    
    using namespace misc_cli;
    
    namespace Ui {
    class cli_gui_log;
    }
    

    misc_cli.pro

    #-------------------------------------------------
    #
    # Project created by QtCreator 2017-01-15T21:25:10
    #
    #-------------------------------------------------
    
    QT       += core gui widgets network
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = cli_gui
    TEMPLATE = app
    
    
    SOURCES += main.cpp\
        cli_gui_main.cpp \
        cli_gui_log.cpp \
        cli_dlg_set.cpp
    
    HEADERS  += \
        cli_gui_main.h \
        cli_gui_log.h \
        cli_dlg_set.h
    
    FORMS    += \
        cli_gui_log.ui \
        cli_gui_main.ui \
        cli_dlg_set.ui
    
    RESOURCES += \
        resources.qrc
    
    QMAKE_LFLAGS += -Wl,-rpath,"'\$$ORIGIN'"
    
    
    # ============================ MISC_CLI =====================================
    
    # WINDOWS - MINGW
    
    
    
    # UNIX - GCC
    
    
    
    unix:!macx: LIBS += -L$$PWD/../../libraries/build-misc_cli-Desktop_Qt_5_9_1_GCC_64bit-Debug/ -lmisc_cli
    
    INCLUDEPATH += $$PWD/../../libraries/misc_cli
    DEPENDPATH += $$PWD/../../libraries/misc_cli
    
    # =======================================================================
    
    

    In summary

    misc_common <-----> misc_cli ....................OK
    misc_cli <-----> cli_gui_log ....................FAIL

    Why does this occur, I have absolutely no idea why?


  • Lifetime Qt Champion

    Hi,

    Since your misc_cli headers include files from misc_common, you also have the add that path to the misc_gui project otherwise they can't be found.

    As for your hardcoded path, you should rather use OUT_PWD.



  • @SGaist Thanks for responding, here is the results from your suggestion:

    I have done so, yet it still complains that misc_common.h cannot be found

    please note: this error occurs when building the gui application, and not the misc_cli library. When building the misc_cli library which uses misc_common, it compiles correctly, but when comiling the 'misc_gui' application, the error below occurs.

    The error (of compiling the gui application) points me to the misc_cli header file highlighting the line

    #include "misc_common.h"
    

    and in my 'misc_gui' application, I make use of only the misc_cli.h file as shown below

    #include "misc_cli.h"
    

    Here is my 'misc_gui' project file

    //...
    # ============================ MISC_CLI =====================================
    
    # WINDOWS - MINGW
    
    
    # UNIX - GCC
    
    
    
    unix:!macx: LIBS += -L$$PWD/../../libraries/build-misc_cli-Desktop_Qt_5_9_1_GCC_64bit-Debug/ -lmisc_cli
    
    INCLUDEPATH += $$PWD/../../libraries/misc_cli
    DEPENDPATH += $$PWD/../../libraries/misc_cli
    
    # =======================================================================
    
    # ============================ MISC_CLI =====================================
    
    # WINDOWS - MINGW
    
    
    win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../libraries/build-misc_common-Desktop_Qt_5_9_1_GCC_64bit-Debug/release/ -lmisc_common
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../libraries/build-misc_common-Desktop_Qt_5_9_1_GCC_64bit-Debug/debug/ -lmisc_common
    
    # UNIX - GCC
    
    else:unix: LIBS += -L$$PWD/../../libraries/build-misc_common-Desktop_Qt_5_9_1_GCC_64bit-Debug/ -lmisc_common
    
    INCLUDEPATH += $$PWD/../../libraries/build-misc_common-Desktop_Qt_5_9_1_GCC_64bit-Debug
    DEPENDPATH += $$PWD/../../libraries/build-misc_common-Desktop_Qt_5_9_1_GCC_64bit-Debug
    
    # =======================================================================
    

    and compile output reads:

    23:22:03: Running steps for project cli_gui...
    23:22:03: Configuration unchanged, skipping qmake step.
    23:22:03: Starting: "/usr/bin/make" 
    g++ -c -pipe -g -Wall -W -D_REENTRANT -fPIC -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I../cli_gui -I. -I../../libraries/gen_cli -I../../libraries/gen_common -I../../libraries/netman -I../../libraries/netman -I../../libraries/data_mananger -I../../libraries/data_mananger -I../../libraries/misc_cli -I../../libraries/build-misc_common-Desktop_Qt_5_9_1_GCC_64bit-Debug -I/opt/Qt5.9.1/5.9.1/gcc_64/include -I/opt/Qt5.9.1/5.9.1/gcc_64/include/QtWidgets -I/opt/Qt5.9.1/5.9.1/gcc_64/include/QtGui -I/opt/Qt5.9.1/5.9.1/gcc_64/include/QtNetwork -I/opt/Qt5.9.1/5.9.1/gcc_64/include/QtCore -I. -isystem /usr/include/libdrm -I. -I/opt/Qt5.9.1/5.9.1/gcc_64/mkspecs/linux-g++ -o main.o ../cli_gui/main.cpp
    In file included from ../cli_gui/cli_gui_log.h:13:0,
                     from ../cli_gui/cli_gui_main.h:12,
                     from ../cli_gui/main.cpp:3:
    ../../libraries/misc_cli/misc_cli.h:9:10: fatal error: misc_common.h: No such file or directory
     #include "misc_common.h"
              ^~~~~~~~~~~~~~~
    compilation terminated.
    make: *** [Makefile:2098: main.o] Error 1
    23:22:03: The process "/usr/bin/make" exited with code 2.
    Error while building/deploying project cli_gui (kit: Desktop Qt 5.9.1 GCC 64bit)
    The kit Desktop Qt 5.9.1 GCC 64bit has configuration issues which might be the root cause for this problem.
    When executing step "Make"
    23:22:03: Elapsed time: 00:00.
    

  • Lifetime Qt Champion

    "misc_common.h" is located in the "misc_common" folder, no ? That's the one you have to add to your project.



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