How to Compile for OS X in Linux or Windows?

2019-01-04 08:25发布

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?

11条回答
Bombasti
2楼-- · 2019-01-04 08:30
  1. Get "VMware Player"
  2. Get "Mac OS X vm image"
  3. 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:

  1. I make a change on OS 1
  2. reboot into OS 2
  3. forget something on OS 1
  4. reboot into OS 1
  5. make a change on OS 1
  6. reboot into OS 2 ... AGAIN...

BAM there goes 30 minutes of my time and I haven't done anything productive.

查看更多
ら.Afraid
3楼-- · 2019-01-04 08:33

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.

查看更多
萌系小妹纸
4楼-- · 2019-01-04 08:33

I found this small documentation on the net: 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.

查看更多
我命由我不由天
5楼-- · 2019-01-04 08:37

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.

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.

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.

查看更多
【Aperson】
6楼-- · 2019-01-04 08:44

The short answer is kind of. You will need to use a cross-platform library like QT. There are IDE's like QT Creator that will let you develop on one OS and generate Makefiles for others. For more information on cross platform development, check out the cross-platform episodes of this podcast (note that the series isn't over and new episodes appear to come out weekly).

As other answers explain you can probably compile for a Mac on Windows or Linux but you won't be able to test your applications so you should probably spend the $600 for a Mac if you’re doing professional programming, or if you’re working on open-source software find a developer with a Mac who will help you.

查看更多
Ridiculous、
7楼-- · 2019-01-04 08:48

You can hire a mac in the cloud from this website. You can hire them from $1, which should be enough (unless you need root access, then you are looking at $49+).

查看更多
登录 后发表回答