简体   繁体   English

如何使用gcc在Linux的Windows上跨平台编译?

[英]How to cross-platform compile on windows for linux using gcc?

My aim is to create cross-platform C++ python modules. 我的目标是创建跨平台的C ++ python模块。 I'm using Cyther (cross-platform The Cross-Platform Cython/Python Compiler). 我正在使用Cyther (跨平台的Cross-Cython / Python编译器)。

Cyther uses GCC to compile modules and gives the user the ability to add GCC command-line args. Cyther使用GCC来编译模块,并使用户能够添加GCC命令行参数。

So, I need run compiler on Windows, but compile for Linux. 因此,我需要在Windows上运行编译器,但要在Linux上编译。 What args I must pass to GCC to compile a module for Linux (or other platform)? 我必须传递给GCC哪些参数来编译Linux(或其他平台)的模块?

Is this possible, if so how? 如果可能的话,这可能吗?

Gcc must be built separately for each compilation target. 必须为每个编译目标分别构建Gcc。 It can be built for any target on any host. 可以为任何主机上的任何目标构建它。 The target you need is i386-linux-gnu (or often i586-linux-gnu ) for 32-bit and x86_64-linux-gnu for 64-bit Linux. 您需要的目标是32位的i386-linux-gnu (或经常是i586-linux-gnu )和64位Linux的x86_64-linux-gnu

Note that it provides separate binaries, i386-linux-gnu-gcc , x86_64-linux-gnu-gcc etc. Parameters are then the same. 请注意,它提供了单独的二进制文件,即i386-linux-gnu-gccx86_64-linux-gnu-gcc等。然后参数相同。

I am not sure anybody provides that, but you can build it yourself. 我不确定有人可以提供,但是您可以自己构建。 A tool to help you with that is described in C++ cross-compiler from Windows to Linux . 从Windows到Linux的C ++交叉编译器中介绍了一种可以帮助您的工具。

Or you can go the simpler way and build on Linux (including cross-compilation to Windows). 或者,您可以采用更简单的方法,并在Linux上构建(包括与Windows的交叉编译)。 This kind of things is just so much easier on a decent Linux distribution. 在一个不错的Linux发行版上,这种事情要容易得多。

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

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