【问题标题】:mingw installation on Linux在 Linux 上安装 mingw
【发布时间】:2016-09-21 17:03:17
【问题描述】:

我目前正在尝试在 Linux 操作系统上编译 Windows 应用程序。我需要 mingw 来做这件事。我读到 Debian 已经安装了 mingw 包。当我运行 shell 命令时:

apt-cache search mingw

我得到一个输出:

binutils-mingw-w64 - Cross-binutils for Win32 and Win64 using MinGW-w64
binutils-mingw-w64-i686 - Cross-binutils for Win32 (x86) using MinGW-w64
binutils-mingw-w64-x86-64 - Cross-binutils for Win64 (x64) using MinGW-w64
g++-mingw-w64 - GNU C++ compiler for MinGW-w64
g++-mingw-w64-i686 - GNU C++ compiler for MinGW-w64 targeting Win32
g++-mingw-w64-x86-64 - GNU C++ compiler for MinGW-w64 targeting Win64
gcc-mingw-w64 - GNU C compiler for MinGW-w64
gcc-mingw-w64-base - GNU Compiler Collection for MinGW-w64 (base package)
gcc-mingw-w64-i686 - GNU C compiler for MinGW-w64 targeting Win32
gcc-mingw-w64-x86-64 - GNU C compiler for MinGW-w64 targeting Win64
gcc-mingw32 - GNU Compiler Collection for MinGW32 (transition package)
gfortran-mingw-w64 - GNU Fortran compiler for MinGW-w64
gfortran-mingw-w64-i686 - GNU Fortran compiler for MinGW-w64 targeting Win32
gfortran-mingw-w64-x86-64 - GNU Fortran compiler for MinGW-w64 targeting Win64
gnat-mingw-w64 - GNU Ada compiler for MinGW-w64
gnat-mingw-w64-i686 - GNU Ada compiler for MinGW-w64 targeting Win32
gnat-mingw-w64-x86-64 - GNU Ada compiler for MinGW-w64 targeting Win64
gobjc++-mingw-w64 - GNU Objective-C++ compiler for MinGW-w64
gobjc++-mingw-w64-i686 - GNU Objective-C++ compiler for MinGW-w64 targeting Win32
gobjc++-mingw-w64-x86-64 - GNU Objective-C++ compiler for MinGW-w64 targeting Win64
gobjc-mingw-w64 - GNU Objective-C compiler for MinGW-w64
gobjc-mingw-w64-i686 - GNU Objective-C compiler for MinGW-w64 targeting Win32
gobjc-mingw-w64-x86-64 - GNU Objective-C compiler for MinGW-w64 targeting Win64
gdb-mingw-w64 - Cross-debugger for Win32 and Win64 using MinGW-w64
gdb-mingw-w64-target - Cross-debugger server for Win32 and Win64 using MinGW-w64
libconfig++-dbg - parsing and manipulation of structured config files(C++ debug symbols)
libconfig++-dev - parsing and manipulation of structured config files(C++ development)
libconfig++9 - parsing and manipulation of structured configuration files(C++ binding)
libconfig-dbg - parsing and manipulation of structured config files(debug symbols)
libconfig-dev - parsing and manipulation of structured config files(development)
libconfig-doc - parsing and manipulation of structured config files(Documentation)
libconfig9 - parsing and manipulation of structured configuration files
mingw-ocaml - OCaml cross-compiler based on mingw
mingw32-ocaml - OCaml cross-compiler based on mingw -- dummy transitional package
mingw-w64 - Development environment targetting 32- and 64-bit Windows
mingw-w64-dev - Development files for MinGW-w64 (transitional package)
mingw-w64-i686-dev - Development files for MinGW-w64 targeting Win32
mingw-w64-tools - Development tools for 32- and 64-bit Windows
mingw-w64-x86-64-dev - Development files for MinGW-w64 targeting Win64
mingw32 - Minimalist GNU win32 (cross) compiler
mingw32-binutils - Minimalist GNU win32 (cross) binutils
mingw32-runtime - Minimalist GNU win32 (cross) runtime

当我检查 i686-w64-mingw32 的 /usr/bin/ 和 /usr/lib 时,我在任何地方都找不到它。

我还找到了一个搜索 sing find -name "mingw" ,但运气不佳。

Debian 是否带有 mingw 或者我必须安装它?如果它确实带有 mingw 我该如何使用它?

【问题讨论】:

  • 如果我没记错的话,apt-cache search 会搜索可用的包。如果您尚未安装它们,或者尚未安装它们,则在您安装之前您不会找到它们。
  • 你试过find /usr -name '*mingw*' 吗?祝你好运。

标签: linux debian mingw


【解决方案1】:

使用 wine64 安装工具链(用于运行 Windows 可执行文件):

sudo apt-get install gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 wine64

举个例子程序hello.c:

#include <stdio.h>
int main() {
    printf("Hello world!\n");
}

编译:

x86_64-w64-mingw32-gcc -g -o hello hello.c

检查结果:

file hello.exe

应该输出如下内容:

hello.exe: PE32+ executable (console) x86-64, for MS Windows

运行:

wine64 ./hello.exe
Hello world!

还有gdb-mingw-w64提供/usr/bin/x86_64-w64-mingw32-gdb,但我不知道它是如何工作的(当我尝试时它显示Don't know how to run. Try "help target".)。

可以使用/usr/share/win64/gdbserver.exe(来自gdb-mingw-w64-target 包)在Linux 上远程交叉调试Windows 二进制文件。例如:

/usr/share/win64/gdbserver.exe localhost:1234 ./hello.exe
Listening on port 1234

然后打开常规gdb会话:

gdb -q hello.exe
Reading symbols from hello.exe...
(gdb) target remote localhost:1234
Remote debugging using localhost:1234
warning: Could not load shared library symbols for 4 libraries, e.g. C:\windows\system32\ntdll.dll.
Use the "info sharedlibrary" command to see the complete listing.
Do you need "set solib-search-path" or "set sysroot"?
0x000000007bcddf65 in ?? ()
(gdb) b main
Breakpoint 1 at 0x40159c: file hello.c, line 2.
(gdb) c
Continuing.

Breakpoint 1, main () at hello.c:2
2   int main() {
(gdb) n
3       printf("Hello world!\n");
(gdb) n
4   }
(gdb) c
Continuing.
[Inferior 1 (Remote target) exited normally]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多