如何在 Linux 上调用 MinGW 交叉编译器?

2023-10-17C/C++开发问题
25

本文介绍了如何在 Linux 上调用 MinGW 交叉编译器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个项目要为 Windows 交叉编译.我有合适的 Makefile 并且一切都适用于 g++.我跑了

I have a project that I want to cross-compile for Windows. I have the appropriate Makefile and everything works with g++. I've run

$ apt install mingw-w64

并下载了 500 MB 的软件包,但我不知道如何实际运行它.没有 mingw 可执行文件,那么我如何实际使用它进行编译?

and downloaded 500 MB of packages, but I cannot find out how to actually run it. There is no mingw executable, so how do I actually compile with it?

推荐答案

如果您查看 mingw-w64 的组成软件包的 Ubuntu 软件包网络服务器上的文件列表:

If you look at the file lists on the Ubuntu package webserver for mingw-w64's constituent packages:

  • gcc-mingw-w64-x86-64
  • g++-mingw-w64-x86-64
  • binutils-mingw-w64-x86-64
  • mingw-w64-x86-64位开发
  • gcc-mingw-w64-i686
  • g++-mingw-w64-i686
  • binutils-mingw-w64-i686
  • mingw-w64-i686-dev

您可以看到 mingw-w64 提供了一个工具链,即一组用于编译您的代码的替代工具(编译器、链接器、头文件等)另一个系统.

You can see that mingw-w64 provides a toolchain, i.e. a set of alternative tools (compiler, linker, headers, etc.) used to compile your code for another system.

假设您要为 64 位系统编译 C++ 代码,则需要使用 /usr/bin/x86_64-w64-mingw32-g++-win32.您可以使用 CXX 环境变量告诉大多数 Makefile 使用该编译器来编译代码.

Assuming you want to compile C++ code for a 64-bit system, you'll need to use /usr/bin/x86_64-w64-mingw32-g++-win32. You can use the CXX environment variable to tell most Makefiles to use that compiler to compile code.

这篇关于如何在 Linux 上调用 MinGW 交叉编译器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

无法访问 C++ std::set 中对象的非常量成员函数
Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)...
2024-08-14 C/C++开发问题
17

从 lambda 构造 std::function 参数
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)...
2024-08-14 C/C++开发问题
25

STL BigInt 类实现
STL BigInt class implementation(STL BigInt 类实现)...
2024-08-14 C/C++开发问题
3

使用 std::atomic 和 std::condition_variable 同步不可靠
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)...
2024-08-14 C/C++开发问题
17

在 STL 中将列表元素移动到末尾
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)...
2024-08-14 C/C++开发问题
9

为什么禁止对存储在 STL 容器中的类重载 operator&()?
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)...
2024-08-14 C/C++开发问题
6