Compile On Linux For Mac



  • 1Cross compiling for macOS on Linux

Cross compiling for macOS on Linux

Requirements

Arm Compiler for Linux supports all the latest Armv8-A-based processors, including Neoverse processors. Arm Compiler for Linux is a mature toolchain that is tailored to the development of server and High Performance Computing (HPC) applications, and is supported on all leading Linux distributions: RHEL, SLES, and Ubuntu. Note: with the upcoming Go 1.5 (Q3 2015), this will be easier. See 'Cross compilation just got a whole lot better in Go 1.5'(still from Dave Cheney). For successful cross compilation you would need. Compilers for the target platform, if they differed from your host platform, ie you’re on darwin/amd64 (6g) and you want to compile for linux/arm (5g).

What you'll need:

  • an Intel Mac running Leopard, Snow Leopard, or Lion
  • Xcode installed on your Mac or the original or retail operating system DVD (for the SDK)
  • a working Linux setup (tested with Debian Squeeze)
  • up to date source for FPC (tested with 2.4.x) and Lazarus (tested with 0.9.30)
  • the Open Darwin cctools (odcctools)

Warning: These instructions are for i386 Linux; trying this on x64 Linux has failed. Update 2013-12-13: cross compiling from Linux for macOS no longer works at all for 10.8 and above. The compiler works fine but viable linker tools (cctools for linux) are not available for Linux anymore. Please adjust instructions if you find a solution for this. The cctools are available in Arch Linux.

STEP 1: copy the SDK from your Mac

You need to install Xcode from your operating system DVD if you've not already done so and copy the SDK to an appropriate location on your Linux box.

I'd recommend Leopard 10.5.sdk (compatible with Leopard) but it depends on how far back you want to be compatible. The 10.5.sdk is located in /Developer/SDKs on the Mac.I put mine at /opt/Mac/ on my Debian box. Example using ssh from your Linux box to copy over the files:

STEP 2: grab odcctools from SVN

Odcctools apparantly provide binutils for OSX/Darwin.

Linux

On 64 bit Linux environments, fpc mailing list users have problems with this step. Perhaps this StackOverflow question and answer can help: in the configure step, you'd apparently need to setCC='gcc -m32' CXX='g++ -m32' ./configure blah blah blah

and build it as

This installs the tools in /opt/odcctools.I've specified gcc 4.4 but it should be okay with other versions.

STEP 3: rebuild FPC

(my sources are in ~/hg/pascal) Crow for mac os.

Note that the options (OPT) as shown are vital, especially -gw.

STEP 4: configure fpc.cfg

Add a darwin (cross-compile) clause to /etc/fpc.cfg:

STEP 5: build the Carbon LCL

Be sure to specify the Darwin OS target, i386 CPU target and, most importantly, add the -gw option. Perform a Clean+Build of the LCL and the Package Registration.

You should now be able to use Lazarus in Linux to build for macOS.

Gotcha's

There are two more gotcha's when cross-compiling to macOS:

Linux development on mac
  • Be sure to specify the -gw in your projects to avoid problems

reported in (the unfixable) FPC bug #12001.

  • Be sure to specify the -XR option pointing to your SDK root (e.g. -XR/opt/Mac/Leopard10.5.sdk), or the Darwin linker will try to link to the wrong startup object (/usr/lib/crt1.o).

Install Linux On Mac

Source

Fpc Mailing list 6 August 2011 post by Bruce titled 'Re: Cross Compiling from Linux to Leopard 10.5 or Snow Leopard 10.6 target. How? [SOLVED]'Adapted by BigChimp

Older instructions

This section was taken from the general Cross compiling page and may still be of interest:

Compile On Linux For Macbook

Mac
  • First you need the binutils for the platform you want to compile to. Download odcctools from this site (use the cvs version) and follow their instructions for installing. http://www.opendarwin.org/projects/odcctools/
  • you need to create a fake root dir like: $HOME/darwinroot copy at least the /System and /Frameworks and /usr directories (you may have to copy more than this) from your Apple or Darwin computer to $HOME/darwinroot
  • now that you have these files make a folder in $HOME/darwinroot called cross. where ever you installed the odcctools you need to make links for the cross tools to be more fpc friendly. there are a bunch of files from odcc tools called powerpc-apple-darwin-* you need to make links (or rename them) so powerpc-apple-darwin-ld becomes powerpc-darwin-ld, do the same for *-ar and *-as.
  • now you are ready to crosscompile fpc. basically you need to have the fpc source and have a terminal open there.
Compile On Linux For Mac

type:

type (iirc):

if that succeded you can install it to whereever you want with:

now copy the file ./compiler/ppccross somewhere you will be able to find it as it's the compiler you'll need to build powerpc programs

  • configure your /etc/fpc.cfg file.

add a section like this:

whenever you want to crosscompile you have to have ppccross and the symlinks to powerpc-darwin-* in the PATHand you should be able to just do ppccross someprogie.pas and it will create a darwin executable.

I may have missed some things (or most everything) as it's been a while since I did this.

Retrieved from 'https://wiki.freepascal.org/index.php?title=Cross_compiling_OSX_on_Linux&oldid=129917'