Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Issue using static library
Forum Updated to NodeBB v4.3 + New Features

Issue using static library

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 389 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xpog
    wrote on last edited by
    #1

    Hi everyone,

    I am facing an issue with the use of a static library.
    First the "C" static library is created as bellow :

    gcc -c hello.c
    ar -rcs libarray.a hello.o
    

    The file hello.c contains the following code :

    #include "hello.h"
    
    int Array_ToInt(char* a , int* b){
        return 10;
    }
    
    

    and hello.h :

    extern int Array_ToInt(char*, int*);
    
    

    Then I perform a "nm" cmd on the library file, the result is :

    hello.o:
    0000000000000000 T Array_ToInt
    

    Therefore, it seems that the library is exporting the Array_ToInt function !

    Now in my Qt project the file .h included contains :

    extern "C" int Array_ToInt(char*, int*);
    

    And the function is called in the .cpp file:

    ret = Array_ToInt(&a, &b);
    

    The compilation line is :

    mingw32-make[1]: Entering directory 'C:/Users/xxx/xxxx/xxxx/xxxx/build-xxxx-xxxx_Qt_5_15_2_MinGW_32_bit-Debug'
    g++ -Wl,-subsystem,windows -mthreads -o debug\xxxx.exe @object_script.xxxx.Debug  -LC:\Users\xxxx\xxxx\xxxx\xxxx\xxxx\src -larray C:\Qt\5.15.2\mingw81_32\lib\libQt53DExtras.a C:\Qt\5.15.2\mingw81_32\lib\libQt53DRender.a C:\Qt\5.15.2\mingw81_32\lib\libQt53DInput.a C:\Qt\5.15.2\mingw81_32\lib\libQt53DLogic.a C:\Qt\5.15.2\mingw81_32\lib\libQt53DCore.a C:\Qt\5.15.2\mingw81_32\lib\libQt5Gamepad.a C:\Qt\5.15.2\mingw81_32\lib\libQt5Charts.a C:\Qt\5.15.2\mingw81_32\lib\libQt5Widgets.a C:\Qt\5.15.2\mingw81_32\lib\libQt5Gui.a C:\Qt\5.15.2\mingw81_32\lib\libQt5Network.a C:\Qt\5.15.2\mingw81_32\lib\libQt5Core.a debug\xxxx.o  -lmingw32 C:\Qt\5.15.2\mingw81_32\lib\libqtmain.a -LC:\openssl\lib -LC:\Utils\my_sql\mysql-5.7.25-win32\lib -LC:\Utils\postgresql\pgsql\lib -lshell32 
    

    But it seems that there is an issue with the link of the static library because the following error happens:

    debug/xxxx.o: In function `Z14Qt_XXXX_Get_IntijPi':
    C:\Users\xxxx\xxxx\xxxx\xxxx\build-xxxx-xxxx_Qt_5_15_2_MinGW_32_bit-Debug/../xxxx/../src_lib/xxxx/xxxx.cpp:169: undefined reference to `Array_ToInt'
    

    I do not understand because as you can see the library is included by :

    -LC:\Users\xxxx\xxxx\xxxx\xxxx\xxxx\src -larray
    

    In the .pro file the library is included as follows:

    unix:!macx|win32: LIBS += -L$$PWD/src/ -larray
    
    INCLUDEPATH += $$PWD/src
    DEPENDPATH += $$PWD/src
    
    win32:!win32-g++: PRE_TARGETDEPS += $$PWD/src/array.lib
    else:unix:!macx|win32-g++: PRE_TARGETDEPS += $$PWD/src/libarray.a
    

    In both compilation (library and Qt app) mingw32 is used.

    Is someone understand what is going wrong ?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Are you sure your custom library is built in 32bit ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • X Offline
        X Offline
        xpog
        wrote on last edited by
        #3

        Thank you for the answer.

        I performed a "gcc -v" :

         gcc -v
        Using built-in specs.   
        COLLECT_GCC=C:\msys64\mingw64\bin\gcc.exe
        COLLECT_LTO_WRAPPER=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/lto-wrapper.exe
        Target: x86_64-w64-mingw32
        Configured with: ../gcc-10.3.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --enable-bootstrap --enable-checking=release --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++,jit --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts=yes --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-lto --enable-libgomp --disable-multilib --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev5, Built by MSYS2 project' --with-bugurl=https://github.com/msys2/MINGW-packages/issues --with-gnu-as --with-gnu-ld --with-boot-ldflags='-pipe -Wl,--dynamicbase,--high-entropy-va,--nxcompat,--default-image-base-high -Wl,--disable-dynamicbase -static-libstdc++ -static-libgcc' 'LDFLAGS_FOR_TARGET=-pipe -Wl,--dynamicbase,--high-entropy-va,--nxcompat,--default-image-base-high' --enable-linker-plugin-flags='LDFLAGS=-static-libstdc++\ -static-libgcc\ -pipe\ -Wl,--dynamicbase,--high-entropy-va,--nxcompat,--default-image-base-high\ -Wl,--stack,12582912'
        Thread model: posix
        Supported LTO compression algorithms: zlib zstd
        gcc version 10.3.0 (Rev5, Built by MSYS2 project) 
        

        As the target is "x86_64-w64-mingw32", I think it is build for 32bit... Am I wrong ?

        For the "ar" cmd (to create the static library) the C:\msys64\mingw64\bin\ar.exe is used.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @xpog said in Issue using static library:

          x86_64-w64-mingw32

          x86_64-w64 -> 64 but.

          The fact that it ends by mingw32 is not an indication of the target architecture.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • X Offline
            X Offline
            xpog
            wrote on last edited by xpog
            #5

            Indeed that was the problem ! Thank you very much :)

            Pablo J. RoginaP 1 Reply Last reply
            0
            • X xpog

              Indeed that was the problem ! Thank you very much :)

              Pablo J. RoginaP Offline
              Pablo J. RoginaP Offline
              Pablo J. Rogina
              wrote on last edited by
              #6

              @xpog said in Issue using static library:

              Indeed that was the problem

              Is your issue solved now? If so, please don't forget to mark your post as such.

              Upvote the answer(s) that helped you solve the issue
              Use "Topic Tools" button to mark your post as Solved
              Add screenshots via postimage.org
              Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved