Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Cross Compiling for OS X?

72 views
Skip to first unread message

TMC

unread,
Apr 29, 2008, 3:40:46 PM4/29/08
to Discuss...@gnu.org

I've been enjoying creating a few simple CLI tools with GNUstep on my Linux
box. Now I'd like to use them on OS X. How can I set up a cross-compiling
environment to build tools for OS X?

Naturally I'm only using Foundation and a few custom frameworks, so I don't
expect any incompatibilities with Cocoa. Also, I don't really need to
compile PPC or Universal binaries; I just want to play with my code on my
Intel Mac. Thus I want to avoid the hassle of setting up a PowerPC
cross-compiler on my x86 Linux. I think this is not an unrealistic goal
because [cross-compiling with distcc][1] is possible.

[1]: http://ranger.befunk.com/fink/darwin-cross/

--Tycho Martin Clendenny
--
View this message in context: http://www.nabble.com/Cross-Compiling-for-OS-X--tp16968633p16968633.html
Sent from the GNUstep - General mailing list archive at Nabble.com.

Markus Hitter

unread,
Apr 29, 2008, 3:57:00 PM4/29/08
to TMC, Discuss...@gnu.org

Am 29.04.2008 um 21:40 schrieb TMC:
> How can I set up a cross-compiling environment to build tools for
> OS X?


Would installing GNUstep on Mac OS X be an option?

If you really want to cross-compile, you'd have to start with
building a cross-compiler toolchain (gcc and friends). If you have
this and simple executables work, use it to compile GNUstep, pretty
much the same as compiling GNUstep natively. Nothing unmanageable,
but loads of work and lots of fun with keeping different toolchains
and library/framework sets apart.


Markus

- - - - - - - - - - - - - - - - - - -
Dipl. Ing. Markus Hitter
http://www.jump-ing.de/


TMC

unread,
May 2, 2008, 6:57:39 PM5/2/08
to Discuss...@gnu.org

I don't see why I should have to install GNUstep on OS X when it already has
a perfectly good Foundation. I'll look into creating a cross-compiling
environment.

--Tycho Martin Clendenny
--
View this message in context: http://www.nabble.com/Cross-Compiling-for-OS-X--tp16968633p17029319.html

h...@computer.org

unread,
May 3, 2008, 2:49:34 AM5/3/08
to
> I don't see why I should have to install GNUstep on OS X when it already has
> a perfectly good Foundation. I'll look into creating a cross-compiling
> environment.

So you have some GNUstep code that you want to run natively on OSX?
And compile on OSX?

Then, your preferred "cross-compiling environment" is called Xcode
(but is in fact a *native* compiling environment).

Just open a new Xcode project for use of a makefile (or a "command
line tool"), drag your Obj-C source files from the GNUstep project
into your Xcode project, add the resources, add the Cocoa
Foundation.framework, update the makefile and do a "build".

-- hns

h...@computer.org

unread,
May 3, 2008, 5:26:27 AM5/3/08
to
After thinking a little and taking into account that essentially the
same question was asked twice this week, I have thought to write some
simple FAQ:

1. I have a GNUstep source running on Linux/GNUstep and want the same
application to run on OSX

You have several options - more or less complex.

a) Copy source files to OSX

Add a wrapping Xcode project (in addition to the GNUstep makefile) and
configure it to compile directly on OSX for OSX using the OSX Cocoa
frameworks. You can share the sources e.g. through SVN. There is no
problem having GNUmakefiles and some .xcodeproj in the same source
code directory.

Examples: SWK Browser from the GNUstep SWK project, DataBuilder from
GSCoreData (look into the sources at www.gna.org)

Development is done by either working on Linux and using GORM/Project
Center and compiling for Linux. or on OSX opening the project in
Xcode. The only thing to keep in mind is that you also update the
Xcode project or the GNUmakefile if you add source files or resources.

The GNUstep .app bundle is different and runs on Linux only. The
OSX .app bundle runs only on OSX, i.e. there is no single bundle that
covers all architectures (unless you do some additional tricks).

