How to build FlightGear cvs on Mac OS X

This document illustrates how to build OS X Bundle (FlightGear.app) with cvs-head on Mac OS 10.4.x/10.5.x with Xcode 3.0 or later

Requirements

System Requirements

  • Mac OS 10.5.x (Leopard) or higher
  • Xcode 3.0 or higher as of Oct-18-2008
  • PPC / Intel Mac
    Faster machine (G5 or Intel) is recommended as FlightGear-cvs with OSG is heavier than 0.9.9 or 0.9.10. Compiling all the files may also take hours in slower G4 machines. FYI, It takes approximately 45 mins to compile everything on MacBook Pro 2.33GHz.

Required Skills

We assume you have some basic knowledge about using:

  • terminal (/Applications/Utilities/Terminal.app) - must
  • Xcode (inlcuding gcc etc)
  • Unix commands

If you are not familiar with the tools above, we highly recommend you consult some web articles and/or books about these before you get started. Please DO NOT ask project members about the use of these tools.

Instruction

Here is the step-by-step instruction of building FlightGear.

Required files

Mac OS X project files contains shell scripts that semi-automatically download all required files so you don't have to find these files. However, required files can be frequently changed so it's good to know where you can get those. Most recent information about required source files are listed here so keep an eye on that page. F.Y.I., This page also shows the required files as of June 17th, 2009.

