I have a project where ClientLauncher is the executing subdir. I also have two libraries GUI and Metrics.
Initially ClientLauncher and GUI were "one", and that used the Metrics library and all was good. But I now get "filename.h": No such file or directory when compiling the program on every place where GUI includes something from Metrics.
The reason why I am changing this is because I want to be able to test all my code in another library UnitTests. For that reason I want to have everything in a library so that UnitTests can use that code.
So GUI is now a library, but it used to be the start of the program. To convert it to a library, I added TEMPLATE = lib to the .pro as you can see below.
ClientLauncher "launches" GUI. It only has main.cpp and includes "mainwindow.h" which is a header file in the GUI library.
ClientLauncher/main.cpp
#include "mainwindow.h"
int main(int argc, char *argv[]) {
return 0; //Actual code doesn't cause error
}
GUI/mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "metricslib.h" //ERROR: metricslib.h: No such file or directory
#endif
Metrics/metricslib.h
#ifndef METRICSLIB_H
#define METRICSLIB_H
//Nothing that causes error
#endif
I'm using a subdirs project as a root:
TEMPLATE = subdirs
QT += widgets
CONFIG += qt
SUBDIRS += \
ClientLauncher \
Metrics \
GUI
ClientLauncher.depends = GUI
GUI.depends = Metrics
ClientLauncher.pro
QT += core gui charts network sql widgets
CONFIG += c++11 console gui c++14
CONFIG -= app_bundle
SOURCES += \
main.cpp
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
unix|win32: LIBS += -L$$OUT_PWD/../GUI/ -lGUI
INCLUDEPATH += $$PWD/../GUI
DEPENDPATH += $$PWD/../GUI
GUI.pro
QT += core gui charts network sql widgets
TEMPLATE = lib
#DEFINES += GUI_LIBRARY
CONFIG += c++11 gui c++14
# Set icon
RC_ICONS = icon.ico
SOURCES += \
mainwindow.cpp \
HEADERS += \
mainwindow.h \
FORMS += \
mainwindow.ui \
RESOURCES += \
resources.qrc
## Metrics dependency ##
unix|win32: LIBS += -L$$OUT_PWD/../Metrics/ -lMetrics
INCLUDEPATH += $$PWD/../Metrics
DEPENDPATH += $$PWD/../Metrics
win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../Metrics/Metrics.lib
else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../Metrics/libMetrics.a
Metrics.pro
QT -= gui
TEMPLATE = lib
CONFIG += c++11 gui staticlib
HEADERS += \
metricslib.h
I am not sure I am reading this right I am a little tired but if I am right this is a simple fix.
so when include a existing file into your Project you have it in your project but... that is not how you include it you include the header file by the file path for example lets say the main file is
desktop/project/main.cppand one header isdesktop/project/GUI/header.hand another isdesktop/header2.hhere is how you get to them from main.cpp,I know it is a ruff example but I hope it helps have a good day!