Qmake and Make using separate folders for sources and headers

这一生的挚爱 提交于 2019-12-24 10:10:39

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/4300330/qmake-and-make-using-separate-folders-for-sources-and-headers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!