Reputation: 863
I have a simple QT subdir project with the structure of
TestProject/
TestProject.pro
Subdir1/
Subdir1.pro
sources/
main.cpp
Subdir2/
Subdir2.pro
headers/
mainwindow.h
sources/
mainwindow.cpp
Here are my .pro files TestProject.pro
TEMPLATE = subdirs
SUBDIRS += \
Subdir1 \
Subdir2
Subdir1.pro
SOURCES += \
main.cpp
Subdir2.pro
QT += sql
SOURCES += \
mainwindow.cpp \
HEADERS += \
mainwindow.h \
When I try to run the application I get the following error:
(.text+0x18):-1: error: undefined reference to `main'
I am using the Qt Creator IDE on Ubuntu 12.04. I have spent all morining trying to figure this out, What must I put in the .pro files in order for Qt to be able to build the project?
Thanks in advance
Upvotes: 3
Views: 4395
Reputation: 5718
It looks like what you're trying to do is build all your source files into one executable. This is not what the subdirs template is for, it's for creating a single Makefile which builds several different targets (for example two different executables, or an executable and a library).
What you probably want is either to just have a single .pro file with e.g.
SOURCES = Subdir1/mainwindow.cpp Subdir1/main.cpp
Or you can make the subdir pro files into (by convention) .pri files. Then at the top level you would just do:
include(Subdir1/Subdir1.pri)
include(Subdir2/Subdir2.pri)
Upvotes: 4
Reputation: 29966
Try to add your Subdir.pro files into your TestProject.pro file explicitly:
OTHER_FILES += \
Subdir1/Subdir1.pro\
Subdir2/Subdir2.pro\
so Qt knows there are subprojects.
Upvotes: 1