如何使用 gcc/g++ 在 Linux 上为 Windows 编译?

2021-12-18 00:00:00 opengl gcc c++ glut freeglut

我在 Linux 上使用 freeglut 在 C++ (g++) 中编写了一些效果,并使用

I have written some effects in C++ (g++) using freeglut on Linux, and I compile them with

g++ -Wall -lglut part8.cpp -o part8

所以我想知道是否有可能让 g++ 生成包含所需一切的静态编译 Windows 可执行文件?

So I was wondering if it is possible to have g++ make static compiled Windows executables that contains everything needed?

我没有 Windows,所以如果我能在 Linux 上做到这一点,那就太酷了 :)

I don't have Windows, so it would be really cool, if I could do that on Linux :)

推荐答案

mingw32 作为 Linux 的一个包存在.您可以使用它交叉编译和链接 Windows 应用程序.在 Code::Blocks 论坛上有一个教程.例如,请注意命令更改为 x86_64-w64-mingw32-gcc-win32.

mingw32 exists as a package for Linux. You can cross-compile and -link Windows applications with it. There's a tutorial here at the Code::Blocks forum. Mind that the command changes to x86_64-w64-mingw32-gcc-win32, for example.

例如,Ubuntu 的存储库中有 MinGW:

Ubuntu, for example, has MinGW in its repositories:

$ apt-cache search mingw
[...]
g++-mingw-w64 - GNU C++ compiler for MinGW-w64
gcc-mingw-w64 - GNU C compiler for MinGW-w64
mingw-w64 - Development environment targeting 32- and 64-bit Windows
[...]

相关文章