Using CodeBlocks on a Mac

I use Code::Blocks on the Mac and wanted to be able to use it to compile an OpenFrameworks project. I hate using Xcode and the more recent version of Code::Blocks for Mac works pretty well.

I saw a few people asking how to make this work so I thought I’d share how I got the following configuration to compile:
Mac OSX 10.7.5
Xcode 4.6.3
CodeBlocks 12.11 SP1 (the About page shows the date Dec 27, 2012)
OpenFramework 0.8.0 (I downloaded the Mac OSX Xcode version).

All I’ve tested was getting the GraphicsExample to compile and run in Debug mode. Hopefully, this solution will be more generally helpful. The only limitation is that the Xcode version of OF is only compiled for 32-bit architectures. I’m not sure why OF has that limitation.

Step 1) Using Xcode, compile the OpenFrameworks libraries
Follow the instructions here: http://www.openframeworks.cc/setup/xcode/
I didn’t want to try and compile the OF libraries using C::B.

Step 2) Create the .cbp Code::Blocks project file.
Put the .cbp file in the directory with the example you want to compile.
For the GraphicsExample, I created the file $(OF_DIRECTORY)/examples/graphics/graphicsExample/GraphicsExample.cbp with the following contents:

  
  
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>  
<CodeBlocks_project_file>  
	<FileVersion major="1" minor="6" />  
	<Project>  
		<Option title="GraphicsExample" />  
		<Option pch_mode="2" />  
		<Option compiler="gcc" />  
		<Build>  
			<Target title="Debug">  
				<Option output="bin/Debug/GraphicsExample" prefix_auto="1" extension_auto="1" />  
				<Option object_output="obj/Debug/" />  
				<Option type="1" />  
				<Option compiler="gcc" />  
				<Compiler>  
					<Add option="-g" />  
				</Compiler>  
				<Linker>  
					<Add option="-m32 -framework Accelerate -framework QTKit -framework GLUT /Users/jimsalem/Documents/p/of_v0.8.0_osx_release/libs/openFrameworksCompiled/lib/osx/openFrameworksDebug.a -framework AGL -framework ApplicationServices -framework AudioToolbox -framework Carbon -framework CoreAudio -framework CoreFoundation -framework CoreServices -framework OpenGL -framework QuickTime -framework AppKit -framework Cocoa -framework IOKit -framework CoreVideo" />  
					<Add library="../../../libs/openFrameworksCompiled/lib/osx/openFrameworksDebug.a" />  
					<Add library="../../../libs/fmodex/lib/osx/libfmodex.dylib" />  
					<Add library="../../../libs/glut/lib/osx/GLUT.framework/Versions/A/GLUT" />  
					<Add library="../../../libs/glfw/lib/osx/libglfw3.a" />  
					<Add library="../../../libs/FreeImage/lib/osx/freeimage.a" />  
					<Add library="../../../libs/freetype/lib/osx/freetype.a" />  
					<Add library="../../../libs/glew/lib/osx/glew.a" />  
					<Add library="../../../libs/poco/lib/osx/PocoCrypto.a" />  
					<Add library="../../../libs/poco/lib/osx/PocoData.a" />  
					<Add library="../../../libs/poco/lib/osx/PocoDataODBC.a" />  
					<Add library="../../../libs/poco/lib/osx/PocoDataSQLite.a" />  
					<Add library="../../../libs/poco/lib/osx/PocoFoundation.a" />  
					<Add library="../../../libs/poco/lib/osx/PocoNet.a" />  
					<Add library="../../../libs/poco/lib/osx/PocoNetSSL.a" />  
					<Add library="../../../libs/poco/lib/osx/PocoUtil.a" />  
					<Add library="../../../libs/poco/lib/osx/PocoXML.a" />  
					<Add library="../../../libs/poco/lib/osx/PocoZip.a" />  
					<Add library="../../../libs/rtAudio/lib/osx/rtAudio.a" />  
					<Add library="../../../libs/tess2/lib/osx/tess2.a" />  
					<Add library="../../../libs/cairo/lib/osx/cairo-script-interpreter.a" />  
					<Add library="../../../libs/cairo/lib/osx/cairo.a" />  
					<Add library="../../../libs/cairo/lib/osx/pixman-1.a" />  
					<Add library="../../../libs/openssl/lib/osx/crypto.a" />  
					<Add library="../../../libs/openssl/lib/osx/ssl.a" />  
				</Linker>  
			</Target>  
			<Target title="Release">  
				<Option output="bin/Release/GraphicsExample" prefix_auto="1" extension_auto="1" />  
				<Option object_output="obj/Release/" />  
				<Option type="1" />  
				<Option compiler="gcc" />  
				<Compiler>  
					<Add option="-O2" />  
				</Compiler>  
				<Linker>  
					<Add option="-s" />  
				</Linker>  
			</Target>  
		</Build>  
		<Compiler>  
			<Add option="-Wall" />  
			<Add option="-m32" />  
			<Add directory="../../../addons/" />  
			<Add directory="../../../libs/openFrameworks" />  
			<Add directory="../../../libs/openFrameworks/types" />  
			<Add directory="../../../libs/openFrameworks/events" />  
			<Add directory="../../../libs/openFrameworks/math" />  
			<Add directory="../../../libs/openFrameworks/gl" />  
			<Add directory="../../../libs/openFrameworks/graphics" />  
			<Add directory="../../../libs/openFrameworks/3d" />  
			<Add directory="../../../libs/openFrameworks/app" />  
			<Add directory="../../../libs/openFrameworks/communication" />  
			<Add directory="../../../libs/openFrameworks/video" />  
			<Add directory="../../../libs/openFrameworks/utils" />  
			<Add directory="../../../libs/openFrameworks/sound" />  
			<Add directory="../../../libs/cairo/include/cairo" />  
			<Add directory="../../../libs/fmodex/include" />  
			<Add directory="../../../libs/poco/include" />  
			<Add directory="../../../libs/glew/include" />  
			<Add directory="../../../libs/tess2/include" />  
		</Compiler>  
		<Unit filename="src/main.cpp" />  
		<Unit filename="src/testApp.cpp" />  
		<Unit filename="src/testApp.h" />  
		<Extensions>  
			<code_completion>  
				<search_path add="../../../libs/openFrameworks" />  
				<search_path add="../../../libs/openFrameworks/app" />  
				<search_path add="../../../libs/openFrameworks/communication" />  
				<search_path add="../../../libs/openFrameworks/graphics" />  
				<search_path add="../../../libs/openFrameworks/video" />  
				<search_path add="../../../libs/openFrameworks/utils" />  
				<search_path add="../../../libs/openFrameworks/sound" />  
			</code_completion>  
			<envvars />  
			<debugger />  
		</Extensions>  
	</Project>  
