在 Windows 上运行并生成 Linux 代码的 C++ 编译器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4512875/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:50:41  来源:igfitidea点击:

C++ compiler that runs on windows and generates Linux code

c++windowslinuxcompiler-construction

提问by x1234x

I'm just curious if this is posible: Is there C++ compiler that runs on windows and can generate Linux code?

我只是好奇这是否可行:是否有在 Windows 上运行并可以生成 Linux 代码的 C++ 编译器?

回答by Frédéric Hamidi

回答by Kieveli

Absolutely it's possible. You need a compiler that can handle cross-compilations and then specify the target. The key point is to get a compiler that's capable of creating the binary files in a manner required by the target system. g++ would do just that for you.

绝对有可能。您需要一个可以处理交叉编译然后指定目标的编译器。关键是获得一个能够以目标系统所需的方式创建二进制文件的编译器。g++ 会为你做到这一点。

I worked on a project where we used linux to create embedded arm executables using their C compiler, and then used scp to copy it over for testing.

我参与了一个项目,我们使用 linux 使用他们的 C 编译器创建嵌入式 arm 可执行文件,然后使用 scp 将其复制过来进行测试。

回答by MarkR

Yes it's possible, but why bother? There is a risk that you will set it up incorrectly and get a binary which doesn't work correctly.

是的,这是可能的,但为什么要麻烦呢?您可能会错误地设置它并获得无法正常工作的二进制文件。

Plus also, you'll need vmware** installed so you can test the resulting binaries - you are going to run comprehensive tests, aren't you?

此外,您还需要安装 vmware**,以便您可以测试生成的二进制文件 - 您将运行全面的测试,不是吗?

Simply set up another VM to do the building (because of course, you need to test that it will work on a machine without the build-tools installed).

只需设置另一个 VM 来进行构建(当然,因为您需要测试它是否可以在未安装构建工具的机器上运行)。

** Other virtualisation platforms are available, this is not a commercial.

** 可以使用其他虚拟化平台,这不是商业用途。

回答by OneOfOne

If you have recent enough CPU you should get VirtualBoxand just install kubuntuor any other distro, while it might sound complicated it will be easier to test the binaries and debug them.

如果你有足够的 CPU,你应该获得VirtualBox并安装kubuntu或任何其他发行版,虽然这听起来很复杂,但测试二进制文件和调试它们会更容易。

回答by Patrick

There are also libraries such as this one: http://www.shlomifish.org/open-source/portability-libs/that provide portability between platforms. For other ones I suggest looking for abstraction libraries

还有像这样的库:http: //www.shlomifish.org/open-source/portability-libs/提供平台之间的可移植性。对于其他的,我建议寻找抽象库