Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross-compiling for OS X from Linux

Is there an easy to use tool-chain to compile code for Darwin (mac's OS) from Linux?

For example, I would like to compile libpcap (or tcpdump) on a Linux machine and run in on my MAC. I've come across osxcross but it requires getting the Xcode SDK and such, has anyone tried this before ?

Thanks.

like image 972
Blondy314 Avatar asked Sep 09 '16 10:09

Blondy314


People also ask

Is Mac OS X based on Linux?

You may have heard that Macintosh OSX is just Linux with a prettier interface. That's not actually true. But OSX is built in part on an open source Unix derivative called FreeBSD. And until recently, FreeBSD's co-founder Jordan Hubbard served as director of Unix technology at Apple.

Can GCC cross-compile?

For instance when installing GCC, the GNU Compiler Collection, we can use --target= target to specify that we want to build GCC as a cross-compiler for target . Mixing --build and --target , we can cross-compile a cross-compiler; such a three-way cross-compilation is known as a Canadian cross.


1 Answers

You should give darling a spin.

Darling is:

Darling is a runtime environment for OS X applications.

It's like WINE for Mac OS X. Although it is still relatively a small project, you can already compile applications using Xcode using darling.

Darling [~]$ hdiutil attach Xcode_7.2.dmg
/Volumes/Xcode_7.2
Darling [~]$ cp -r /Volumes/Xcode_7.2/Xcode.app /Applications
Darling [~]$ export SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk
Darling [~]$ echo 'void main() { puts("Hello world"); }' > helloworld.c
Darling [~]$ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang helloworld.c -o helloworld
Darling [~]$ ./helloworld
Hello world

I'm not sure a more complicated program will compile correctly and will work on Mac, but it's worth a try.

Alternatively, you can run Mac OS X on a Virtualbox inside Linux, and then transfer the compiled files to the destination machine.

like image 66
oz123 Avatar answered Oct 16 '22 16:10

oz123