如何使用 gcc/g++ 在 Linux 上编译 Windows?
我在 Linux 上使用 freeglut 在 C++ (g++) 中编写了一些效果,并使用它们进行编译。
g++ -Wall -lglut part8.cpp -o part8
所以我想知道是否可以让 g++ 生成包含所需所有内容的静态编译 Windows 可执行文件?
我没有 Windows,所以如果我能在 Linux 上做到这一点那就太酷了:)
I have written some effects in C++ (g++) using freeglut on Linux, and I compile them with
g++ -Wall -lglut part8.cpp -o part8
So I was wondering if it is possible to have g++ make static compiled Windows executables that contains everything needed?
I don't have Windows, so it would be really cool, if I could do that on Linux :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
mingw32 作为 Linux 的软件包存在。您可以使用它交叉编译和链接 Windows 应用程序。 Code::Blocks 论坛有一个教程。请注意,例如,命令更改为
x86_64-w64-mingw32-gcc-win32
。例如,Ubuntu 的存储库中有 MinGW:
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, for example, has MinGW in its repositories:
建议的方法在 Ubuntu 16.04 上给了我错误: E: 无法定位包 mingw32
================================================ =================================
要在 Ubuntu 上安装此软件包,请使用以下命令:
安装后即可使用它:
请注意!
对于 64 位使用:x86_64-w64-mingw32-g++
对于 32 位使用:i686-w64-mingw32-g++
Suggested method gave me error on Ubuntu 16.04: E: Unable to locate package mingw32
===========================================================================
To install this package on Ubuntu please use following:
After install you can use it:
Please note!
For 64-bit use: x86_64-w64-mingw32-g++
For 32-bit use: i686-w64-mingw32-g++
在 Linux 中编译 Windows 的一种选择是通过 mingw。我在此处找到了一个非常有用的教程。
要在基于 Debian 的系统上安装 mingw32,请运行以下命令:
sudo apt-get install mingw32
要编译代码,您可以使用以下命令:
i586-mingw32msvc-g++ -o myApp.exe myApp.cpp
您有时会希望直接在 Linux 中测试新的 Windows 应用程序。您可以使用葡萄酒来实现这一点,但您应该始终记住葡萄酒可能有错误。这意味着您可能不确定 wine、您的程序或两者中是否存在错误,因此仅使用 wine 进行一般测试。
要安装 wine,请运行:
sudo apt-get install wine
One option of compiling for Windows in Linux is via mingw. I found a very helpful tutorial here.
To install mingw32 on Debian based systems, run the following command:
sudo apt-get install mingw32
To compile your code, you can use something like:
i586-mingw32msvc-g++ -o myApp.exe myApp.cpp
You'll sometimes want to test the new Windows application directly in Linux. You can use wine for that, although you should always keep in mind that wine could have bugs. This means that you might not be sure that a bug is in wine, your program, or both, so only use wine for general testing.
To install wine, run:
sudo apt-get install wine
安装交叉编译器,例如包管理器中的 mingw64。
然后按以下方式编译:不要简单地调用
gcc
,而是调用i686-w64-mingw32-gcc
(对于 32 位 Windows)或x86_64-w64-mingw32-gcc "
对于 64 位 Windows。我还会使用--static
选项,因为目标系统可能没有所有库。如果你想编译其他语言,例如 Fortran,将前面命令中的
-gcc
替换为-gfortran
。Install a cross compiler, like mingw64 from your package manager.
Then compile in the following way: instead of simply calling
gcc
calli686-w64-mingw32-gcc
for 32-bit Windows orx86_64-w64-mingw32-gcc"
for 64-bit Windows. I would also use the--static
option, as the target system may not have all the libraries.If you want to compile other language, like Fortran, replace
-gcc
with-gfortran
in the previous commands.我在 Linux 上使用 mingw 用 C 语言制作 Windows 可执行文件,我怀疑 C++ 也可以工作。
我有一个项目 ELLCC,它将 clang 和其他东西打包为交叉编译器工具链。我用它来编译适用于 Windows 的 clang (C++)、binutils 和 GDB。点击 ellcc.org 上的下载链接,获取适用于多个 Linux 主机的预编译二进制文件。
I've used mingw on Linux to make Windows executables in C, I suspect C++ would work as well.
I have a project, ELLCC, that packages clang and other things as a cross compiler tool chain. I use it to compile clang (C++), binutils, and GDB for Windows. Follow the download link at ellcc.org for pre-compiled binaries for several Linux hosts.
来自:https://fedoraproject.org/wiki/MinGW/Tutorial
“使用 Windows 交叉编译器的提示和技巧”:https://fedoraproject.org/wiki/MinGW /提示
From: https://fedoraproject.org/wiki/MinGW/Tutorial
"Tips and tricks for using the Windows cross-compiler": https://fedoraproject.org/wiki/MinGW/Tips
对于费多拉:
For Fedora: