c++ MinGW 32/64未针对32位进行编译

hwazgwia  于 2022-11-19  发布在  其他
关注(0)|答案(2)|浏览(205)

我 编写 了 一 个 DLL , 用于 LabView 2020 ( 32 位 ) 。 在 * * 代码 : : 块 IDE * * v20.03 中 开发 , 安装 了 几 天 前 的 * * Win-Builds * * ( 32/64 位 mingw 工具 g + + 和 gcc ) 。
DLL 编译 为 64 位 , 可 与 Windows 一起 使用 ( VBA 测试 应用 程序 和 rundll ) 。 编译 为 32 位 不 成功 , 以 错误 结束 。
在 论坛 中 我 读 到 使用 " - m32 " 参数 进行 编译 。
我 该 怎么 做 ?

  • 编译 日志 64 位 : *
-------------- 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))

中 的 每 一 个

vmpqdwk3

vmpqdwk31#

这通常意味着您正在尝试使用64位编译器构建32位二进制文件。MinGW-w64(随Win-Builds提供)(假设您使用的是最新版本1.5)是v3.3.0,使用GCC-4.8.3。(从GCC-4.8.0开始可用)是单目标,即它们只包含用于64位或32位的库,而不是同时包含这两种库。只有旧的SJLJ版本仍然是实际的双目标,为此提供-m32将起作用。鉴于64- 2位编译对您来说运行良好,而32位编译却失败了,看起来您是前一种情况。您可能必须使用32位工具链进行编译,以便32位编译工作(i686-w64-mingw32-g++和32位库)。

bis0qfac

bis0qfac2#

我和你遇到了同样的问题,这就是我解决问题的方法。
首先我研究了this answer
我已经从here安装了MSYS2,但我只安装了64位,使用的是:

pacman -S mingw-w64-ucrt-x86_64-gcc

第一件事是更新MSYS2安装及其所有包和依赖项。要在msys2.exe的控制台上执行此操作,请键入:

pacman -Suy

然后结束

pacman -Syyu

然后要编译32位,您必须安装:

pacman -S mingw-w64-i686-gcc

然后,您必须将这个新版本添加到path变量中的环境变量中。
最后,为了编译32位的库(我想要一个.SO),我做了:

gcc -m32 -fPIC -shared -o my_lib_name_x86.so my_source_code.c

在我的例子中,我可以使用Python 32位解释器中的ctypes.cdll.LoadLibrary("./my_lib_name_x86.so")来加载它(我暂时用它来替换默认的64位解释器)

相关问题