Qmake 和 Make 使用单独的文件夹来存放源文件和标头

发布于 2024-10-04 16:36:28 字数 916 浏览 2 评论 0原文

我对这个愚蠢的问题快要疯了。

我有一棵这样的树:

src
|--- sources
        |--- one.cpp
        |--- two.cpp
        |--- sources.pro
|--- headers
        |--- one.h
        |--- two.hpp
        |--- headers.pro
|--- src.pro

我尝试了一切方法让它在两个文件夹中都能看到,但不知何故我无法让它工作。我对 QMake 不太了解,但我认为这很容易。我错了。

所以实际上我最终以这种方式获得了 src.pro 文件:


QT += dbus

CONFIG += warn_on
DEFINES = QT_FATAL_WARNINGS QT_NO_DEBUG_OUTPUT

devel {
  DEFINES -= QT_NO_DEBUG_OUTPUT
}

OBJECTS_DIR += build
MOC_DIR += build

TARGET = example

[...]

TEMPLATE = subdirs
SUBDIRS = sources \
          headers

[...]

以及 resources.pro 和 headers.pro 以这种方式:

sources.pro


SOURCES = one.cpp \
          two.cpp

headers.pro


HEADERS = one.h \
          two.hpp

以及当然(不是)问题是它仍然没有看到所有的东西。 我也看了文档,但我发誓我不明白,哈哈

I'm going mad on this stupid problem.

I've a tree like this:

src
|--- sources
        |--- one.cpp
        |--- two.cpp
        |--- sources.pro
|--- headers
        |--- one.h
        |--- two.hpp
        |--- headers.pro
|--- src.pro

I tried EVERYTHING to make it look in both the folders, but somehow I can't get it working. I don't know much about QMake, but I tought it was easy. And I was wrong.

So actually I ended up having the src.pro file in this way:


QT += dbus

CONFIG += warn_on
DEFINES = QT_FATAL_WARNINGS QT_NO_DEBUG_OUTPUT

devel {
  DEFINES -= QT_NO_DEBUG_OUTPUT
}

OBJECTS_DIR += build
MOC_DIR += build

TARGET = example

[...]

TEMPLATE = subdirs
SUBDIRS = sources \
          headers

[...]

And the sources.pro and headers.pro in this way:

sources.pro


SOURCES = one.cpp \
          two.cpp

headers.pro


HEADERS = one.h \
          two.hpp

And of course (not) the problem is that it still doesn't see the stuff all together.
I looked at the documentation too, but I swear I don't get it lol

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

漫漫岁月 2024-10-11 16:36:28

自从我不得不使用 qmake 以来已经有一段时间了(万岁 CMake!),但是你不能只设置.pro 文件中的 INCLUDEPATH 变量,即执行以下操作:

INCLUDEPATH += ./sources
INCLUDEPATH += ./headers
INCLUDEPATH += ../utils/include
# (etc, etc.)

然后只需将 SOURCES var 中的条目指向 sources 文件夹如下:

SOURCES = sources/one.cpp \
          sources/two.cpp

我不清楚为什么要使用 TEMPLATE = subdirs。对于你的情况来说似乎没有必要。难道你不能只使用TEMPLATE = app(或TEMPLATE = lib)并完成它吗?像这样的东西:

QT += dbus
TEMPLATE = app
TARGET = example

INCLUDEPATH += ./sources

SOURCES += sources/one.cpp \
           sources/two.cpp

It's been awhile since I've had to use qmake (long live CMake!), but can't you just set the INCLUDEPATH variable in your .pro file, i.e., do something like:

INCLUDEPATH += ./sources
INCLUDEPATH += ./headers
INCLUDEPATH += ../utils/include
# (etc, etc.)

Then just point the entry in your SOURCES var at the sources folder like so:

SOURCES = sources/one.cpp \
          sources/two.cpp

It's not clear to me why you're using TEMPLATE = subdirs. It doesn't seem like it should be necessary in your case. Can't you just use TEMPLATE = app (or TEMPLATE = lib) and be done with it? Something like this:

QT += dbus
TEMPLATE = app
TARGET = example

INCLUDEPATH += ./sources

SOURCES += sources/one.cpp \
           sources/two.cpp
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文