简体   繁体   English

qmake:等效于INCLUDEPATH用于源/ cpp文件?

[英]qmake: Equivalent of INCLUDEPATH for source / cpp files?

Assume that we have a class called Katze in a directory called dirOfKatze . 假设我们在名为dirOfKatze的目录中有一个名为Katze的类。

Katze.h 凯瑟

#ifndef KATZE_H
#define KATZE_H


class Katze
{
public:
    Katze();
};

#endif // KATZE_H

Katze.cpp 卡瑟

#include "katze.h"
#include <iostream>

Katze::Katze()
{
    std::cout<<"MIAU"<<std::endl;
}

Lets assume that I want to add the class to a Qt project. 假设我想将类添加到Qt项目中。 I can do so by specifying 我可以通过指定

INCLUDEPATH += dirOfKatze INCLUDEPATH + = dirOfKatze

in my .pro file. 在我的.pro文件中。 Now the header file of Katze, or better all header files in the directory dirOfKatze are included. 现在包括Katze的头文件,或者包括目录dirOfKatze中的所有头文件。 But unfortunately Katze.cpp can still not be found by the linker: 但是很不幸,链接器仍然找不到Katze.cpp:

#include "katze.h"

int main()
{
    Katze myCat;

    return 0;
}

Results in: LNK2019 ...public: __cdecl Katze::Katze(void)"... 结果在:LNK2019 ...公共:__cdecl Katze :: Katze(void)“ ...

Is there any way to tell the linker that it should look for the cpp files in dirOfKatze equivalent to INCLUDEPATH? 有什么办法告诉链接器它应该在dirOfKatze寻找与INCLUDEPATH等效的cpp文件? This relevant for me, because there might be many cpp files and I would like to add them all at once, without adding them one by one by typing SOURCE += .... \\ 这对我而言很重要,因为可能有很多cpp文件,并且我想一次全部添加,而无需通过键入SOURCE + = ...逐个添加。

You have to add the following lines in your .pro file: 您必须在.pro文件中添加以下行:

HEADERS += pathTo_Katze.h
SOURCES += pathTo_Katze.cpp

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

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