简体   繁体   English

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

[英]Manual for cross-compiling a C++ application from Linux to Windows?

Is there a manual for cross-compiling a C++ application from Linux to Windows? 是否有从Linux到Windows交叉编译C ++应用程序的手册?

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. 我的目标是在Linux中编译一个程序并获得一个我可以在Windows下运行的.exe文件。

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. apt-get替换为yum ,或者Linux发行版使用的任何内容。 That will generate a hello.exe for Windows. 这将生成Windows的hello.exe

Once you get your head around that, you could use autotools , and set CC=i586-mingw32msvc-cc 一旦你了解了它,你可以使用autotools ,并设置CC=i586-mingw32msvc-cc

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

Or use CMake and a toolchain file to manage the build. 或者使用CMake和工具链文件来管理构建。 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. 通常它们存储在/usr/cross/i586-mingw32msvc/{include,lib} ,您需要在构建过程的配置步骤中单独添加这些路径。

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. 如果您的意思是要在Windows上使用现有的Linux应用程序,那么您可以尝试在Windows上使用Cygwin进行编译。 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. 但是,这并没有给你一个Windows可执行文件,没有所有依赖Cygwin(你的可执行文件仍然依赖于cygwin.dll文件) - 它仍然可能需要一些移植才能工作。 See http://www.cygwin.com . 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. 如果您的意思是希望能够在Linux上执行Windows应用程序的实际编译并生成可在Windows上执行的.exe文件 - 从而使用Linux框进行开发和/或编译,那么您应该查看MinGW Linux是Linux上用于交叉编译Windows的工具。 See http://www.mingw.org/wiki/LinuxCrossMinGW . http://www.mingw.org/wiki/LinuxCrossMinGW

Best regards! 最好的祝福!

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. 我建议您尝试下面的GUB (Grand Unified Builder),因为它将几个包与它们的依赖项交叉编译,并将它们组装成一个单独的安装包,用于当前的11个体系结构。 You can download a prebuilt iso for installation in a VM from here and follow the source here . 您可以从此处下载预安装的iso以便在VM中安装,并在此处按照源进行操作。 It can currently be used to cross-compile GNU LilyPond/ GNU Denemo / Inkscape and OpenOffice.org. 它目前可用于交叉编译GNU LilyPond / GNU Denemo / Inkscape和OpenOffice.org。

The target architectures are: 目标架构是:

  • darwin-ppc - tar.bz2 file for Darwin 7 (MacOS 10.3)/PowerPC 用于Darwin 7(MacOS 10.3)/ PowerPC的darwin-ppc-tar.bz2文件
  • darwin-x86 - tar.bz2 file for Darwin 8 (MacOS 10.4)/x86 darwin-x86 - 用于Darwin 8(MacOS 10.4)/ x86的tar.bz2文件
  • mingw - mingw executable for Windows32 mingw - Windows32的mingw可执行文件
  • linux-x86 - shar archive for Linux/x86 linux-x86 - 用于Linux / x86的shar存档
  • linux-64 - shar archive for Linux/x86_64 linux-64 - 用于Linux / x86_64的shar存档
  • linux-ppc - shar archive for Linux/PowerPC linux-ppc - 用于Linux / PowerPC的shar存档
  • freebsd-x86 - shar archive for FreeBSD 4/x86 freebsd-x86 - 用于FreeBSD 4 / x86的shar存档
  • freebsd-64 - shar archive for FreeBSD 6/x86_64 freebsd-64 - 用于FreeBSD 6 / x86_64的shar存档
  • cygwin - .tar.bz2 packages for Cygwin/Windows32 用于Cygwin / Windows32的cygwin - .tar.bz2包
  • arm - shar archive for Linux/ARM (largely untested) arm - 用于Linux / ARM的存档(很大程度上未经测试)
  • debian - shar archive for Debian (largely untested) Debian - 用于Debian的shar存档(很大程度上未经测试)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM