G++从Linux交叉编译到Windows

发布于 2025-02-07 11:58:52 字数 230 浏览 2 评论 0原文

我试图将C ++应用程序从Linux交叉到Windows。我希望能够像我一直使用的那样使用普通的G ++编译器。

我尝试在网上寻找有关此问题的帮助,但只发现了Mingw或Clang的东西或具有长期复杂设置的东西。

是否有像一行命令一样,我可以使用G ++ -windows将其构建以在此处构建Windows可执行文件。我的代码不使用任何Windows Libaries,因此应该可以编译。

感谢您的帮助。

Im trying to cross compile a c++ application to windows from linux. I want to be able to use the normal g++ compiler as I have always used.

I tried looking online for help on this issue and found only mingw or clang stuff or stuff with a long complex setup.

Is there like a one line command I can use like g++ -windows to get it to build a windows executable right there. My code doesnt use any windows libaries so should compile just fine.

Thanks for the help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余生一个溪 2025-02-14 11:58:52

真的不是那么困难。您唯一需要做的就是安装g ++ -mingw-w64与:

sudo apt install g++-mingw-w64 -y

之后,您唯一需要做的就是编译:

x86_64-w64-mingw32-g++ hello.c -o hello.exe

这将为Windows提供64位的可执行文件那只是运行。这就是我的方式,我没有任何问题。

如果您想要32位可执行文件,那就做:

i686-w64-mingw32-g++ hello.c -o hello.exe

Is really not that hard. The only thing you need to do is install g++-mingw-w64 with:

sudo apt install g++-mingw-w64 -y

After that, the only thing you need to do is compile with:

x86_64-w64-mingw32-g++ hello.c -o hello.exe

That is going to give you a 64-bit executable for windows that just runs. That's how I do it and I haven't had any problems.

If you want a 32-bit executable just do:

i686-w64-mingw32-g++ hello.c -o hello.exe
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文