How to Compile for OS X in Linux or Windows?
Solution 1
There appears to be some scripts that 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 instructions for cross-compiling for 10.4, and these ones for cross compiling for 10.5; those instructions may be more helpful than the script, depending on how well the script fits your needs.
If your program is free or open source software, then you may wish instead to create a MacPorts portfile (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).
Solution 2
For Linux, there is a prebuilt GCC cross-compiler (from publicly available Apple's modified GCC sources).
https://launchpad.net/~flosoft/+archive/cross-apple
Update for 2015
- After so many years, the industry-standard IDE now supports OSX/iOS/Android.
http://channel9.msdn.com/Events/Visual-Studio/Connect-event-2014/311
Embarcadero's RadStudio also supports building OSX/iOS/Android apps on Windows.
This answer by Thomas also provides a cross-compilation tool.
For all these options you still need a real mac/i-device to test the application.
Solution 3
I have created a project called OSXCross which aims to target OS X (10.4-10.9) from Linux.
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+).
LTO works as well, for both, clang
and GCC
.
Currently using cctools-870 with ld64-242.
https://github.com/tpoechtrager/osxcross
Solution 4
- 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
When you are trying to get something working on multiple platforms you absolutely must compile/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.
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.
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...
BAM there goes 30 minutes of my time and I haven't done anything productive.
Solution 5
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.
Related videos on Youtube
Unknown
Updated on July 05, 2022Comments
-
Unknown almost 2 years
I would like to port my C/C++ apps to OS X.
I don't have a Mac, but I have Linux and Windows. Is there any tool for this?
-
Admin over 13 yearsWhen 3 boots take 30 minutes, you need new hardware; and probably the ability to access and edit one OS's filesystem from another. But I understand the sentiment and also prefer VMs because they allow me to mostly treat them as dedicated physical machines.
-
Arafangion over 13 yearsThe time taken to reboot isn't just the boot-up time, it's the shut-down time, restarting daemons, setting up your development environment, checking that you still have the most recent checkout from your version control system, etcetera.
-
Trevor Boyd Smith over 12 yearsNot to mention my brain loses all cache-coherency and needs to slowly re-cache everything I need to do... and most likely lose productivity when the web browser opens accidently.
-
Prof. Falken over 12 yearsI have access to many Windows machines. Yet I prefer to generate the Windows binary at the same time I build for Linux. Of course then the program must be tested on Windows, but it's very convenient to see that the program at least builds for all targeted platforms in one step.
-
Admin almost 12 yearsIf you have the cross toolchain, you can simply copy the libs from OS X.
-
rubenvb about 11 years@MartinKällman it is against the Apple license agreement. Legality of this depends on what country you're in.
-
awdz9nld about 11 years@rubenvb fair enough, I just personally find it to be unbefitting of SO :o)
-
smaudet almost 11 yearsIt may be technically against a random license agreement, but you can always just buy a Mac Pro and run all three OS using VMs on it. So why shouldn't you be able to buy a nice Windows box and do the same? Allowing anything else is anti-competitive practice, and in my books, downright illegal (or it should be).
-
smaudet almost 11 yearsNot to mention you may not have a Mac, but be interested in allowing others (who want to use your application on a mac) to test the application, without having to compile it themselves.
-
Prof. Falken over 10 yearsOr homebrew nowadays instead of macports.
-
RushPL over 10 yearsHow well does it work? Would it allow compiling Qt for MacOSX for example?
-
Viktor Latypov over 10 yearsIt is a perfectly valid GCC 4.2, capable of compiling large libraries. However, it has not been updated for 10.7, 10.8 or 10.9 SDKs, so right now it can be considered as outdated. I've been using it to compile my own project in C/C++ just to test if it can be ported and fix some obvious incompatibilities, then I've built it on the real mac.
-
Travis Pessetto over 10 yearsI thought it worth noting that Apple no longer uses GCC in XCode, they now use Clang/LLVM.
-
Sam Watkins over 9 yearsSounds like a job for two computers to be honest. but I appreciate your suggestion. Apple sucks for being a "control freak" against their users and developers. :/
-
panzi almost 9 yearsHow can I install this on Fedora?
-
Viktor Latypov almost 9 years@panzi: I've used it only on CrunchBang (a variant of Debian), maybe you should unpack the .deb archives and try to configure the paths. Or, as usual, try to compile the sources. Maybe this answer provides better alternative now: stackoverflow.com/a/19891283/1182653
-
Panayotis over 8 yearsI have used your project and it does what it promises. Tested with latest XCode (7.1) and latest OSX (10.11.1).
-
Brian Campbell over 8 years@jcoffland No, the other way around. It's for building OS X applications on Linux. Read the title. "Cross-Compiling on Linux for Mac OS X 10.3 - 10.5" (emphasis added). Note that this answer is very old by now (almost 7 years old, yikes!) and the later answers below have more up to date information.
-
0xC0000022L over 7 yearsThis assumes, though, that one wants to copy ones sources to some machine "in the cloud". Quite an assumption for non-FLOSS.
-
Lennart Rolland about 7 yearsEven Qt will need a cross-compilation toolchain to build OSX binaries on non-OSX platform.
-
Xantium over 6 yearsNot very long term. After using it 30 times it would be cheaper to buy a mac.
-
AnotherParker about 6 yearsUnfortunately, although Microsoft announced Visual Studio Connect that supports other compilers including clang, I can't find any information as to how to actually target MacOS.
-
Kotauskas about 5 yearsCopying is the way to go, though you'll need the headers/staticlibs too.
-
Admin about 2 yearsYour answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.