Link a library with Qt on windows



  • Hi,

    I m trying to port a simple Qt application from linux to windows which depends one library. https://github.com/labsquare/CuteVCF
    The librarie is a C library. ( https://github.com/samtools/htslib) . I create the library by running "make". Everything works on Linux.

    From Windows ( Windows 10), I compiled the library from cygwin and mingw32. This makes me libhts.so and libhts.a .
    I tried to link the libhts.a file using the following command :

     LIBS += -L$$PWD/htslib-1.3.2/ -lhts
     INCLUDEPATH += $$PWD/htslib-1.3.2
     DEPENDPATH += $$PWD/htslib-1.3.2
    

    But it returns me error.. It seems it doesn't link my library .... Maybe it looks for a dll file ? I m confused now about *a *.so *.lib and *.dll file...
    Any help will be welcome !

    /cygdrive/c/Dev/test/htslib-1.3.2/hts_internal.h:45: undefined reference to `__locale_ctype_ptr'
    C:\Dev\test\htslib-1.3.2/libhts.a(hts.o): In function `decompress_peek':
    /cygdrive/c/Dev/test/htslib-1.3.2/hts.c:141: undefined reference to `inflateInit2_'
    /cygdrive/c/Dev/test/htslib-1.3.2/hts.c:144: undefined reference to `inflate'
    /cygdrive/c/Dev/test/htslib-1.3.2/hts.c:147: undefined reference to `inflateEnd'
    /cygdrive/c/Dev/test/htslib-1.3.2/hts.c:147: undefined reference to `inflateEnd'
    C:\Dev\test\htslib-1.3.2/libhts.a(hts.o): In function `test_and_fetch':
    /cygdrive/c/Dev/test/htslib-1.3.2/hts.c:2010: undefined reference to `__getreent'
    /cygdrive/c/Dev/test/htslib-1.3.2/hts.c:2005: undefined reference to `__getreent'
    /cygdrive/c/Dev/test/htslib-1.3.2/hts.c:2001: undefined reference to `__getreent'
    C:\Dev\test\htslib-1.3.2/libhts.a(hts.o): In function `ks_getuntil2':
    /cygdrive/c/Dev/test/htslib-1.3.2/hts.c:47: undefined reference to `__locale_ctype_ptr'
    /cygdrive/c/Dev/test/htslib-1.3.2/hts.c:47: undefined reference to `__locale_ctype_ptr'
    C:\Dev\test\htslib-1.3.2/libhts.a(hts.o): In function `hts_opt_add':
    /cygdrive/c/Dev/test/htslib-1.3.2/hts.c:531: undefined reference to `__getreent'
    C:\Dev\test\htslib-1.3.2/libhts.a(hts.o): In function `tolower_c':
    /cygdrive/c/Dev/test/htslib-1.3.2/hts_internal.h:51: undefined reference to `__locale_ctype_ptr'
    C:\Dev\test\htslib-1.3.2/libhts.a(hts.o): In function `hts_close':
    /cygdrive/c/Dev/test/htslib-1.3.2/hts.c:861: undefined reference to `__errno'
    /cygdrive/c/Dev/test/htslib-1.3.2/hts.c:866: undefined reference to `__errno'
    /cygdrive/c/Dev/test/htslib-1.3.2/hts.c:827: undefined reference to `__getreent'
    C:\Dev\test\htslib-1.3.2/libhts.a(hts.o): In function `hts_hopen':
    

  • Lifetime Qt Champion

    Hi,

    Are you also using a MinGW32 based Qt ?



  • Yes...
    I think i had some misunderstanding..
    Compiling with cygwin means for cygwin not for windows.
    Compiling with mingw means for windows.


  • Moderators

    @dridk2 Those errors are caused by mixing libraries that are incompatible. If you compiled that lib for cygwin, then you need to build everything with/for cygwin. Qt/your app/all libs. If you made it with mingw then you need to use that on all your libs (including Qt).

    Likewise bit size matters, so if you used mingw64 and mixed with mingw32 that won't work either.

    And finally .lib/.dll are MSVC extensions. If you are using cygwin or mingw you will have .a/.so.

    From the sounds of it, you are mixing cygwin (hts lib) and mingw (qt/yourapp). Recompile the hts lib with mingw (no cygwin) and you should be fine. Assuming bit size is the same.



  • @ambershark Thanks ! I will try it ! It seems clear now!



  • I finally success !
    I compile my library with msys-mingw ! And configure qt creator to use msys-mingw too !
    It works like a charm !


  • Moderators

    @dridk2 Great news! Happy coding. :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.