b) Install GNUstep on OSX using MacPorts.

Then, you can set up an identical build environment on both machines.

The drawback is that you don't have a "native" OSX application which
you can easily launch by a double-click on the .app icon.

c) Real cross-compiling
This means that you have a gcc version on your Linux machine that
emits executables that run on OSX. Unfortunately, OSX uses MACH-O
binaries and building a cross-compiling gcc is very tricky.

So I would not consider this as a reasonable option.

2. I have an Xcode project and want to run on Linux

a) your target machine has a compiler
Here, you have to check that you are not using too specific
frameworks. Then, add a GNUmakefile. Copy the files to your Linux
system and run the GNUstep makefile.

b) your target machine is an embedded system
In this case, you need a cross-compiler on the build host. This can be
a full Linux machine or a OSX machine (but it is more difficult to get
a working cross-compiler running on OSX).

I hope this helps to clarify things a little. If you have more
comments, hints, tricks&tips, we can move and merge this into the
Wiki.

-- hns

Markus Hitter

unread,
May 3, 2008, 5:56:48 AM5/3/08
to TMC, Discuss...@gnu.org

Am 03.05.2008 um 00:57 schrieb TMC:
>
> I don't see why I should have to install GNUstep on OS X when it
> already has
> a perfectly good Foundation. I'll look into creating a cross-compiling
> environment.

Additionally to the already suggested use of Xcode you can build
GNUstep on OS X with the apple-apple-apple combo. While this might
need a tweak or two to work, this gives you a thin layer of GNUstep
(it's additions) onto what Cocoa already provides.

David Chisnall

unread,
May 3, 2008, 6:16:21 AM5/3/08
to h...@computer.org, discuss...@gnu.org
On 3 May 2008, at 10:26, h...@computer.org wrote:

> c) Real cross-compiling
> This means that you have a gcc version on your Linux machine that
> emits executables that run on OSX. Unfortunately, OSX uses MACH-O
> binaries and building a cross-compiling gcc is very tricky.

I've not tried building Apple GCC on non-Apple platforms, but even if
you do this then you need more to get a real cross-compiling
environment. You also need copies of every header file that your
program includes. You can't substitute GNUstep's Foundation.h for
Apple's, since they have different instance variable layouts so any of
your subclasses of Apple classes will be wrong. This header also
includes other headers which define things like the sizes and layouts
of of C types and so on, These can be acquired from the Darwin
sources, but you'll still need the framework headers which are not
publicly redistributable. In short, cross compiling is hard, which is
why hardly anyone does it.

Improving GNUstep Make to build native OS X applications (it already
works nicely for frameworks) would be a better approach, but I'm not
sure how much effort this would be. Building OS X apps from a
makefile isn't very hard, although fat binaries are slightly harder,
so it might be worth investigating.

David


Andreas Höschler

unread,
May 3, 2008, 7:21:56 AM5/3/08
to discuss...@gnu.org
Hi all,

> Improving GNUstep Make to build native OS X applications (it already
> works nicely for frameworks) would be a better approach, but I'm not
> sure how much effort this would be. Building OS X apps from a
> makefile isn't very hard, although fat binaries are slightly harder,
> so it might be worth investigating.


I would be pretty much interested in a gnustep make makefile that
generates an OSX application bundle. However, for now the "Add new
files to XCode and GNUmakefile approach" works well enough for me. I
am just through the process of figuring out how to setup XCode to
build frameworks and applications like I am used to from
ProjectBuilder. If anybody is struggling with the same problem, read on:

Problem: Source code for a bunch of frameworks and a bunch of
applications and tools requiring these frameworks. The makefiles have
been created with ProjectBuilderWO.app. There was a tool that
generated gnustep makefiles from the PB.project files. The sources are
lying on an NFS server so they can be reached from MacOSX and Solaris.
On both platforms the frameworks, bundles and tools are built with

cd <project dir>
make install

