简体   繁体   中英

Library linking error: undefined reference to _imp__

I can't figure out how to link FTDI library in my Qt project. I copied ftd2xx.h file to my project directory. The file I want to link is dll: ftd2xx.lib which is stored in F:\\Workspace\\qt\\libs\\ftdi\\amd64

I get error:

release/testftdi.o:testftdi.cpp:(.text+0x6f8): undefined reference to `_imp__FT_Open@8'
collect2.exe: error: ld returned 1 exit status

I have QtWidget application with one PushButton:

TestFtdi.pro file:

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = TestFtdi
TEMPLATE = app

LIBS += -L"F:\Workspace\qt\libs\ftdi\amd64" -lftd2xx
INCLUDEPATH += f:/Workspace/qt/libs/ftdi/amd64

SOURCES += main.cpp\
        testftdi.cpp

HEADERS  += testftdi.h

FORMS    += testftdi.ui

main.cpp file:

#include "testftdi.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    TestFtdi w;
    w.show();

    return a.exec();
}

testftdi.h file:

#ifndef TESTFTDI_H
#define TESTFTDI_H

#include <QMainWindow>

namespace Ui {
class TestFtdi;
}

class TestFtdi : public QMainWindow
{
    Q_OBJECT

public:
    explicit TestFtdi(QWidget *parent = 0);
    ~TestFtdi();

private slots:
    void on_pushButton_clicked();

private:
    Ui::TestFtdi *ui;
};

#endif // TESTFTDI_H

testftdi.cpp file:

#include "testftdi.h"
#include "ui_testftdi.h"
#include <QDebug>

#include "windows.h"
#include "ftd2xx.h"

TestFtdi::TestFtdi(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::TestFtdi)
{
    ui->setupUi(this);
}

TestFtdi::~TestFtdi()
{
    delete ui;
}

void TestFtdi::on_pushButton_clicked()
{

    FT_HANDLE ftHandle;
    FT_STATUS ftStatus;


    ftStatus = FT_Open(0, &ftHandle);
    if(ftStatus != FT_OK) { // FT_Open failed
        qDebug() << "FT_Open failed";
    }
}

The compiler command looks in this situation like this:

g++ -Wl,-s -Wl,-subsystem,windows -mthreads -o release\TestFtdi.exe release/main.o release/testftdi.o release/moc_testftdi.o  -lmingw32 -LC:/Qt/5.5/mingw492_32/lib -lqtmain -lshell32 -LF:\Workspace\qt\libs\ftdi\Static\amd64 -lftd2xx -lQt5Widgets -lQt5Gui -lQt5Core 

Could you help me with this?

My guess is, compiler might be looking for ftd2xx rather than ftd2xx.lib (file name is ftd2xx.lib.dll, right?). Have you tried changing the LIBS line to

LIBS += -L"F:\Workspace\qt\libs\ftdi\amd64" -lftd2xx.lib

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM