QT Subdir - 未定义对 main 的引用 - 错误 [英] QT Subdir- Undefined reference to main - Error
问题描述
我有一个简单的 QT subdir 项目,其结构为
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
这是我的 .pro 文件测试项目.pro
Here are my .pro files TestProject.pro
TEMPLATE = subdirs
SUBDIRS += \
Subdir1 \
Subdir2
Subdir1.pro
Subdir1.pro
SOURCES += \
main.cpp
Subdir2.pro
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'
我在 Ubuntu 12.04 上使用 Qt Creator IDE.我花了整整一上午的时间试图弄清楚这一点,我必须在 .pro 文件中放入什么才能让 Qt 能够构建项目?
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?
提前致谢
推荐答案
看起来您想要做的是将所有源文件构建到一个可执行文件中.这不是 subdirs 模板的用途,而是用于创建单个 Makefile 来构建多个不同的目标(例如两个不同的可执行文件,或者一个可执行文件和一个库).
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).
您可能想要的是只有一个 .pro 文件,例如
What you probably want is either to just have a single .pro file with e.g.
SOURCES = Subdir1/mainwindow.cpp Subdir1/main.cpp
或者您可以将 subdir pro 文件制作成(按照惯例).pri 文件.然后在顶层,您只需执行以下操作:
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)
这篇关于QT Subdir - 未定义对 main 的引用 - 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!