首页 > 解决方案 > 使用 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 的构建命令是

  1. g++ -c -DBUILDING_EXAMPLE_DLL example_dll.cpp
  2. g++ -shared -o example_dll.dll example_dll.o -Wl,--out-implib,libexample_dll.a

对于客户端应用程序

  1. g++ -c example_exe.cpp
  2. 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,而不是可执行文件。


标签: c++linuxwindowsmingwcross-compiling

解决方案


推荐阅读