c++ - 使用 Mingw 在 Linux 上交叉编译 Windows DLL
问题描述
我正在尝试使用 Mingw 从 Linux 机器提供 Windows DLL(以及 .so)。
我正在关注这个示例,它由三个文件组成,DLL 源example_dll.cpp
、标头example_dll.h
和客户端应用程序example_exe.cpp
。这些我位于我的 Linux 主机和 Windows 7 VM 共享的文件夹中。两个盒子都安装了Mingw。
DLL 的构建命令是
g++ -c -DBUILDING_EXAMPLE_DLL example_dll.cpp
g++ -shared -o example_dll.dll example_dll.o -Wl,--out-implib,libexample_dll.a
对于客户端应用程序
g++ -c example_exe.cpp
g++ -o example_exe.exe example_exe.o -L. -lexample_dll
所有这些都可以在安装了 Mingw 的 Windows 7 VM 上完美编译和运行。
所有在安装了 Mingw 的 Ubuntu 16.04 下完美编译,替换g++
为i686-w64-mingw32-g++
.
但在这种情况下,当从 Windows VM 运行可执行文件时,“程序无法启动,因为缺少 libgcc_s_sjlj-1.dll。
- 我犯了什么错误?
我可以通过在 Linux 上替换 4. 来强制“丢失”的 DLL 进入可执行文件,i686-w64-mingw32-g++ -o example_exe.exe example_exe.o -L. -lexample_dll -static-libgcc -static-libstdc++
这在 Windows VM 上完美运行。
但我需要提供 DLL,而不是可执行文件。
- 我注意到 DLL libgcc_s_sjlj-1.dll 存在于 Linux 机器上,但不存在于 Windows 机器上。
- 我还注意到 Linux 机器有 Mingw 5.3.1,而 Windows 机器有 Mingw 6.3.0
解决方案
推荐阅读
- terraform - 如何使用 terraform 0.13.5 检查列表中是否存在值?
- python - 在 Windows 上识别 Python 中丢失的 DLL
- git - 将 1 个分支合并到另一个分支,但不是所有文件/文件夹
- google-sheets - 在 Google 表格中使用 ImportXML 从网页中抓取署名
- flutter - 我想知道在 Flutter 中使用内网时如何使用 pub get 和 package download
- python - 为什么烧瓶不返回结果?
- android - 如何从 jetpack compose 更改 OutlinedTextField 的轮廓颜色?
- laravel - 与laravel一起使用时如何翻译metronic菜单?
- php - 为什么在php中运行while循环后没有输出?
- kubernetes - 如何列出一个不存在的命名空间的所有对象?