简体   繁体   English

QT Subdir-对main的未定义引用-错误

[英]QT Subdir- Undefined reference to main - Error

I have a simple QT subdir project with the structure of 我有一个简单的QT subdir项目,其结构为

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 这是我的.pro文件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'

I am using the Qt Creator IDE on Ubuntu 12.04. 我在Ubuntu 12.04上使用Qt Creator IDE。 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? 我花了所有的精力试图弄清楚这一点,为了使Qt能够构建项目,我必须在.pro文件中放入哪些内容?

Thanks in advance 提前致谢

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). 这不是subdirs模板的用途,而是用于创建一个构建多个不同目标(例如,两个不同的可执行文件,一个可执行文件和一个库)的单个Makefile的。

What you probably want is either to just have a single .pro file with eg 您可能想要的是只包含一个.pro文件,例如

SOURCES = Subdir1/mainwindow.cpp Subdir1/main.cpp

Or you can make the subdir pro files into (by convention) .pri files. 或者,您可以将subdir pro文件转换为(按照惯例).pri文件。 Then at the top level you would just do: 然后,您将在顶层执行以下操作:

include(Subdir1/Subdir1.pri)
include(Subdir2/Subdir2.pri)

Try to add your Subdir.pro files into your TestProject.pro file explicitly: 尝试将Subdir.pro文件明确添加到TestProject.pro文件中:

OTHER_FILES += \
    Subdir1/Subdir1.pro\
    Subdir2/Subdir2.pro\

so Qt knows there are subprojects. 所以Qt知道有子项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM