C++ 如何在 Linux 或 Windows 中为 OS X 编译?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/693952/
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
How to Compile for OS X in Linux or Windows?
提问by Unknown
I would like to port my C/C++ apps to OS X.
我想将我的 C/C++ 应用程序移植到 OS X。
I don't have a Mac, but I have Linux and Windows. Is there any tool for this?
我没有 Mac,但我有 Linux 和 Windows。有什么工具可以做到这一点吗?
采纳答案by Brian Campbell
There appears to be some scriptsthat have been written to help get you set up cross compiling for the Mac; I can't say how good they are, or how applicable to your project. In the documentation, they refer to these instructionsfor cross-compiling for 10.4, and these onesfor cross compiling for 10.5; those instructions may be more helpful than the script, depending on how well the script fits your needs.
似乎已经编写了一些脚本来帮助您为 Mac 设置交叉编译;我不能说它们有多好,或者如何适用于您的项目。在本文档中,它们指的是这些说明进行交叉编译为10.4,和这些的为10.5交叉编译; 这些说明可能比脚本更有帮助,具体取决于脚本是否符合您的需求。
If your program is free or open source software, then you may wish instead to create a MacPortsportfile (documentation here), and allow your users to build your program using MacPorts; that is generally the preferred way to install portable free or open source software on Mac OS X. MacPorts has been known to run on Linux in the past, so it may be possible to develop and test your Portfile on Linux (though it will obviously need to be tested on a Mac).
如果您的程序是免费或开源软件,那么您可能希望创建一个MacPorts端口文件(此处为文档),并允许您的用户使用 MacPorts 构建您的程序;这通常是在 Mac OS X 上安装可移植的免费或开源软件的首选方式。过去已知 MacPorts 可以在 Linux 上运行,因此有可能在 Linux 上开发和测试您的 Portfile(尽管它显然需要在 Mac 上进行测试)。
回答by Viktor Latypov
For Linux, there is a prebuilt GCC cross-compiler (from publicly available Apple's modified GCC sources).
对于 Linux,有一个预构建的 GCC 交叉编译器(来自公开可用的 Apple 修改后的 GCC 源)。
https://launchpad.net/~flosoft/+archive/cross-apple
https://launchpad.net/~flosoft/+archive/cross-apple
Update for 2015
2015 年更新
- After so many years, the industry-standard IDE now supports OSX/iOS/Android.
- 经过这么多年,行业标准的 IDE 现在支持 OSX/iOS/Android。
http://channel9.msdn.com/Events/Visual-Studio/Connect-event-2014/311
http://channel9.msdn.com/Events/Visual-Studio/Connect-event-2014/311
Embarcadero's RadStudio also supports building OSX/iOS/Android apps on Windows.
For all these options you still need a real mac/i-device to test the application.
对于所有这些选项,您仍然需要一个真正的 mac/i 设备来测试应用程序。
回答by Thomas
I have created a project called OSXCrosswhich aims to target OS X (10.4-10.9) from Linux.
我创建了一个名为OSXCross的项目,旨在从 Linux 定位 OS X (10.4-10.9)。
It currently supports clang
3.2 up to 3.8 (trunk) (you can use your dist's clang
).
In addition you can build an up-to-date vanilla GCC
as well (4.6+).
它目前支持clang
3.2 到 3.8(中继)(你可以使用你的 dist clang
)。
此外,您还可以构建最新的香草GCC
(4.6+)。
LTO works as well, for both, clang
and GCC
.
LTO 也适用于两者clang
和GCC
.
Currently using cctools-870 with ld64-242.
目前使用 cctools-870 和 ld64-242。
回答by Trevor Boyd Smith
- Get "VMware Player"
- Get "Mac OS X vm image"
- Compile/Debug/Integrate-and-test your code on the new OS to make sure everything works
- 获取“ VMware Player”
- 获取“ Mac OS X虚拟机映像”
- 在新操作系统上编译/调试/集成和测试您的代码以确保一切正常
When you are trying to get something working on multiple platforms you absolutely mustcompile/run/integrate/test on the intended platform. You can not just compile/run on one platform and then say "oh it should work the same on the other platform".
当您尝试在多个平台上运行某些东西时,您绝对必须在预期平台上编译/运行/集成/测试。你不能只在一个平台上编译/运行,然后说“哦,它应该在另一个平台上工作相同”。
Even with the a really good cross-platform language like Java you will run into problems where it won't work exactly the same on the other platform.
即使使用像 Java 这样非常好的跨平台语言,您也会遇到问题,即它在其他平台上无法完全相同地工作。
The only way I have found that respects my time/productivity/ability-to-rapidly iterate on multiple platforms is to use a VM of the other platforms.
我发现尊重我的时间/生产力/在多个平台上快速迭代的能力的唯一方法是使用其他平台的 VM。
There are other solutions like dual-boot and ones that I haven't mentioned but I find that they don't respect my productivity/time.
还有其他解决方案,如双启动和我没有提到的解决方案,但我发现它们不尊重我的生产力/时间。
Take dual-booting as an example:
以双启动为例:
- I make a change on OS 1
- reboot into OS 2
- forget something on OS 1
- reboot into OS 1
- make a change on OS 1
- reboot into OS 2 ... AGAIN...
- 我在 OS 1 上进行了更改
- 重新启动到 OS 2
- 忘记操作系统 1 上的某些东西
- 重新启动到 OS 1
- 在 OS 1 上进行更改
- 重新启动到 OS 2 ......再次......
BAMthere goes 30 minutes of my time and I haven't done anythingproductive.
BAM在那里花了我 30 分钟的时间,但我没有做任何有成效的事情。
回答by Adam Hawes
Apple development is a strange beast unto itself. OS X uses a port of GCC with some modifications to make it 'appley'. In theory, it's possible to the the sources to the Apple GCC and toolchain as well as the Apple kernel and library headers and build a cross compiler on your Windows machine.
苹果的开发本身就是一头奇怪的野兽。OS X 使用 GCC 端口并进行了一些修改以使其成为“appley”。理论上,可以获取 Apple GCC 和工具链以及 Apple 内核和库头文件的源代码,并在您的 Windows 机器上构建交叉编译器。
Why you'd want to go down this path is beyond me. You can have a cheap Mac mini from $600. The time you invest getting a cross compiler working right (particularly with a Windows host for Unix tools) will probably cost more than the $600 anyway.
为什么你想走这条路是我无法理解的。您可以购买 600 美元起的廉价 Mac mini。无论如何,您投入的时间使交叉编译器正常工作(尤其是使用用于 Unix 工具的 Windows 主机)可能会花费超过 600 美元。
If you're really keen to make your app cross platform look into Qt, wxWidgets or FLTK. All provide cross-platform support with minimal changes to the base code. At least that way all you need to do is find a Mac to compile your app on, and that's not too hard to do if you have some technically minded friends who don't mind giving you SSH access to their Mac.
如果你真的很想让你的应用跨平台研究 Qt、wxWidgets 或 FLTK。所有这些都提供跨平台支持,对基本代码进行最少的更改。至少这样你需要做的就是找到一台 Mac 来编译你的应用程序,如果你有一些有技术头脑的朋友不介意让你通过 SSH 访问他们的 Mac,那么这并不难。
回答by Pablo Santa Cruz
You will definitely need OS X somehow. Even if you don't own a Mac, you can still try some alternatives.
您肯定会以某种方式需要 OS X。即使您没有 Mac,您仍然可以尝试一些替代品。
回答by Joel Levin
You would need a toolchain to cross compile for mach-o, but even if you had that, you won't have the Apple libraries around to develop with. I'm not sure how you would be able to port without them, unfortunately.
您将需要一个工具链来为 mach-o 进行交叉编译,但即使您拥有该工具链,您也不会拥有可用于开发的 Apple 库。不幸的是,我不确定如果没有它们,您将如何进行移植。
回答by Joel Levin
I found this small documentation on the net: http://devs.openttd.org/~truebrain/compile-farm/apple-darwin9.txt
我在网上找到了这个小文档:http: //devs.openttd.org/~truebrain/compile-farm/apple-darwin9.txt
This describes exactly what you want. I am interested in it myself, haven't tested it yet though (found it 10 minutes ago). The documentation seems good, though.
这正是您想要的。我自己对它很感兴趣,但还没有测试过(10 分钟前找到了)。不过,文档似乎不错。
回答by 64_
回答by greyfade
There are a few cross-compiler setups, but nearly all of them are meant for distcc-style distributed compiling. To my knowledge there is no way to directly target the Mac platform without actually having a Mac. The closest you can get without resorting to QT or wxWidgets is OpenStep with GNUStep or similar, but that's not a true Cocoa platform, just very close.
有一些交叉编译器设置,但几乎所有设置都是用于 distcc 风格的分布式编译。据我所知,没有 Mac 就无法直接针对 Mac 平台。不求助于 QT 或 wxWidgets 的最接近的是 OpenStep 和 GNUStep 或类似的,但这不是真正的 Cocoa 平台,只是非常接近。