Issue using static library
-
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 ?
-
Hi and welcome to devnet,
Are you sure your custom library is built in 32bit ?
-
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.
-
@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.
-
@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.