xcode 在 Mac 上编译 C++ 程序在 Linux 上运行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3060417/
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
Compile C++ program on Mac to run on Linux
提问by mav
Possible Duplicate:
How to cross compile from Mac OS X to Linux x86?
I have an application that I wrote in C++/SDL, using FMOD library. The app is portable and compiles without any code change on Mac and on Linux. But one annoyance is that when I want to ship Linux version, I have to run my Linux box, copy the source code over there (over USB drive, because I have no network there, it's an old laptop) and compile it, then copy it again over USB to my Mac and upload it.
我有一个使用 FMOD 库用 C++/SDL 编写的应用程序。该应用程序是可移植的,无需更改 Mac 和 Linux 上的任何代码即可编译。但一个烦恼是,当我想发布 Linux 版本时,我必须运行我的 Linux 机器,将源代码复制到那里(通过 USB 驱动器,因为那里没有网络,它是一台旧笔记本电脑)并编译它,然后复制再次通过 USB 连接到我的 Mac 并上传。
My question is - is there a better way of doing it? Ideally, could I compile the app to run on Linux directly from Xcode, where I compile it for Mac?
我的问题是 - 有没有更好的方法来做到这一点?理想情况下,我可以直接从 Xcode 编译应用程序以在 Linux 上运行吗?
采纳答案by Troubadour
A quick google for cross-compiling for Linux on OSX revealed this page.
在 OSX 上为 Linux 进行交叉编译的快速谷歌显示了这个页面。
Actually, this has been asked before in How to cross compile from Mac OS X to Linux x86?.
回答by Greg S
Take a look at How to cross compile from Mac OS X to Linux x86?and the links therein (it suggests compiling under Linux running in a VM, probably the best idea, since trying to setup cross-compiling usually isn't worth the work and trouble).
看看如何从 Mac OS X 交叉编译到 Linux x86?以及其中的链接(它建议在运行在 VM 中的 Linux 下编译,这可能是最好的主意,因为尝试设置交叉编译通常不值得付出努力和麻烦)。
回答by MarkR
The risk of shipping a duff binary is too high to be worth bothering trying to build it on an alien box.
运送 duff 二进制文件的风险太高了,不值得费心去尝试在一个外星盒子上构建它。
You'll clearly NEED a Linux box knocking around for testing each time you do a new release. Therefore, it will be no hassle to build it on that box. Using a Linux VM though is probably a good idea as you can make sure the VM is in the exact same state (and known state) before each build.
每次发布新版本时,您显然都需要一个 Linux 机器来进行测试。因此,在那个盒子上构建它不会很麻烦。不过,使用 Linux VM 可能是个好主意,因为您可以确保 VM 在每次构建之前都处于完全相同的状态(和已知状态)。
I'm assuming that you are at least going to smoke-test each release.
我假设您至少要对每个版本进行冒烟测试。
回答by Luca Matteis
You could statically link the entire code (with all dependencies) into a single binary and have a version for Mac and a version for Linux.
您可以将整个代码(包含所有依赖项)静态链接到一个二进制文件中,并拥有一个适用于 Mac 的版本和一个适用于 Linux 的版本。