包含来自单独目录的文件时未定义的引用
我有非常基本的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于最简单的更改,我认为您需要将 .pro 文件更改为:
Test.pro
如果您还有其他代码也将链接到 common.cpp 中,那么更好的更改是在 f1 中创建 .pro 文件生成一个库,链接到其他应用程序。
但只需手动将 common.cpp 添加到源列表中就可以解决问题。
For the simplest change, I think you need to change your .pro file to this:
Test.pro
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.