Cross Compiling from Linux to a Mac OS X 10.5 or 10.6 target. How?

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Cross Compiling from Linux to a Mac OS X 10.5 or 10.6 target. How?

bruce
So I've got cross-compilation working but I have one last problem.

I can't seem to get fpc to drive the linker to search the SDK path
BEFORE the default paths. Specifically, i386-darwin-ld finds

  /usr/lib/crt1.o

and NOT

  /opt/MacOSX10.5.sdk/usr/lib/crt1.o

despite fpc being passed the option

  -k-L/opt/MacOSX10.5.sdk/usr/lib

on the command line. I'm using Free Pascal Compiler version 2.4.2
[2011/06/07] for i386 and the complete command line is:

fpc \
-MDelphi \
-Scagi \
-O3 \
-Tdarwin \
-Pi386 \
-k-L/opt/MacOSX10.5.sdk/usr/lib \
-vew \
-l \
-Fi${BUILD}/i386/darwin/carbon \
-Fl/opt/MacOSX10.5.sdk/usr/lib \
-Fusrc \
-Fu${LAZARUS}/lcl/units/i386-darwin \
-Fu${LAZARUS}/lcl/units/i386-darwin/carbon \
-Fu${LAZARUS}/packager/units/i386-darwin \
-FU${BUILD}/i386/darwin/carbon/ \
-FE${BUILD}/ \
-oProject \
-gw \
-godwarfsets \
-dLCL \
-dLCLcarbon \
Project.lpr

I know it works because if I temporarily rename /usr/lib/crt1.o the
linker finds the correct SDK version and links the project properly.

What am I doing wrong that fpc does not appear to put the path

  /opt/MacOSX10.5.sdk/usr/lib

ahead of the default paths when calling i386-darwin-ld?

Many thanks, Bruce.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Cross Compiling from Linux to a Mac OS X 10.5 or 10.6 target. How?

Jonas Maebe-2

On 04 Aug 2011, at 15:13, Bruce Tulloch wrote:

> So I've got cross-compilation working but I have one last problem.
>
> I can't seem to get fpc to drive the linker to search the SDK path
> BEFORE the default paths. Specifically, i386-darwin-ld finds
>
>  /usr/lib/crt1.o
>
> and NOT
>
>  /opt/MacOSX10.5.sdk/usr/lib/crt1.o
>
> despite fpc being passed the option
>
>  -k-L/opt/MacOSX10.5.sdk/usr/lib

Use -XR/opt/MacOSX10.5.sdk/ and get rid of the -k parameter.


Jonas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Cross Compiling from Linux to a Mac OS X 10.5 or 10.6 target. How? [SOLVED]

Causal Lists
In reply to this post by bruce
I finally managed to get Intel Mac OS X cross-compilation (from Linux)
working well so I thought I'd document what I did for the benefit of
others because the info in the wiki is wildly out of date.

I'll update the wiki (if I can) to point to this message.

What you'll need:

[1] an Intel Mac running Leopard or Snow Leopard
[2] the original or retail OSX DVD (for the SDK)
[3] a working linux setup (Debian Squeeze in my case)
[4] up to date source for FPC (2.4.x) and Lazarus (0.9.30)
[5] the Open Darwin cctools (odcctools)

Once set up, you won't need the Mac to compile your code.

STEP 1: copy the SDK from your Mac.

You need to install XCode from your OSX DVD if you've not already done
so and copy the SDK to an appropriate location on your Linux box. I'd
recommend MacOSX10.5.sdk but it depends on how far back you want to be
compatible. MacOSX10.5.sdk is located in /Developer/SDKs on the Mac.

I put mine at /opt/MacOSX10.5.sdk on my Debian box.

STEP 2: grab odcctools from SVN (I use mercurial, hence the "hg" stuff)

hg clone http://svn.macosforge.org/repository/odcctools/trunk/ odcctools

and build it as

