I've coded a DLL for usage with LabView 2020 (32-bit). Developed in Code::Blocks IDE v20.03, with few days old installed Win-Builds (32/64 bit mingw tools g++ and gcc).
DLL is compiled well as 64-bit, works with Windows (VBA testing app, and rundll). Compilation for 32-bit is not successful, ends with errors.
In forums I read to use "-m32" parameter for compiling.
How can I do it?
Compilation logs 64bit:
-------------- Build: Release in SampleDLL1 (compiler: GNU GCC Compiler)---------------
g++.exe -Wall -DBUILD_DLL -O2 -c C:\Hello\SampleDLL1\main.cpp -o obj\Release\main.o
g++.exe -shared -Wl,--output-def=bin\Release\libSampleDLL1.def -Wl,--out-implib=bin\Release\libSampleDLL1.a -Wl,--dll obj\Release\main.o -o bin\Release\SampleDLL1.dll -s -luser32
Output file is bin\Release\SampleDLL1.dll with size 18.50 KB
Process terminated with status 0 (0 minute(s), 2 second(s))
0 error(s), 0 warning(s) (0 minute(s), 2 second(s))
*Compilation logs 32bit : (uses -m32 parameter and -lmingw32 for linker)
ERROR : some parameters are "cannot find"*
-------------- Build: Release in SampleDLL1 (compiler: GNU GCC Compiler)---------------
g++.exe -Wall -DBUILD_DLL -O2 -m32 -c C:\Hello\SampleDLL1\main.cpp -o obj\Release\main.o
g++.exe -shared -Wl,--output-def=bin\Release\libSampleDLL1.def -Wl,--out-implib=bin\Release\libSampleDLL1.a -Wl,--dll obj\Release\main.o -o bin\Release\SampleDLL1.dll -s -m32 -lmingw32 -luser32
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Win-builds/lib64/libstdc++.dll.a when searching for -lstdc++
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Win-builds/lib64/libstdc++.a when searching for -lstdc++
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Win-builds/lib64\libstdc++.a when searching for -lstdc++
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Win-builds/lib64/libstdc++.dll.a when searching for -lstdc++
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Win-builds/lib64/libstdc++.a when searching for -lstdc++
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lstdc++
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Win-builds/lib64/libgcc_s.a when searching for -lgcc_s
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Win-builds/lib64\libgcc_s.a when searching for -lgcc_s
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Win-builds/lib64/libgcc_s.a when searching for -lgcc_s
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lgcc_s
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/libgcc.a when searching for -lgcc
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3\libgcc.a when searching for -lgcc
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/libgcc.a when searching for -lgcc
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lgcc
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/lib/libpthread.dll.a when searching for -lpthread
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/lib/libpthread.a when searching for -lpthread
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/lib\libpthread.a when searching for -lpthread
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/lib/libpthread.dll.a when searching for -lpthread
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/lib/libpthread.a when searching for -lpthread
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lpthread
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Win-builds/lib64/libgcc_s.a when searching for -lgcc_s
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Win-builds/lib64\libgcc_s.a when searching for -lgcc_s
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Win-builds/lib64/libgcc_s.a when searching for -lgcc_s
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lgcc_s
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/libgcc.a when searching for -lgcc
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3\libgcc.a when searching for -lgcc
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/libgcc.a when searching for -lgcc
c:/win-builds/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lgcc
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 1 second(s))
7 error(s), 0 warning(s) (0 minute(s), 1 second(s))
That typically means that you are trying a to build a 32 bit binary with a 64 bit compiler. MinGW-w64
that comes with Win-Builds
(assuming you are using the latest version 1.5) is v3.3.0
, uses GCC-4.8.3
. As I recall, both DWARF
and SEH
variants of MinGW-w64
(available starting GCC-4.8.0) are single-target, ie, they contain only the libraries for either 64-bit or 32-bit but not both. Only the old SJLJ
version remains actual dual target and for that supplying -m32
would work. Given the fact that 64-bit builds are working fine for you and 32-bit builds are failing, it seems you are the former case. You might have to build it using the 32-bit toolchain for the 32 bit compilation to work ( i686-w64-mingw32-g++
and 32 bit libraries).
I was just having the same problem as you and this is what I did to solve it.
First I studied this answer
I had already installed MSYS2 from here but I had only installed 64 bits using:
pacman -S mingw-w64-ucrt-x86_64-gcc
The first thing is updating the MSYS2 installation and all its packages and dependencies. To do this on the console of msys2.exe type:
pacman -Suy
end then
pacman -Syyu
Then for compiling 32 bits you have to install:
pacman -S mingw-w64-i686-gcc
Then you have to add this new version to your environment variables in the path variable. On my PC the path was C:\msys64\mingw32\bin
. I momentarily took the 64 bit gcc version in C:\msys64\mingw64\bin
out of the path
Finally to compile the library (I wanted a.SO) in 32 bits I did:
gcc -m32 -fPIC -shared -o my_lib_name_x86.so my_source_code.c
And in my case I can load this using ctypes.cdll.LoadLibrary("./my_lib_name_x86.so")
from Python 32 bits interpreter (which I momentarily use as replacement for the default 64 bit interpreter)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.