using gnustep make. Applications had to be built with
ProjectBuilderWO.app on MacOSX since the app bundle generated by
gnustep make did not work correctly on MacOSX. This setup (worked
well for years) was to be migrated from MacOSX 10.2 with
ProjectBuilderWO.app to 10.5 with XCode. XCode has dozens of settings,
some with non-obvious meanings at the first glance. Many defaults need
to be tweaked to get frameworks installed in /Library/Frameworks and
applications installed in /Applications. Here's what I did.

I first created an XCode project (Cocoa framework or Cocoa application
for each of my projects in a temporary directory and copied the
generated files into the real project directories. After opening the
XCode project, adding the files (classes, resources, frameworks) was
simple. The tricky part was to open the "Get Info" panel for the
project and the target - this really has to be done in both places -
and do the following settings for a framework project:

Deployment Location checked
Installation Build Products Location /
Installation Directory /Library/Frameworks
Strip Linked Product not checked

This installs the frameworks in /Library/Frameworks where I usually
expect them to be, not in /Build/Release/Frameworks, /home/ahoesch/
Library/Frameworks,... I don't know whether all of these settings are
required, but it works for me this way.

By the way, I found Parallels to be an extremely useful product
(MacOSX application) for GNUsteppers. It allowed me to install Solaris
10 x86 (and thus GNUstep) in a virtual machine on my PowerBook, so I
can carry around a full featured MacOSX/GNUstep development
environment with me now. The performance is pretty convincing.

Regards,

Andreas

Blake Nicholson

unread,
May 3, 2008, 9:25:24 PM5/3/08
to David Chisnall, discuss...@gnu.org, h...@computer.org

On May 3, 2008, at 6:16 AM, David Chisnall wrote:

> On 3 May 2008, at 10:26, h...@computer.org wrote:
>

>> c) Real cross-compiling
>> This means that you have a gcc version on your Linux machine that
>> emits executables that run on OSX. Unfortunately, OSX uses MACH-O
>> binaries and building a cross-compiling gcc is very tricky.
>

> I've not tried building Apple GCC on non-Apple platforms, but even
> if you do this then you need more to get a real cross-compiling
> environment. You also need copies of every header file that your
> program includes. You can't substitute GNUstep's Foundation.h for
> Apple's, since they have different instance variable layouts so any
> of your subclasses of Apple classes will be wrong. This header also
> includes other headers which define things like the sizes and
> layouts of of C types and so on, These can be acquired from the
> Darwin sources, but you'll still need the framework headers which
> are not publicly redistributable. In short, cross compiling is
> hard, which is why hardly anyone does it.
>

> Improving GNUstep Make to build native OS X applications (it already
> works nicely for frameworks) would be a better approach, but I'm not
> sure how much effort this would be. Building OS X apps from a
> makefile isn't very hard, although fat binaries are slightly harder,
> so it might be worth investigating.
>

David, would you mind clarifying your last paragraph a bit? My
reading of your first sentence is that you want to build native OS X
applications via GNUstep Make, but then your second sentence seems to
suggest you're already doing that. For what it's worth, I use GNUstep
make to build native applications on OS X (the app is not a universal
binary). I use the DBModeler application from GDL2 as a native app (I
had to build nibs to replace the gorm files).

I may have completely misunderstood what you're saying, and apologize
if that's the case.


Cheers,
Blake


Blake Nicholson