Preparation

  1. Download and install subversion (only if you don't have one. Leopard has one by default).
  2. Add the following lines to ~/.bashrc (only for those who installed svn from subversion.trigris.org):
    alias svn='LC_ALL=C /usr/local/bin/svn'
    and run:
    $ source ~/.bashrc
  3. Download Xcode project files
  4. run download.sh - fetches everything you need
    • when asked cvs password, type 'guest' or 'cvsguest' as requested.
  5. run patch.sh
  6. patch -N -p0 < patches/alc.patch
    • This will fix the broken OpenAL.framework/Headers/alc.h that causes compilation errors

Compilation

It's easy to build. Use build.sh to build everything from Terminal.app.

You can also manually build these files (if you want). Open and build Xcode projects in this order:

  • OpenSceneGraph/Xcode/OpenSceneGraph/OpenSceneGraph.xcodeproj
    • FlightGear needs only two targets: "osgFrameworks" and "osgPlugins"
  • PLIB/PLIB.xcodeproj
  • SimGear/SimGear.xcodeproj
  • FlightGear/FlightGear.xcodeproj
  • FlightGearOSX/FlightGearOSX.xcodeproj (GUI launcher)

Note

  • "Active Build Configuration" in three OpenSceneGraph related Xcode projects must be set to "Deployment" before pressing the Build button, otherwise the FlightGear Xcode project cannot find OSG frameworks and plugins.
  • Building FlightGearOSX/FlightGearOSX.xcodeproj on PPC Macs causes an error saying there's no i386 arch for Cocoa.framework. This is because your PPC Mac doesn't have universal binary version of Cocoa.framework. Change the "Architecture" configuration on Xcode from 'i386 ppc' to ppc. Since fgfs is compiled as a universal binary, the launcher doesn't have to be a universal binary.

Tips

You might encounter "undefined symbols" when linking. This happens when new files are added into CVS repository but Xcode project file is not updated. In this case, open Xcode for the project and add the files manually. The easiest way to find the files to add is:

  • use grep to find a file that contains the method/function that dyld cannot find.
  • add the file to an appropriate group in Xcode project
    • usually you can find the group by the path to the file
  • check the target of the file
    • usually you can find the target by the path to the file

As this source package (FlightGearOSX/CVS) uses OpenSceneGraph/svn, you may be in trouble with some unexpecting BUS error or Segmentation fault (EXE_BAD_ACCESS or KERN_PROTECTION FAILURE in a crash log). to build more stable FlightGear, you should download OpenSceneGraph as of the same date of the FlightGearMacOSX-DevOSG package. You can download the files at OpenSceneGraph/Producer/OpenThreads nightly tarballs. Download three tar.gz files released on the same date and extract these at FlightGearMacOSX/OpenSceneGraph/. Don't forget to rename folder names to original ones (without version-date postfix ; e.g. mv OpenSceneGraph-1.5.0-200612082325 OpenSceneGraph ). See also FlightGear CVS/OSG build results for some detail information.

Optimizing FlightGear on Intel Macs

There are some compiler flags you can use on Intel Macs. (It's hard to find the common optimization flags for PPC Macs...)

  • PER_ARCH_CCFLAGS_i386 = -mtune=prescott -mfpmath=sse
  • PER_ARCH_CFLAGS_i386 = -mtune=prescott -mfpmath=sse

You can specify these flags from "Project" -> "Edit Project Settings" -> "Customized Options" for Deployment (or one of FlightGear, SimGear, or Release) configuration.

Note

  • Core 2 Duo users can use -mtune=core2 instread of prescott.
    It enables you to use ssse3 extension + 64bit extension. I haven't trid it so give me your feedback. Specifying this flag makes FlightGear run only on Core 2 Duo Macs and Mac Pros so it's better not distribute it.
  • Optimization flags may cause Illegal operation exceptions.
    This is caused by either wrong optimization flags for you CPU or a bug in Mac OS kernel (darwin). If you get this type of error, clear the optimization flag (e.g. -mtune=core2, -mfpmath=sse) and try again.
  • Using -O2, -O3, or -Os with gcc4.0 (comes with Xcode 3.1/3.1.1) causes FlightGear crash. Do not use these optimization flags for FlightGear. edit build.sh and change GCC_OPTIMIZATION_LEVEL to 0 or 1. You can also use gcc 4.2 for enabling full optimization.
  • Using gcc 4.2 on Xcode will give you some compilation errors around ALUT or OpenAL/alc.h. In this case, you need to edit SDK's OpenAL/alc.h and alut.h to change both ALCvoid and ALvoid to void if it is the only argument of a prototype declaration. Moreover, gcc 4.2 doesn't contain SDKs for Mac OS X 10.4. However, specifying SDKROOT=MacOSX10.5.sdk and TARGET_MAC_OSX=10.4 can build a binary for both Tiger and Leopard.
  • Using your own ALUT.framework (if you build FlightGear without using my Xcode project files) might get linker error. In this case, specify linker to link ALUT.framework before OpenAL.framework. This is because Apple's OpenAL.framework contains ALUT implementation so linker complains the duplicated symbols (but no alut.h inside framework).

Have a test flight

Launch FlightGear.app at FlightGearOSX/build/Deployment.

You can also fly without the launcher by running the following command:

$ cd FlightGearOSX/build/Deoployment/Flightgear.app/Contents/Resources
$ ./fgfs.sh

You can change aircraft and airport as you want.

Enjoy!

Author

Tat Nishioka <tat "dot" fgmacosx 'at' gmail "dot" com>

11 Responses to “How to build FlightGear cvs on Mac OS X”

  1. Pooyan Says:
    Got past the first build failure by adding SGMaterialAnimation.cxx/.hxx to the sgmodel target in the SimGear xcode project, now getting another failure when trying to compile main.m in FlightGearOSX; it fails to find included file RubyCocoa/RBRuntime.h This file (RBRuntime.h) doesn't exist on my system, so it appears that RubyCocoa is needed but not installed. I downloaded and installed the RubyCocoa dmg (perhaps download.sh should do this automatically?), but now I'm getting link errors, regarding architectures etc. (I'm building on a G4 by the way.) I can email the errors or post them here, but they're quite long.
  2. Tat Says:
    I guess you're going a bit ahead of my updating the repository :-) I updated the repository a few minutes ago, so you can update your local working copy to the latest revision. RubyCocoa downloader is already included in 0.9.10 package so I updated the one in DevOSG package. The downloader will launch the installer. You can compile FlightGearOSX for ppc only. FlightGearOSX.xcodeproj only compiles the launcher so you can cut off i386 if Xcode coplains about missing i386 arch in Framework or ruby library. Important thing is that you already made a universal binary version of fgfs. Don't care about the architecture of the launcher.
  3. Pooyan Says:
    Minor suggestion: make the download.sh script use compression when doing a CVS or SVN checkout; for example, add a "-z9" flag.
  4. Tat Says:
    Though I don't know if 9 is the best compression level in terms of overall performance, specifying -z option is a good idea. Let me change that later. We can change the level if there's any problem.
  5. Pooyan Says:
    Yep, the build completes on the G4, albeit with i386-related linker warnings. However, the download.sh script fails to check out the flightgear data. ie, simgear source and flightgear source are ok, but flightgear data fails to check out. This is because when we first checkout the macflightgear stuff from subversion, this creates the (empty) directory FlightGearOSX/data. And download.sh then notices that the directory exists, so instead of doing a CVS checkout, it does a CVS update, which fails because there are no CVS control files in that directory. Also, (once the data is put in the right place), running the testfly.sh script results in a runtime error, with fgfs failing doing a vm_allocate(). I haven't yet tried to debug this, I will do so soon.
  6. Tat Says:
    Yeah, I also encountered this CVS update problem -) I'm gonna remove the data folder from svn repository. That should not be there. I haven't tried fgfs-cvs/osg on ppc Macs so I can't help you, but I hope you can solve the problem.
  7. Pooyan Says:
    No luck debugging the runtime error; I tried it again and now it works fine.
  8. Tat Says:
    That's great to hear that you successfully built it. I removed data folder from the svn repository so you can checkout the data for the first time.
  9. nn Says:
    In build FlightGear, in build fgfs can't locate -lsgbucket /usr/bin/ld: warning -L: directory name (/FlightGearMacOSX/flightgear/../SimGear/build/SimGear) does not exist. Set project Framework Search Paths for simgear how?
  10. nn Says:
    setting plib and simgear links fixes that.
  11. iwyxugtf fkzn Says:
    hluv glqbca dyqknwho esralbmvk khvdpousb kvpn zekojlw

Leave a comment

Please DO NOT post a crash log here. it's hard to read and is not worth reading for most of users. Email it to me directly with some additional information including exact FlightFear version, machine spec, and what was you doing when it went crash. Thank you.
Begin the comment with //pukiwiki if you want to write a comment in PukiWiki format.

You must be logged in to post a comment.