[英]How to link a dynamic library in QtCreator use qmake and MinGW32?
I am trying to use hiredis and libevent in my project, I downloaded their source code and compiled them with CmakeGUI and MinGW32.我试图在我的项目中使用hiredis和libevent,我下载了他们的源代码并用CmakeGUI和MinGW32编译它们。 Then i got the header files and those library files.然后我得到了头文件和那些库文件。
Then I wrote some test programs to use these libraries, but could not link successfully The error looks like this:然后我写了一些测试程序来使用这些库,但是无法成功链接错误是这样的:
error: undefined reference to `redisConnect'
here is my pro file and code.这是我的专业文件和代码。
#my pro file
#hiredis
INCLUDEPATH += $$PWD/include/hiredis
LIBS += -L$$PWD/lib/ -llibhiredis.dll
#event2
INCLUDEPATH += $$PWD/include/libevent
LIBS += -L$$PWD/lib/ -llibevent.dll
LIBS += -L$$PWD/lib/ -llibevent_core.dll
LIBS += -L$$PWD/lib/ -llibevent_extra.dll
#include "hiredis.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow) {
ui->setupUi(this);
redisContext *asd = redisConnect("127.0.0.1", 6379);
}
This is the compile output这是编译输出
g++ -Wl,-s -Wl,-subsystem,windows -mthreads -o release\Test.exe release/main.o
release/mainwindow.o release/moc_mainwindow.o
-LC:\Users\VC\Desktop\Test\lib C:\Users\VC\Desktop\Test\lib\libhiredis.dll.a
C:\Users\VC\Desktop\Test\lib\libevent.dll.a
C:\Users\VC\Desktop\Test\lib\libevent_core.dll.a
C:\Users\VC\Desktop\Test\lib\libevent_extra.dll.a
D:\Work\env\cpp\Qt\5.12.9\mingw73_32\lib\libQt5Widgets.a
D:\Work\env\cpp\Qt\5.12.9\mingw73_32\lib\libQt5Gui.a
D:\Work\env\cpp\Qt\5.12.9\mingw73_32\lib\libQt5Core.a
-lmingw32 D:\Work\env\cpp\Qt\5.12.9\mingw73_32\lib\libqtmain.a
-LC:\openssl\lib -LC:\Utils\my_sql\mysql-5.6.11-win32\lib
-LC:\Utils\postgresql\pgsql\lib -lshell32
release/mainwindow.o:mainwindow.cpp:(.text+0x2c9): undefined reference to `redisConnect'
I tried two different libraries(libevent and hiredis) and got similar results, what am I doing wrong?我尝试了两个不同的库(libevent 和hiredis)并得到了相似的结果,我做错了什么?
thank you谢谢你
Try to remove the .dll, just give the name of the lib, I mean include the lib like this :尝试删除 .dll,只需给出 lib 的名称,我的意思是包含这样的 lib:
INCLUDEPATH += $$PWD/include/hiredis
INCLUDEPATH += -L$$PWD/lib
LIBS += -L$$PWD/lib/ -llibhiredis
Then clean the project and run qmake.然后清理项目并运行qmake。
我曾经在环境变量中设置了64位版本的MinGW,但是忘记了当我改成32位MinGW路径时,编译成功,可以使用动态库
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.