Qt Creator链接错误:未定义引用`KFUNC'

时间:2017-09-04 06:34:02

标签: c++ c qt

)我目前正在Qt Creator 4.3.1下开发一个项目,该项目需要一个外部库来使用一个锁钥匙硬件设备。

该设备附带一张CD,其中包含库libkfunc64.solibkfunc64.a(以及32位版本),可能是Cgcc一起编译的。我已经在虚拟程序中尝试了这些库来检查它们是否有效,而且它们确实有效。

但是当我将重要的代码块添加到Qt项目中时,它会发出以下错误

 [...] error: undefined reference to `KFUNC(unsigned int, unsigned int, unsigned int, unsigned int)'

我已经尝试包含库

  • 通过将库复制到系统目录并简单地在.pro文件中包含以下行
      

    LIBS + = -lkfunc64

  • 使用.pro文件中的库的相对路径

      

    LIBS + = -L $$ PWD /../ build-project / -lkfunc64

         

    INCLUDEPATH + = $$ PWD /../ build-Qmetrics-Desktop-Debug   DEPENDPATH + = $$ PWD /../ build-Qmetrics-Desktop-Debug

         

    #PRE_TARGETDEPS + = $$ PWD /../ build-Qmetrics-Desktop-Debug / libkfunc64.a

但是在尝试(重新)构建它时它会一直显示此错误。我几乎在互联网上阅读了关于这个问题的所有主题,但没有解决这个问题。

这是main.cpp

的代码
#include "mainwindow.h"

#include <QApplication>
#include <QMessageBox>

// Key-lock stuff ----------
#define ValidateCode1 0X488B 
#define ValidateCode2 0XFEE2 
#define ValidateCode3 0XEF90
#define ClientIDCode1 0xB862 
#define ClientIDCode2 0x54CB 
#define ReadCode1     0X1772 
#define ReadCode2     0XC4E6
#define ReadCode3     0XBCF8

extern unsigned long KFUNC(unsigned, unsigned, unsigned, unsigned);
unsigned RotateLeft(unsigned, int);
void KTASK(unsigned, unsigned, unsigned, unsigned);
unsigned short ReturnValue1, ReturnValue2;
// -------------------------

int main(int argc, char *argv[])
{  
    KTASK(1, ValidateCode1, ValidateCode2, ValidateCode3);
    KTASK(RotateLeft(ReturnValue1, ReturnValue2 & 7) ^ ReadCode3 ^ ReturnValue2, RotateLeft(ReturnValue2, ReturnValue1 & 15), ReturnValue1 ^ ReturnValue2, 0);

    if ((ReturnValue1 == ClientIDCode1) && (ReturnValue2 == ClientIDCode2))
    {
        QApplication app(argc, argv);

        MainWindow w;
        w.showFullScreen();

        return app.exec();
    }
    else
    {
        QMessageBox msgBox;
        msgBox.setText("Wrong or missing key-lock!");
        return msgBox.exec();
    }
}

unsigned RotateLeft(unsigned Target, int Counts)
{
    int i;
    static unsigned LocalTarget, HighBit;
    LocalTarget = Target;
    for (i=0; i<Counts; i++)
    {
        HighBit = LocalTarget & 0X8000;
        LocalTarget = (LocalTarget << 1) + (HighBit >> 15);
    }
    LocalTarget = LocalTarget & 0XFFFF; /* For 32 bit integers */
    return (LocalTarget);
}

void KTASK(unsigned CommandCode, unsigned Argument2, unsigned Argument3, unsigned Argument4)
{
  unsigned long int ReturnValue;
  ReturnValue = KFUNC(CommandCode, Argument2, Argument3, Argument4); // <--- this is the only function that is used from the external library
  ReturnValue1 = (unsigned) (ReturnValue & 0XFFFF);
  ReturnValue2 = (unsigned) (ReturnValue >> 16);
}

.pro文件的(相关部分)如下

# Adds OpenCV, DC1394 and Keylok libraries
unix {
    CONFIG += link_pkgconfig
    PKGCONFIG += opencv
    LIBS += -ldc1394 -lkfunc64
}

我真的不知道该怎么做:'(

1 个答案:

答案 0 :(得分:1)

您是否尝试使用extern“C”声明该函数?

e.G:

#ifdef __cplusplus
extern "C"
{
#endif

   extern unsigned long KFUNC(unsigned, unsigned, unsigned, unsigned);

#ifdef __cplusplus
};
#endif

这是从c ++调用外部c函数的nessecary。