$ cd ~/hg/odcctools && ./extract.sh && cd odcctools
$ CC=gcc-4.4 ./configure --target=i386-darwin \
  --prefix=/opt/odcctools --with-sysroot=/opt/MacOSX10.5.sdk
$ make && make install

I've specified gcc 4.4 but it should be okay with other versions.

STEP 3: rebuild FPC (my sources are in ~/hg/pascal)

$ cd ~/hg/pascal && hg id -bint
  730fd5ffbeb1 16666 fixes_2_4 release_2_4_2
$ make distclean && FPC=ppc386 make crossall crossinstall \
  CPU_TARGET=i386 OS_TARGET=darwin \
  CROSSBINDIR=/opt/odcctools/bin BINUTILSPREFIX=i386-darwin- \
  INSTALL_PREFIX=/opt/cross \
  OPT="-gl -gw -godwarfsets -XX -CX -Xd -Fl/opt/MacOSX10.5.sdk/usr/lib"

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

STEP 4: add a darwin (cross-compile) clause to /etc/fpc.cfg

#IFDEF darwin
-Fu/opt/cross/lib/fpc/$fpcversion/units/i386-darwin/
-Fu/opt/cross/lib/fpc/$fpcversion/units/i386-darwin/*
-Fu/opt/cross/lib/fpc/$fpcversion/units/i386-darwin/rtl
-FD/opt/odcctools/bin
#ENDIF

STEP 5: build the Carbon LCL (in Lazarus)

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 Mac OS X.

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

First, be sure to specify the -gw in your projects to avoid problems
reported in (the unfixable) FPC bug #12001.

Second, be sure to specify the -XR option pointing to your SDK root, in
my case -XR/opt/MacOSX10.5.sdk, or the Darwin linker will try to link to
the wrong startup object (/usr/lib/crt1.o).

I hope this information saves the next person to try to set this up a
lot of time :-)

Cheers, Bruce.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Cross Compiling from Linux to a Mac OS X 10.5 or 10.6 target. How? [SOLVED]

Reinier Olislagers
On 6-8-2011 15:28, Causal Lists wrote:
> I finally managed to get Intel Mac OS X cross-compilation (from Linux)
> working well so I thought I'd document what I did for the benefit of
> others because the info in the wiki is wildly out of date.
>
> I'll update the wiki (if I can) to point to this message.
>
<snip>
> Cheers, Bruce.

Bruce,

Thanks for your post. I've taken the liberty to start the wiki page as
I'm trying it out.

See
http://wiki.lazarus.freepascal.org/Cross_compiling_OSX_on_Linux

Regards,
Reinier
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Cross Compiling from Linux to a Mac OS X 10.5 or 10.6 target. How? [SOLVED]

bruce
Brilliant, thanks Reinier, it looks good. Cheers, Bruce.

On 08/08/11 23:03, Reinier Olislagers wrote:

> On 6-8-2011 15:28, Causal Lists wrote:
>> I finally managed to get Intel Mac OS X cross-compilation (from Linux)
>> working well so I thought I'd document what I did for the benefit of
>> others because the info in the wiki is wildly out of date.
>>
>> I'll update the wiki (if I can) to point to this message.
>>
> <snip>
>> Cheers, Bruce.
>
> Bruce,
>
> Thanks for your post. I've taken the liberty to start the wiki page as
> I'm trying it out.
>
> See
> http://wiki.lazarus.freepascal.org/Cross_compiling_OSX_on_Linux
>
> Regards,
> Reinier
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Cross Compiling from Linux to a Mac OS X 10.5 or 10.6 target. How? [SOLVED]

Reinier Olislagers
My pleasure - though I haven't finished yet & may run into things.

It seems you're setting up a 32 bit environment. Both my Linux (Debian)
and OSX machine are 64 bit - don't know if this will work.

Anyway, I'll get back on the list if I have problems...

Reinier
On 9-8-2011 10:28, Bruce Tulloch wrote:
> Brilliant, thanks Reinier, it looks good. Cheers, Bruce.
>
> On 08/08/11 23:03, Reinier Olislagers wrote:
>> http://wiki.lazarus.freepascal.org/Cross_compiling_OSX_on_Linux
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Cross Compiling from Linux to a Mac OS X 10.5 or 10.6 target. How? [SOLVED]

Torsten Bonde Christiansen-2
On 2011-08-09 10:46, Reinier Olislagers wrote:
> My pleasure - though I haven't finished yet&  may run into things.
>
> It seems you're setting up a 32 bit environment. Both my Linux (Debian)
> and OSX machine are 64 bit - don't know if this will work.
I've just tried to follow the guide, but seem to run into the same
problem as many other apparently also do:

At global scope:
cc1plus: warning: unrecognized command line option "-Wno-long-doubl

 From what I can read on the web this is somehow related to 64-bit vs.
32-bit crosscompile, but I'm not sure how to solve it.

The following resources are an interesting read, but didn't really seem
to get me any further.
http://code.google.com/p/iphone-dev/issues/detail?id=212#makechanges
http://code.google.com/p/iphone-dev/issues/detail?id=14

Neither of the CFLAGS/LDFLAGS options helped me, perhaps someone have
done this succesfully on a Ubuntu 10.04 x86_64 like my system.

Kind regards,
Torsten Bonde Christiansen
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Cross Compiling from Linux to a Mac OS X 10.5 or 10.6 target. How? [SOLVED]

Reinier Olislagers
On 9-8-2011 12:21, Torsten Bonde Christiansen wrote:

> On 2011-08-09 10:46, Reinier Olislagers wrote:
>> My pleasure - though I haven't finished yet&  may run into things.
>>
>> It seems you're setting up a 32 bit environment. Both my Linux (Debian)
>> and OSX machine are 64 bit - don't know if this will work.
> I've just tried to follow the guide, but seem to run into the same
> problem as many other apparently also do:
>
> At global scope:
> cc1plus: warning: unrecognized command line option "-Wno-long-doubl
>
> From what I can read on the web this is somehow related to 64-bit vs.
> 32-bit crosscompile, but I'm not sure how to solve it.
>
> The following resources are an interesting read, but didn't really seem
> to get me any further.
> http://code.google.com/p/iphone-dev/issues/detail?id=212#makechanges
> http://code.google.com/p/iphone-dev/issues/detail?id=14
>
> Neither of the CFLAGS/LDFLAGS options helped me, perhaps someone have
> done this succesfully on a Ubuntu 10.04 x86_64 like my system.
>
I've put this on the wiki, don't know if it helps
On 64 bit Linux environments, fpc mailing list users have problems.
Perhaps this
[http://stackoverflow.com/questions/3024255/building-odcctools-in-a-64-bit-os
StackOverflow question and answer] can help: in the configure step,
you'd apparently need to set
CC="gcc -m32" CXX="g++ -m32" ./configure blah blah blah
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Cross Compiling from Linux to a Mac OS X 10.5 or 10.6 target. How? [SOLVED]

bruce
In reply to this post by Reinier Olislagers
Indeed. I have retained a 32 bit system for my main development host for
the time being due to issues such as this (not that I knew of this
particular problem). I'll be interested to see what solutions you find
work as I do plan to migrate to 64 bits soon. Good to know what I'm up
against. FWIW, the cross-compiled bundle generated by my new setup does
appear to run okay on a 64-bit Mac -b

On 08/09/11 18:46, Reinier Olislagers wrote:

> My pleasure - though I haven't finished yet & may run into things.
>
> It seems you're setting up a 32 bit environment. Both my Linux (Debian)
> and OSX machine are 64 bit - don't know if this will work.
>
> Anyway, I'll get back on the list if I have problems...
>
> Reinier
> On 9-8-2011 10:28, Bruce Tulloch wrote:
>> Brilliant, thanks Reinier, it looks good. Cheers, Bruce.
>>
>> On 08/08/11 23:03, Reinier Olislagers wrote:
>>> http://wiki.lazarus.freepascal.org/Cross_compiling_OSX_on_Linux
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Cross Compiling from Linux to a Mac OS X 10.5 or 10.6 target. How? [SOLVED]

Torsten Bonde Christiansen-2
In reply to this post by Reinier Olislagers
On 2011-08-09 12:59, Reinier Olislagers wrote:

> On 9-8-2011 12:21, Torsten Bonde Christiansen wrote:
>> On 2011-08-09 10:46, Reinier Olislagers wrote:
>>> My pleasure - though I haven't finished yet&   may run into things.
>>>
>>> It seems you're setting up a 32 bit environment. Both my Linux (Debian)
>>> and OSX machine are 64 bit - don't know if this will work.
>> I've just tried to follow the guide, but seem to run into the same
>> problem as many other apparently also do:
>>
>> At global scope:
>> cc1plus: warning: unrecognized command line option "-Wno-long-doubl
>>
>>  From what I can read on the web this is somehow related to 64-bit vs.
>> 32-bit crosscompile, but I'm not sure how to solve it.
>>
>> The following resources are an interesting read, but didn't really seem
>> to get me any further.
>> http://code.google.com/p/iphone-dev/issues/detail?id=212#makechanges
>> http://code.google.com/p/iphone-dev/issues/detail?id=14
>>
>> Neither of the CFLAGS/LDFLAGS options helped me, perhaps someone have
>> done this succesfully on a Ubuntu 10.04 x86_64 like my system.
>>
> I've put this on the wiki, don't know if it helps
> On 64 bit Linux environments, fpc mailing list users have problems.
> Perhaps this
> [http://stackoverflow.com/questions/3024255/building-odcctools-in-a-64-bit-os
> StackOverflow question and answer] can help: in the configure step,
> you'd apparently need to set
> CC="gcc -m32" CXX="g++ -m32" ./configure blah blah blah
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
You may also put a note that there exists a launchpad ppa for ubuntu,
then you don't need to compile the binutils yourself (which evidently
can be a pain in the ...).

https://launchpad.net/~flosoft/+archive/cross-apple 
<https://launchpad.net/%7Eflosoft/+archive/cross-apple>

Btw. I got the compilation working on a Ubuntu 11.04 64-bit (within a
VM), but since my main desktop still runs 10.04 I cannot use the ppa.

Kind regards,
Torsten Bonde Christiansen.




_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Cross Compiling from Linux to a Mac OS X 10.5 or 10.6 target. How? [SOLVED]

Reinier Olislagers
On 9-8-2011 14:29, Torsten Bonde Christiansen wrote:

> On 2011-08-09 12:59, Reinier Olislagers wrote:
>> On 9-8-2011 12:21, Torsten Bonde Christiansen wrote:
>>> On 2011-08-09 10:46, Reinier Olislagers wrote:
>> I've put this on the wiki, don't know if it helps
>> On 64 bit Linux environments, fpc mailing list users have problems.
>> Perhaps this
>> [http://stackoverflow.com/questions/3024255/building-odcctools-in-a-64-bit-os
>>
>> StackOverflow question and answer] can help: in the configure step,
>> you'd apparently need to set
>> CC="gcc -m32" CXX="g++ -m32" ./configure blah blah blah
> You may also put a note that there exists a launchpad ppa for ubuntu,
> then you don't need to compile the binutils yourself (which evidently
> can be a pain in the ...).
>
> https://launchpad.net/~flosoft/+archive/cross-apple
> <https://launchpad.net/%7Eflosoft/+archive/cross-apple>
>
> Btw. I got the compilation working on a Ubuntu 11.04 64-bit (within a
> VM), but since my main desktop still runs 10.04 I cannot use the ppa.
>
Thanks for the hints, but feel free to write it up yourself; I use
Debian, not Ubuntu & haven't tried it...

Regards,
Reinier
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal