Compiling On Mac OSX

Building Irrlicht examples in Xcode on OSX Mountain Lion

This has been tested on

  • XCode 4.5.2, Irrlicht 1.7.3, OSX Mountain Lion 10.8.2
  • XCode 4.6, Irrlicht 1.8, OSX Mountain Lion 10.8.2
  1. Select the libIrrlicht.a target
  2. Select "Build Settings"
  3. Change "Architectures" to "Standard (32/64-bit Intel)"
  4. Change "Build Active Architecture Only" to "Yes"
  5. Change "Compiler for C/C++/Objective-C" to "LLVM GCC 4.2"

Select the libIrrlicht scheme and build. It should build without errors. Now for the demo targets...

  1. Select all targets from "01.HelloWorld" down to "GUIEditor"
  2. Select "Build Settings"
  3. Change "Architectures" to "Standard (32/64-bit Intel)"
  4. Change "Build Active Architecture Only" to "Yes"

You can now select each scheme and build them individually. Some of the demos don't seem to work well - but the majority work fine.

Note, that at the time of writing the first demo doesn't seem to work properly unless you change: video::EDT_SOFTWARE to video::EDT_OPENGL

Building Irrlicht examples in earlier versions of OSX/XCode

As of irrLicht 1.5, on my mac OS X 10.5.6 machine, everything built fine out-of-the-box using the provided Xcode project.

This is broken under Mac OS X 10.5. You can build applications but they do not execute. There may be a hack to get around this.

Simple hack:

replace in example source code this to lines in main() function

	char i;
	std::cin >> i;

with

	char i = 'c';
	//std::cin >> i;  //<--- this is cause the hang, in some examples such line occurs more than once and you need to fix them all.

Building in the command line

Under Mac OS X 10.5, a problem arises while linking any of the examples on the command line (04.Movement in this case):

~/Downloads/irrlicht/examples/04.Movement $> make
g++ -I../../include -I/usr/X11R6/include -O3 -ffast-math main.cpp -o ../../bin/Linux/04.Movement -L/usr/X11R6/lib -L../../lib/Linux -lIrrlicht -lGL -lXxf86vm -lXext -lX11
ld: cycle in dylib re-exports with /usr/X11R6/lib/libGL.dylib
collect2: ld returned 1 exit status
make: *** [all_linux] Error 1

This error and its solution are described in Apple's developer article: http://developer.apple.com/qa/qa2007/qa1567.html

You must add to the LDFLAGS used in linking:

LDFLAGS += -dylib_file \
/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:\
/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib \
-framework Cocoa -framework OpenGL -framework Carbon -framework IOKit

You'll notice the last line. This is required because libIrrlicht.a was built against the Cocoa, Carbon, and OpenGL frameworks. If you don't add this then you will end up with a slew of undefined symbols.

Also, you need to make sure the Makefile in question is linking against the library that you installed, and not the one that it will automatically choose.

This still yields warnings from ld, but the examples will build. There is also something strange about relative paths in the media loading calls.

More generally, assuming that you've installed the includes in /usr/include/irrlicht and the library is in /usr/lib then you can compile a program main.cpp with:

g++ main.cpp -I/usr/include/irrlicht -I/usr/X11R6/include -O3 -ffast-math -L/usr/local/include -L/usr/X11R6/lib -lIrrlicht -lGL -lXxf86vm -lXext -lX11 -dylib_file /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib -framework Cocoa -framework OpenGL -framework IOKit -framework Carbon

X11 windowing

Building in the command line

Under Mac OS X 10.5 you must still add to the LDFLAGS used in linking:

LDFLAGS += -dylib_file \
/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:\
/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib \