C++ 交叉编译手册 应用程序从Linux到Windows?

发布于 2024-07-07 10:42:25 字数 176 浏览 5 评论 0原文

是否有从 Linux 到 Windows 交叉编译 C++ 应用程序的手册?

只是。 我想要一些信息(链接、参考、示例...)来指导我做到这一点。

我什至不知道这是否可能。

我的目标是在 Linux 中编译一个程序并获得一个可以在 Windows 下运行的 .exe 文件。

Is there a manual for cross-compiling a C++ application from Linux to Windows?

Just that. I would like some information (links, reference, examples...) to guide me to do that.

I don't even know if it's possible.

My objective is to compile a program in Linux and get a .exe file that I can run under Windows.

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

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

发布评论

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

评论(3

南薇 2024-07-14 10:42:33

我建议您尝试一下 GUB (Grand Unified Builder),因为它交叉编译了多个包它们的依赖关系并将它们组装成当前 11 种架构的单个安装包。 您可以从 此处并遵循此处的源代码。 它目前可用于交叉编译 GNU LilyPond/ GNU Denemo / Inkscape 和 OpenOffice.org。

目标架构为:

  • darwin-ppc - Darwin 7 (MacOS 10.3)/PowerPC 的
  • tar.bz2 文件 darwin-x86 - Darwin 8 (MacOS 10.4)/x86 的 tar.bz2 文件
  • mingw - Windows32 的 mingw 可执行
  • 文件 linux-x86 - shar Linux/x86 的存档
  • linux-64 - Linux/x86_64 的 shar 存档
  • linux-ppc - Linux/PowerPC 的 shar 存档
  • freebsd-x86 - FreeBSD 4/x86 的 shar 存档
  • freebsd-64 - FreeBSD 6/x86_64 的 shar 存档
  • cygwin - .适用于 Cygwin/Windows32 的 tar.bz2 软件包
  • arm - 适用于 Linux/ARM 的 shar 存档(基本未经测试)
  • debian - 适用于 Debian 的 shar 存档(基本未经测试)

I suggest you give the following, GUB (Grand Unified Builder) a try as it cross-compiles several packages with their dependencies and assembles them into a single installation package for currently 11 architectures. You can download a prebuilt iso for installation in a VM from here and follow the source here. It can currently be used to cross-compile GNU LilyPond/ GNU Denemo / Inkscape and OpenOffice.org.

The target architectures are:

  • darwin-ppc - tar.bz2 file for Darwin 7 (MacOS 10.3)/PowerPC
  • darwin-x86 - tar.bz2 file for Darwin 8 (MacOS 10.4)/x86
  • mingw - mingw executable for Windows32
  • linux-x86 - shar archive for Linux/x86
  • linux-64 - shar archive for Linux/x86_64
  • linux-ppc - shar archive for Linux/PowerPC
  • freebsd-x86 - shar archive for FreeBSD 4/x86
  • freebsd-64 - shar archive for FreeBSD 6/x86_64
  • cygwin - .tar.bz2 packages for Cygwin/Windows32
  • arm - shar archive for Linux/ARM (largely untested)
  • debian - shar archive for Debian (largely untested)
最后的乘客 2024-07-14 10:42:32

这取决于你的意思(我真的不能说)。

  1. 如果您想在 Windows 上使用现有的 Linux 应用程序,那么您可以尝试使用 Cygwin。 然而,这并不能为您提供一个摆脱对 Cygwin 的所有依赖关系的 Windows 可执行文件(您的可执行文件仍然依赖于 cygwin.dll 文件) - 并且它仍然可能需要一些移植才能工作。 请参阅 http://www.cygwin.com

  2. 如果您的意思是您希望能够在 Linux 上执行 Windows 应用程序的实际编译并生成可在 Windows 上执行的 .exe 文件 - 从而使用您的 Linux 机器进行开发和/或编译,那么您应该查看进入 MinGW for Linux,这是一个在 Linux 上交叉编译 Windows 的工具。 请参阅 http://www.mingw.org/wiki/LinuxCrossMinGW

此致!

It depends on what you mean (I couldn't really say).

  1. If you mean that you want to use an existing Linux application on Windows, then you could try compiling it using Cygwin on Windows. This however does not give you a Windows executable free from all dependencies towards Cygwin (your executable still depends on the cygwin.dll file) - and it still may need some porting before it will work. See http://www.cygwin.com.

  2. If you mean that you want to be able to perform the actual compilation of a Windows application on Linux and produce a .exe file that is executable on Windows - thus using your Linux box for development and/or compilation then you should look into MinGW for Linux which is a tool for crosscompiling for Windows on Linux. See http://www.mingw.org/wiki/LinuxCrossMinGW.

Best regards!

别在捏我脸啦 2024-07-14 10:42:30

基础知识并不太难:

sudo apt-get install mingw32    
cat > main.c <<EOF
int main()
{
  printf("Hello, World!");
}
EOF
i586-mingw32msvc-cc main.c -o hello.exe

将 apt-get 替换为 yum 或您的 Linux 发行版使用的任何内容。 这将为 Windows 生成 hello.exe

一旦你明白了这一点,你就可以使用autotools,并设置CC=i586-mingw32msvc-cc

CC=i586-mingw32msvc-cc ./configure && make

或使用 CMake 和工具链文件来管理构建。 更困难的仍然是添加本机交叉库。 通常它们存储在 /usr/cross/i586-mingw32msvc/{include,lib} 中,您需要在构建过程的配置步骤中单独添加这些路径。

The basics are not too difficult:

sudo apt-get install mingw32    
cat > main.c <<EOF
int main()
{
  printf("Hello, World!");
}
EOF
i586-mingw32msvc-cc main.c -o hello.exe

Replace apt-get with yum, or whatever your Linux distro uses. That will generate a hello.exe for Windows.

Once you get your head around that, you could use autotools, and set CC=i586-mingw32msvc-cc

CC=i586-mingw32msvc-cc ./configure && make

Or use CMake and a toolchain file to manage the build. More difficult still is adding native cross libraries. Usually they are stored in /usr/cross/i586-mingw32msvc/{include,lib} and you would need to add those paths in separately in the configure step of the build process.

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