17

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.

Alireza
  • 100,211
  • 27
  • 269
  • 172
Blondy314
  • 751
  • 9
  • 24
  • 4
    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](http://www.gnustep.org/), which attempts to provide the Cocoa framework. – jww Jul 03 '17 at 04:36
  • @jww 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. – maaartinus Jul 03 '17 at 07:40
  • 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 https://github.com/multiarch/crossbuild – fhossfel Jul 03 '17 at 11:40
  • +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. – hidefromkgb Jul 08 '17 at 23:01
  • In my experience, the best solution is to avoid osxcross and use homebrew on a mac instead. – Phillip Jul 09 '17 at 10:45
  • I don't think its possible. If you want you can rent a mac online from websites like http://www.macincloud.com or http://www.xcodeclub.com. – jobinrjohnson Jul 30 '17 at 04:33
  • Not an answer, but just so you know: `tcpdump` and `libpcap` come preinstalled on macOS. – Ken Thomases Jan 10 '19 at 04:23

1 Answers1

4

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.

Community
  • 1
  • 1
oz123
  • 27,559
  • 27
  • 125
  • 187
  • 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. – Marnen Laibow-Koser May 17 '19 at 17:28
  • 2
    Quoting the FAQ at https://www.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. – user2366975 Apr 14 '21 at 20:14