</CodeBlocks_project_file>  
  

Note the -m32 parameter which forces the compiler and linker to compile for 32 bit.

Step 3) Move fmodex.dylib to the executable directory
From the graphicsExample directory run the following command:

  
  
cp ../../../Libs/fmodex/lib/osx/libfmodex.dylib .  
  

Step 4) Run the example

  
  
bin/Debug/GraphicsExample  
  

Hopefully this will be successful for you!

Jim

just want to ask further on this. i have been looking for ways to use code::blocks instead of xcode. i dont mind xcode, BUT, if id like to move my project to say windows or linux, id want to keep it in the same IDE. so code::blocks it is.

but just to ask the very specific steps. or even better still, could you make a screencast. that would help terribly.

though on running it does build of sorts. but does run into a ploblem with the ‘tr1/memory’ not found. but unlike xcode, i dont know how to fix this in codeBlocks.

also with the hack to make this work. would you have to go through all those steps each time for all your projects?

thanks

lewis lepton
smokingbunny.net

in all honesty though, i would prefer if there was a codeBlocks for oF that does not need to do this hack. but its nice to have something. i hope @theo , @zach and the rest of the oF team could look at making a codeblocks for mac version.
there are people who would like to use it, plus it would make multi-platforming projects that much easier.

please oh please