unread,
May 3, 2008, 10:53:55 PM5/3/08
to Andreas Höschler, discuss...@gnu.org
On May 3, 2008, at 7:21 AM, Andreas Höschler wrote:
>
> I first created an XCode project (Cocoa framework or Cocoa
> application for each of my projects in a temporary directory and
> copied the generated files into the real project directories. After
> opening the XCode project, adding the files (classes, resources,
> frameworks) was simple. The tricky part was to open the "Get Info"
> panel for the project and the target - this really has to be done in
> both places - and do the following settings for a framework project:
>
> Deployment Location checked
> Installation Build Products Location /
> Installation Directory /Library/Frameworks
> Strip Linked Product not checked
>

Andreas,

Setting identical settings for a project and its targets should not be
necessary. I have not specifically set the installation settings you
describe (I install from my GNUstep GNUmakefile), but for other
settings it is not necessary. What I do is put all of my settings
that are common to all targets in the project's settings. By default,
targets inherit the settings from the project. If you need to
customize the settings for a target (for example for a search path),
you can set the first entry to $(inherited) to inherit the settings
from the project (if desired), and then add whatever additional
entries the target requires beyond what is in the project.

Also, if you have some build settings that you'd like to apply across
many projects, you may want to consider build configuration files.
Check out the following document from Apple:

http://developer.apple.com/tools/xcode/xcodebuildsettings.html

I don't know if you've already read through the Xcode User Guide, but
two parts of it that you may find useful are:

Build Settings
http://developer.apple.com/documentation/DeveloperTools/Conceptual/XcodeUserGuide/Contents/Resources/en.lproj/05_04_bs_build_settings/chapter_33_section_1.html
[http://tinyurl.com/3v4ccz]

Build for Release (describes installation)
http://developer.apple.com/documentation/DeveloperTools/Conceptual/XcodeUserGuide/Contents/Resources/en.lproj/05_07_bs_building_product/chapter_35_section_7.html
[http://tinyurl.com/53jklc]

In the case of your installation settings, I believe you'll want to
set those on the Release build configuration of the target associated
with the application or framework you wish to install. Some of the
settings will already be configured in the Release build configuration.

I hope this is helpful.


Blake

Nicolas Roard

unread,
May 4, 2008, 7:30:58 AM5/4/08
to Blake Nicholson, h...@computer.org, discuss...@gnu.org
On Sun, May 4, 2008 at 2:25 AM, Blake Nicholson <bla...@umich.edu> wrote:
> I use the
> DBModeler application from GDL2 as a native app (I had to build nibs to
> replace the gorm files).

Neat, have you planned to send those nibs to gnustep ? I'm sure other
people might be interested by running GDL2 and DBModeler on OSX (and
if you could write a tutorial as well it would be even better :-P )

--
Nicolas Roard


Benoit

unread,
May 3, 2008, 10:57:57 AM5/3/08
to discuss...@gnu.org
Hi all,

> b) Install GNUstep on OSX using MacPorts.
>
> Then, you can set up an identical build environment on both machines.
>
> The drawback is that you don't have a "native" OSX application which
> you can easily launch by a double-click on the .app icon.

I think I have done this :
- I installed GNUstep Make and BaseAdditions on Mac OS X 10.3 (it was
2 years ago so not the Make 2.0 version, I don't know if it works with
the new version),
- I used a GNUmakefile like this one :

----
# This usually happens when you source GNUstep.sh, then run ./configure,
# then log out, then log in again and try to compile
ifeq ($(GNUSTEP_MAKEFILES),)
$(error You need to run the GNUstep configuration script before
compiling!)
endif

include $(GNUSTEP_MAKEFILES)/common.make

APP_NAME = WRP

WRP_MAIN_MODEL_FILE = MainMenu
WRP_APPLICATION_ICON = WRP.icns
WRP_PRINCIPAL_CLASS = NSApplication

WRP_RESOURCE_FILES = gui/* Images/* Resources/*

WRP_OBJC_FILES = main.m \
...
snip a bunch of sources files
...
DEGeneralPrefsController.m \
GSStringCat.m

include GNUmakefile.preamble
include $(GNUSTEP_MAKEFILES)/application.make
----

- there was a trick however, the first time I had to write manually
some file, WRPInfo.plist if I remember well, and then it was used.

I don't do anything on this app since 2 years ago so I don't remember
well, but I am pretty sure I had nothing more to do. And the result was
a perfectly Mac OS X app build with GNUstep make.


Benoit Astruc


Tim McIntosh

unread,
May 4, 2008, 12:34:18 PM5/4/08
to Discuss-gnustep GNUstep

I'll add them to this package if I can get a copy (already directly e-
mailed Blake about this): http://hoth.radiofreeomaha.net:3000/~tmcintos/GNUstepWeb/

I had planned to create the NIBs myself but had not found the time to
do it. I already created an Xcode project that builds a universal
binary.

-Tim

Blake Nicholson

unread,
May 4, 2008, 12:34:35 PM5/4/08
to Nicolas Roard, h...@computer.org, discuss...@gnu.org
Hi Nicolas,

I'd be happy to contribute the nibs to gnustep. They are currently
NIB 3.x bundles, but I'll switch them to NIB 2.x for people that
aren't using Leopard. I'll assemble my modifications and send them
off to David Ayers and Matt Rice to add to the GDL2 repository.

I think it may be a bit premature to write a tutorial for DBModeler
just yet. I primarily use DBModeler for SQL and Objective-C
generation (I wrote a very basic Objective-C generator). Right now, I
am not able to use DBModeler to add entities, attributes, etc. It
reads in existing eomodeld files, but I am not able to create a new
model or add to an existing one. I will work on improving DBModeler's
compatibility with OS X. Once the basic functionality is there, I
will write up a tutorial document.

Blake


On May 4, 2008, at 7:30 AM, Nicolas Roard wrote:
> On Sun, May 4, 2008 at 2:25 AM, Blake Nicholson <bla...@umich.edu>
> wrote:
>> I use the
>> DBModeler application from GDL2 as a native app (I had to build
>> nibs to
>> replace the gorm files).
>
> Neat, have you planned to send those nibs to gnustep ? I'm sure other
> people might be interested by running GDL2 and DBModeler on OSX (and
> if you could write a tutorial as well it would be even better :-P )
>

> --
> Nicolas Roard
>
>

Andreas Höschler

unread,
May 5, 2008, 4:22:37 AM5/5/08
to Blake Nicholson, discuss...@gnu.org
Hi Blake,

> Setting identical settings for a project and its targets should not be
> necessary. I have not specifically set the installation settings you
> describe (I install from my GNUstep GNUmakefile),

I tried that! The frameworks built and installed fine, I could even run
an application built with XCode and Debug as the target. But as soon as
I switched to Release I got an error message that the frameworks haven
been built for the wrong platform!? Rather weird! Are you building your
applications (linking to your frameworks) with XCode or with gnustep
make?

> Also, if you have some build settings that you'd like to apply across
> many projects, you may want to consider build configuration files.
> Check out the following document from Apple:
>
> http://developer.apple.com/tools/xcode/xcodebuildsettings.html
>
> I don't know if you've already read through the Xcode User Guide, but
> two parts of it that you may find useful are:
>
> Build Settings
> http://developer.apple.com/documentation/DeveloperTools/Conceptual/
> XcodeUserGuide/Contents/Resources/en.lproj/05_04_bs_build_settings/
> chapter_33_section_1.html
> [http://tinyurl.com/3v4ccz]
>
> Build for Release (describes installation)
> http://developer.apple.com/documentation/DeveloperTools/Conceptual/
> XcodeUserGuide/Contents/Resources/en.lproj/05_07_bs_building_product/
> chapter_35_section_7.html
> [http://tinyurl.com/53jklc]
>
> In the case of your installation settings, I believe you'll want to
> set those on the Release build configuration of the target associated
> with the application or framework you wish to install. Some of the
> settings will already be configured in the Release build > configuration.

Thanks for the links!

Regards,

Andreas

Blake Nicholson

unread,
May 5, 2008, 7:36:03 AM5/5/08
to Andreas Höschler, discuss...@gnu.org

On May 5, 2008, at 4:22 AM, Andreas Höschler wrote:

> Hi Blake,
>
>> Setting identical settings for a project and its targets should not
>> be necessary. I have not specifically set the installation
>> settings you describe (I install from my GNUstep GNUmakefile),
>
> I tried that! The frameworks built and installed fine, I could even
> run an application built with XCode and Debug as the target. But as
> soon as I switched to Release I got an error message that the
> frameworks haven been built for the wrong platform!? Rather weird!
> Are you building your applications (linking to your frameworks) with
> XCode or with gnustep make?
>

Andreas,

The error you get about the wrong platform is due to the fact that by
default the Debug build configuration just builds for the architecture
on which you are compiling, whereas Release will build a universal
binary. If you haven't built all of the frameworks against which your
application links as universal binaries, then you'll get this error.

You have two options:
1) Change your build settings so your Release build configuration does
not build a universal binary.
2) Re-build all of your frameworks as universal binaries so your
application can be built as a universal binary.

For option 1, you need to go to your Project's build settings
(Project ... Edit Project Settings) and switch to the Release
configuration. Update the Architectures setting (it's the first one)
so that it only lists your architecture.

Let me know if any issues come up.


Blake

Nicola Pero

unread,
May 5, 2008, 6:17:37 PM5/5/08
to h...@computer.org, discuss...@gnu.org

On 3 May 2008, at 10:26, h...@computer.org wrote:

> After thinking a little and taking into account that essentially the
> same question was asked twice this week, I have thought to write some
> simple FAQ:
>
> 1. I have a GNUstep source running on Linux/GNUstep and want the same
> application to run on OSX
>
> You have several options - more or less complex.

The simplest, and best option is obviously to install gnustep-make (./
configure; make; sudo
make install) and then compile your project by typing 'make'. You
get a native Apple OSX
application compiled against the Apple OSX ObjC frameworks ... using
the same GNUmakefiles
you were using on GNU/Linux/*BSD/Windows. :-)

If there are issues with this solution, please report them so we can
fix them :-)

Thanks


Nicola Pero

unread,
May 5, 2008, 6:20:14 PM5/5/08
to David Chisnall, discuss...@gnu.org, h...@computer.org

> Improving GNUstep Make to build native OS X applications (it
> already works nicely for frameworks) would be a better approach

This is all already done - gnustep-make is able to build native OS X
applications on OS X - I'm confused - either nobody
tried it out (it's a great feature!), or something is broken.

If something is broken, I'd be grateful if people would report some
details of the problem. ;-)

Thanks


Dr. H. Nikolaus Schaller

unread,
May 6, 2008, 3:21:04 AM5/6/08
to Nicola Pero, discuss...@gnu.org

Am 06.05.2008 um 00:20 schrieb Nicola Pero:

>
>> Improving GNUstep Make to build native OS X applications (it
>> already works nicely for frameworks) would be a better approach
>
> This is all already done - gnustep-make is able to build native OS X
> applications on OS X - I'm confused - either nobody
> tried it out (it's a great feature!), or something is broken.

Well, I would assume a third option: nobody knows it (and hasn't tried
therefore)...

This is the reason why I want to put all info from this thread into a
new Wiki page.


Yen-Ju Chen

unread,
May 6, 2008, 3:56:23 AM5/6/08
to Dr. H. Nikolaus Schaller, discuss...@gnu.org
I used gnustep-make to build OS X application occasionally.
It is quite easy to try and I wonder why people are confused,
probably because they cannot find an application to start.

Yen-Ju

> _______________________________________________
> Discuss-gnustep mailing list
> Discuss...@gnu.org
> http://lists.gnu.org/mailman/listinfo/discuss-gnustep
>


Nicola Pero

unread,
May 6, 2008, 5:05:15 AM5/6/08
to Dr. H. Nikolaus Schaller, discuss...@gnu.org

>> This is all already done - gnustep-make is able to build native OS X
>> applications on OS X - I'm confused - either nobody
>> tried it out (it's a great feature!), or something is broken.
>
> Well, I would assume a third option: nobody knows it (and hasn't tried
> therefore)...
>
> This is the reason why I want to put all info from this thread into a
> new Wiki page.

That would be great! :-)

Thanks


h...@computer.org

unread,
May 9, 2008, 11:18:23 AM5/9/08
to
On 6 Mai, 11:05, "Nicola Pero" <nicola.p...@meta-innovation.com>
wrote:

Here it is: http://wiki.gnustep.org/index.php/Cross_Compiling

Please feel free to fix inaccuracies. It is our Wiki!

-- hns

0 new messages