简体   繁体   English

Qt图书馆链接

[英]Qt Library Linking

I am currently trying to get my head around library linking with Qt in order to split up some existing code into logically structured modular parts that can be called by different applications. 我目前正试图让我的脑袋围绕库与Qt链接,以便将一些现有代码拆分成逻辑结构的模块化部分,可以由不同的应用程序调用。

I keep getting a problem where no obj files are being created... so I have created a smaller sample project and replicated my problem below. 我一直遇到没有创建obj文件的问题...所以我创建了一个较小的示例项目并在下面复制了我的问题。

It seems, to me, the problem lies in the library ...so I will start there. 对我来说,似乎问题出在图书馆......所以我将从那里开始。

If I have code like this, the obj file is created (and can therefore be linked to by my test application): 如果我有这样的代码,则创建obj文件(因此可以通过我的测试应用程序链接):

mylib.h mylib.h

#ifndef MYLIB_H
#define MYLIB_H

#include "mylib_global.h"

class MYLIB_EXPORT MyLib
{
public:
    MyLib();
    ~MyLib();

private:

};

#endif // MYLIB_H

mylib.cpp mylib.cpp

#include "mylib.h"

MyLib::MyLib()
{

}

MyLib::~MyLib()
{

}

But if I remove the cpp file and just have the header file with function bodys included (as is the structure of my actual codes library as the code consists ONLY of templates), nothing is created: 但是如果我删除cpp文件并且只包含包含函数bodys的头文件(因为我的实际代码库的结构,因为代码只包含模板),所以没有创建:

mylib.h mylib.h

// .......
public:
    MyLib(){}
    ~MyLib(){}
// .......

How can I get Qt to build my code please? 我怎样才能让Qt构建我的代码?

如果您的库只是一个头文件,您不需要编译它,在其他项目中包含您的头文件,它们将被编译到其中。

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

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