Cross-compiling for OS X from Linux
Asked Answered
E

1

18

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.

Ephraimite answered 9/9, 2016 at 10:10 Comment(7)
Based on my experience with Linux and OS X, there's no easy way to cross-compile for OS X from Linux. It would probably be easiest/best to buy an older, second hand Mac or Macbook and work from it. Also note there is a free and open source GNUstep, which attempts to provide the Cocoa framework.Neuron
@Neuron I'm creating already three different shared libraries (Linux 32, 64 and Windows), so I'd really prefer to be able to create the forth one as well.Amboina
You won't be able to do it without the Xcode SDK because you need the header files. For what you are trying to do you are probably better off using a cross build image github.com/multiarch/crossbuildStephanestephani
+1 to jww; however, even if that`s not quite legal (or is it?), you might want to install Hackintosh on a VM like VirtualBox. That`d make compiling for Mac a lot easier.Undergo
In my experience, the best solution is to avoid osxcross and use homebrew on a mac instead.Vestry
I don't think its possible. If you want you can rent a mac online from websites like macincloud.com or xcodeclub.com.Fidellas
Not an answer, but just so you know: tcpdump and libpcap come preinstalled on macOS.Microvolt
E
6

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.

Eolithic answered 10/1, 2019 at 1:49 Comment(2)
The license agreement of Mac OS (at least current versions) prohibits its being run on non-Apple hardware, even if it's technically possible to do so.Cabalism
Quoting the FAQ at darlinghq.org: **Does it violate Apple's EULA?** No! We only directly use those parts of Darwin that are released as fully free software. I take from that statement that Darling doesn't conflict with the license agreement. But I'm not a lawyer.Pinchpenny

© 2022 - 2024 — McMap. All rights reserved.