包含来自单独目录的文件时未定义的引用

发布于 2024-12-03 20:03:20 字数 710 浏览 1 评论 0原文

我有非常基本的 QT 应用程序(只是创建来解释我的问题)。 所以我开始了:)我有两个文件夹,f1 和 f2,它们位于同一级别(父文件夹具有相同的文件夹)。在 f1 中,我有我的项目的源代码,在 f2 中,我有另一个项目的源代码。 为了这个例子,假设在 f1 中我只有 common.h 和 common.cpp,而在 f2 中我有:

Test.pro

SOURCES = main.cpp
INCLUDEPATH += "..//f1//"

main.cpp

#include <common.h>
#include <QDebug>

int main(int argc, char *argv[])
{

    qDebug()<<CalculateMD5("test");
}

当我尝试构建这个项目(Test.pro)时,我收到以下错误: f2/main.cpp:7:对“CalculateMD5(QString)”的未定义引用

我做错了什么?我应该如何包含另一个项目的代码? 我需要CalculateMD5 函数是全局的。

您可以在这里下载整个示例(1kb): http://www.xx77abs.com/test.rar

谢谢!!

I have very basic QT application (just create to explain my problem).
So here I go :) I have two folders, f1 and f2, and they are on same level (have same folder for parent). In f1 I have source code from my project, and in f2 another project.
For sake of this example, let's say that in f1 I have only common.h and common.cpp, and in f2 I have:

Test.pro

SOURCES = main.cpp
INCLUDEPATH += "..//f1//"

main.cpp

#include <common.h>
#include <QDebug>

int main(int argc, char *argv[])
{

    qDebug()<<CalculateMD5("test");
}

When I try to build this project (Test.pro) I get following error:
f2/main.cpp:7: undefined reference to `CalculateMD5(QString)'

What am I doing wrong ? How should I include code from another project ?
I need CalculateMD5 function to be global.

Here you can download whole example (1kb):
http://www.xx77abs.com/test.rar

Thanks !!

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

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

发布评论

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

评论(1

知你几分 2024-12-10 20:03:20

对于最简单的更改,我认为您需要将 .pro 文件更改为:

Test.pro

SOURCES = main.cpp ../f1/common.cpp
INCLUDEPATH += "..//f1//"

如果您还有其他代码也将链接到 common.cpp 中,那么更好的更改是在 f1 中创建 .pro 文件生成一个库,链接到其他应用程序。

但只需手动将 common.cpp 添加到源列表中就可以解决问题。

For the simplest change, I think you need to change your .pro file to this:

Test.pro

SOURCES = main.cpp ../f1/common.cpp
INCLUDEPATH += "..//f1//"

If you have other code that will also be linking in common.cpp, then a better change would be to make a .pro file in f1 that generates a library, to be linked in to other applications.

But just manually adding common.cpp to your list of sources should do the trick.

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