Difference between revisions of "Cross Compiling"

From GNUstepWiki
Jump to navigation Jump to search
 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== Cross Compiling and GNUstep ==
+
Cross Compiling and GNUstep depends on what you want to achieve.
  
depends on what you want to achieve.
+
The following is based on [http://groups.google.com/group/gnu.gnustep.discuss/browse_frm/thread/06920400aed740d2 this discussion] on the mailing list.
  
The following is based on this discussion [[http://groups.google.de/group/gnu.gnustep.discuss/browse_frm/thread/06920400aed740d2#]]
+
See also: [[Writing_portable_code]]
  
=== I have a GNUstep source running on Linux/GNUstep and want the same application to run on OSX ===
+
== 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.  
+
You have several options - more or less complex.
  
a) Copy source files to OSX  
+
=== Copy source files to OSX and use gnustep-make ===
 +
 
 +
The simplest, and best option is obviously to install [[Media:FOSDEM2007Make-2.0.pdf|gnustep-make]] on your Mac.
 +
 
 +
  curl ftp://ftp.gnustep.org/pub/gnustep/core/gnustep-make-2.0.5.tar.gz
 +
  ./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. :-)
 +
--N. Pero
 +
 
 +
 
 +
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 (its additions) onto what Cocoa already provides.
 +
--Markus Hitter
 +
 
 +
=== Copy source files to OSX to develop, build and debug using Xcode ===
  
 
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.
 
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.
 
You can share the sources e.g. through SVN.
 
There is no problem having GNUmakefiles and some .xcodeproj in the same source code directory.  
 
There is no problem having GNUmakefiles and some .xcodeproj in the same source code directory.  
 +
The main benefit of this approach is that you can use the Xcode/gdb integration for debugging.
  
Examples:
+
Examples using this approach:
 
1. SWK Browser from the GNUstep SWK project, DataBuilder from  
 
1. SWK Browser from the GNUstep SWK project, DataBuilder from  
 
2. GSCoreData (look into the sources at www.gna.org)  
 
2. 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.
+
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 only thing to keep in mind is that you must 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 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).  
+
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.
+
=== Install GNUstep on OSX using MacPorts ===
  
 
Then, you can set up an identical build environment on both machines.  
 
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.  
 
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  
+
Benoit Astruc writes:        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.
 +
 
 +
=== Real cross-compiling (building on Linux for MacOS X) ===
  
 
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.  
 
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.
 
So I would not consider this as a reasonable option.
  
=== I have an Xcode project and want to run on Linux ===
+
== I have an Xcode project and want to run on Linux ==
  
 
a) your target machine has a compiler  
 
a) your target machine has a compiler  
Line 45: Line 92:
 
a full Linux machine or a OSX machine (but it is more difficult to get  
 
a full Linux machine or a OSX machine (but it is more difficult to get  
 
a working cross-compiler running on OSX).
 
a working cross-compiler running on OSX).
 +
 +
== I have an Xcode project and want to run on Windows ==
 +
 +
Please refer to [http://www.gnustep.org/experience/Windows.html]

Latest revision as of 12:11, 30 January 2009

Cross Compiling and GNUstep depends on what you want to achieve.

The following is based on this discussion on the mailing list.

See also: Writing_portable_code

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.

Copy source files to OSX and use gnustep-make

The simplest, and best option is obviously to install gnustep-make on your Mac.

 curl ftp://ftp.gnustep.org/pub/gnustep/core/gnustep-make-2.0.5.tar.gz
 ./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. :-) --N. Pero


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 (its additions) onto what Cocoa already provides. --Markus Hitter

Copy source files to OSX to develop, build and debug using Xcode

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. The main benefit of this approach is that you can use the Xcode/gdb integration for debugging.

Examples using this approach: 1. SWK Browser from the GNUstep SWK project, DataBuilder from 2. 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 must 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).

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.

Benoit Astruc writes: 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.

Real cross-compiling (building on Linux for MacOS X)

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.

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 have an Xcode project and want to run on Windows

Please refer to [1]