【问题标题】:Undefined reference errors linking a dll in QtCreator在 QtCreator 中链接 dll 的未定义引用错误
【发布时间】:2017-10-19 02:21:45
【问题描述】:

我在mingw下使用g++构建了一个简单的dll: 我们有一个包含文件:

#ifndef __TESTDLL_H
#define __TESTDLL_H

class sineCalculator
{
    double n;
public:
    sineCalculator();
    sineCalculator(double);
    double sine();
    void setAngle(double);
};

#endif

然后是一个实现cpp:

#include <testdll.h>
#include <math.h>

sineCalculator::sineCalculator()
{
    n = 0;
}

sineCalculator::sineCalculator(double x)
{
    n = x;
}

double sineCalculator::sine()
{
    return sin(n);
}

void sineCalculator::setAngle(double x)
{
    n = x;
}

我已经编译为一个 dll。生成一个 .dll 文件和一个名为 visaTest.dll 和 libvisaTest.a 的导入库

我可以编写一个小程序并使用命令行成功链接到这个 dll - 没有 Qt,只有 g++。我可以创建对象并运行所有方法。

但是,我现在想将此库添加到 QtCreator 中的 Qt 应用程序中。我遵循了几个问题的建议,并将这些行添加到我的 .pro 文件中:

INCLUDEPATH += C:/msys64/home/hoyla/libs/
INCLUDEPATH +=C:/msys64/home/hoyla/includes/
DEPENDPATH +=C:/msys64/home/hoyla/libs/

win32:CONFIG(release, debug|release): LIBS += -LC:/msys64/home/hoyla/libs/ -lvisaTest
else:win32:CONFIG(debug, debug|release):  LIBS += -LC:/msys64/home/hoyla/libs/ -lvisaTest
else:unix: LIBS += -L$$PWD/../../../../libs/ -lvisaTest

虽然我在这里使用了一些绝对路径,但我也尝试过使用相对路径。但是,在构建 Qt 文件时,我的 dll 函数不断收到未定义的引用错误。我要指出,路径指向我的 .a 导入库的位置,.dll 本身位于系统路径中。我在这里做错了什么?

【问题讨论】:

    标签: c++ qt dll mingw


    【解决方案1】:

    过错!看来我已经在 64 位 MinGW 下编译了我的库,但 Qt Creator 默认使用 32 位工具链。人们会认为链接器可能已经能够确定这是错误并生成更有用的错误消息,但我们走了。经验教训 - 确保您使用的是您认为自己正在使用的工具。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-23
      • 2023-03-31
      • 2014-04-21
      • 2013-03-15
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多