Reputation: 99
I'm trying to create project structure like below
test/
test.pro
build/
build.pro
main.cpp
gui/
gui.pro
mainwindow.h
mainwindow.cpp
My test.pro looks like this:
TEMPLATE = subdirs
SUBDIRS = gui
CONFIG += ordered
SUBDIRS +=build
build.pro
TEMPLATE = app
QT += core gui
SOURCES += main.cpp
LIBS += -L../gui
gui.pro
TEMPLATE = lib
SOURCES += \
mainwindow.cpp
HEADERS += \
mainwindow.h
mainwindow.cpp
#include "mainwindow.h"
MainWindow::MainWindow(){}
MainWindow::~MainWindow(){}
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class MainWindow : public QMainWindow
{
public:
MainWindow();
~MainWindow();
};
#endif // MAINWINDOW_H
main.cpp
#include <QApplication>
#include "gui/mainwindow.h" //error
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
//MainWindow w;
//w.show();
return a.exec();
}
I got an error during compilation:
../../test/build/main.cpp:2:25: error: gui/gui.h: No such file or directory
What am I doing wrong?
Thanks bruno. I changed the line:
#include "gui/mainwindow.h"
to
#include "../gui/mainwindow.h"
But now I have error like below:
undefined reference to `MainWindow::MainWindow()'
undefined reference to `MainWindow::~MainWindow()'
My mainwindow.cpp file looks like below:
#include "mainwindow.h"
MainWindow::MainWindow()
{}
MainWindow::~MainWindow()
{}
How should I add a mainwindow.h file to mainwindow.cpp??
Upvotes: 1
Views: 1840
Reputation: 99
When I changed build.pro file to:
TEMPLATE = app
QT += core gui
SOURCES += main.cpp
LIBS += -L../gui/debug -lgui
application exited with code -1073741515.
Maybe the path in libs section is wrong?
Below files tree generated by qt:
test/
test.pro
build/
build.pro
main.cpp
gui/
gui.pro
mainwindow.h
mainwindow.cpp
test-build-desktop/
Makefile
build/
debug/
release/
Makefile
Makefile.Debug
Makefile.Release
gui/
debug/
gui.dll
libgui.a
mainwindow.o
release/
Makefile
Makefile.Debug
Makefile.Release
I checked the exe file by Dependency Walker: LINK to image
Upvotes: 1
Reputation: 2882
I do not know what I'm doing wrong? When I comment out #include "gui/mainwindow.h" then everything is OK.
I think the problem is in your include directive. Try changing it to
#include "../gui/mainwindow.h"
When the preprocessor finds an
#include
directive it replaces it by the entire content of the specified file. There are two ways to specify a file to be included:
#include "file"
#include <file>
The only difference between both expressions is the places (directories) where the compiler is going to look for the file. In the first case where the file name is specified between double-quotes, the file is searched first in the same directory that includes the file containing the directive. In case that it is not there, the compiler searches the file in the default directories where it is configured to look for the standard header files. If the file name is enclosed between angle-brackets <> the file is searched directly where the compiler is configured to look for the standard header files. Therefore, standard header files are usually included in angle-brackets, while other specific header files are included using quotes.
http://msdn.microsoft.com/en-us/library/36k2cdd4%28VS.80%29.aspx
Edited:
Now for the undefined reference error. You need to change your build.pro file.
Change:
LIBS += -L../gui
to something like
LIBS += -L../gui/debug -lgui
(the path ../gui/debug works for me because that is the place where the lib "gui" is located)
The idea is that you have to separate the directory where the library is located from the library name (without the extension and without any 'lib' prefix).
See this question here: Adding external library into Qt Creator project
Upvotes: 0
Reputation: 92874
error: gui/gui.h: No such file or directory
That's because there is no such file in that directory. :)
There are only 3 files in that directory
gui.pro
mainwindow.h
and
mainwindow.cpp
.
I think you wanted to include "gui/mainwindow.h"
, right?
Upvotes: 0
Reputation: 13025
test/
test.pro
build/
build.pro
main.cpp
gui/
gui.pro
mainwindow.h
mainwindow.cpp
There is no file named gui.h
in gui
directory - causing the error.
EDIT
May be you wanted gui/mainwindow.h
to include?
Upvotes: 0