How to link a dynamic library in QtCreator use qmake and MinGW32?

VanChun

I am trying to use hiredis and libevent in my project, I downloaded their source code and compiled them with CmakeGUI and MinGW32. Then i got the header files and those library files.

  • libevent.a
  • libevent.dll
  • libevent.dll.a
  • libevent_core.a
  • libevent_core.dll
  • libevent_core.dll.a
  • libevent_extra.a
  • libevent_extra.dll
  • libevent_extra.dll.a
  • libhiredis.dll
  • libhiredis.dll.a

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?

thank you

VanChun

I once set a 64-bit version of MinGW in environment variables, but I forgot When I changed it to the 32-bit MinGW path, the compilation was successful and the dynamic library can be used

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

qmake: How to link a library twice?

From Dev

How to use dynamic link library with CMake?

From Dev

QMake: how to choose version of library to link to

From Dev

How to link against Vulkan with MinGW and QMake?

From Dev

How can I use "make" in windows? mingw32

From Dev

How can I link dynamic library depending on another dynamic library?

From Dev

How to force executable to link dynamic library

From Java

How to install mingw32 on Ubuntu?

From Dev

How do I statically link zstd library to my dynamic library?

From Dev

How to ask QtCreator to use a custom build library on user path instead of using system library

From Dev

Dynamic link library in C

From Dev

Trying to use win32ui with pywin32 gives: A dynamic link library (DLL) initialization routine failed

From Java

How to specify the library version to use at link time?

From Dev

How to use qmake properly in this case?

From Dev

How to link a dynamic Rust library using only rustc and not cargo?

From Dev

MakeFile: Link a library - mingw

From Dev

Unable to link dynamic library in macOS

From Dev

Pass function to dynamic link library

From Dev

Link to a dynamic link library in a cmake project

From Dev

How can I pass a command line CONFIG parameter to qmake from QtCreator?

From Dev

How to build an example cppkafka using qmake & mingw?

From Dev

Can I force a dynamic library to link to a specific dynamic library dependency?

From Dev

How to use pkg-config to link a library statically

From Dev

how does qmake determine the compiler to use in Makefile?

From Dev

How to use QMAKE_EXTRA_TARGETS with SUBDIRS?

From Dev

How to Use Firebase Dynamic Link in Facebook App Install Ad?

From Dev

How do I use a shared dynamic library in c++ project?

From Dev

QtCreator qmake Cannot run compiler 'cl'

From Dev

How to link library manually?

Related Related

  1. 1

    qmake: How to link a library twice?

  2. 2

    How to use dynamic link library with CMake?

  3. 3

    QMake: how to choose version of library to link to

  4. 4

    How to link against Vulkan with MinGW and QMake?

  5. 5

    How can I use "make" in windows? mingw32

  6. 6

    How can I link dynamic library depending on another dynamic library?

  7. 7

    How to force executable to link dynamic library

  8. 8

    How to install mingw32 on Ubuntu?

  9. 9

    How do I statically link zstd library to my dynamic library?

  10. 10

    How to ask QtCreator to use a custom build library on user path instead of using system library

  11. 11

    Dynamic link library in C

  12. 12

    Trying to use win32ui with pywin32 gives: A dynamic link library (DLL) initialization routine failed

  13. 13

    How to specify the library version to use at link time?

  14. 14

    How to use qmake properly in this case?

  15. 15

    How to link a dynamic Rust library using only rustc and not cargo?

  16. 16

    MakeFile: Link a library - mingw

  17. 17

    Unable to link dynamic library in macOS

  18. 18

    Pass function to dynamic link library

  19. 19

    Link to a dynamic link library in a cmake project

  20. 20

    How can I pass a command line CONFIG parameter to qmake from QtCreator?

  21. 21

    How to build an example cppkafka using qmake & mingw?

  22. 22

    Can I force a dynamic library to link to a specific dynamic library dependency?

  23. 23

    How to use pkg-config to link a library statically

  24. 24

    how does qmake determine the compiler to use in Makefile?

  25. 25

    How to use QMAKE_EXTRA_TARGETS with SUBDIRS?

  26. 26

    How to Use Firebase Dynamic Link in Facebook App Install Ad?

  27. 27

    How do I use a shared dynamic library in c++ project?

  28. 28

    QtCreator qmake Cannot run compiler 'cl'

  29. 29

    How to link library manually?

HotTag

Archive