首页 文章

Qt,库函数调用给出了未解决的外部符号错误

提问于
浏览
2

我使用外部库时遇到麻烦,让我们从头开始 . 我有一些库trans2quik,它由3个文件组成:trans2quik .dll / .lib / .h

所以,我使用Qt5.2,MSVC 2012 x64,win7 . 我使用“添加库”向导创建简单的qt小部件应用程序和链接库,用于在我的pro文件中生成LIBS,INCLUDEPATH等 . 然后,当我调用任何函数时,我得到未解析的extenal符号错误:

widget.obj:-1:错误:LNK2019:函数“public:__ cdecl Widget :: Widget(class QWidget *)”中未解析的外部符号__imp_TRANS2QUIK_CONNECT(?? 0Widget @@ QEAA @ PEAVQWidget @@@ Z)

代码如下:

PRO文件:

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET   = bot_test
TEMPLATE = app


SOURCES     += main.cpp\
           widget.cpp

HEADERS     += widget.h

win32: LIBS += -L$$PWD/ -lTRANS2QUIK

INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/

widget.h文件:

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <Windows.h> //For LPSTR and DWORD
class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = 0);
    //Some vars for lib's function
    LPSTR connectionParams;
    LPSTR errorMsg;
    DWORD  errorMsgSize;
    long   *errorCode;

};

#endif // WIDGET_H

widget.cpp文件:

#include "widget.h"
#include "trans2quik_api.h"
#pragma comment(lib, "TRANS2QUIK.lib")
Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    TRANS2QUIK_CONNECT(connectionParams, errorCode, errorMsg, errorMsgSize);
}

因此,.lib和lib的.h文件位于项目目录中,LIB =和INCLUDEPATH =由QtCreator生成,所以我认为它不是问题 . 希望有任何停顿,谢谢你提前 .

1 回答

  • 0

    问题是你试图连接32位trans2quik,而你的应用程序似乎被定义为64位 . 不要混合它们 . 构建32位应用程序,或使用64位库 .

相关问题