Tuesday, September 6, 2011

Boost and SOIL in Xcode

Well I have been trying to get this working for quite some time, and I finally got it. I first could only get g++ via make to compile it, but soon found out how to get Xcode to compile it.

BOOST
This one was the hardest, mainly because you have to install it instead of just dragging it into the project. To install it (on mac) you can either use "MacPorts" via "sudo port install boost" or my terminal method. It's up to you wich method you pick. My terminal method I came up with is:

#!/bin/bash/


#BOOST INSTALL

clear

echo "### INSTALLING -> BOOST ###"

echo "---This part will take a while, and needs user participation"


cd ~/Downloads/

#see if the file is there to begin with, if it is skip the download part

if [ ! -d "boost_1_47_0" ]; then

echo "---A web browser will open up a website for you to download a"

echo "zip containing BOOST."

echo "---Please let it download to ~/Downloads/"

echo "---When the download has finished come back to this terminal for"

echo "--- further instructions."

echo "---Please press the enter button to commence..."

read

open "http://prdownloads.sourceforge.net/boost/boost_1_47_0.tar.gz"

echo "---Press the enter key when the download is"

echo "--- finished and when you are ready to proceed"

#wait for the user

read

#see if the file is there

if [ -f "boost_1_47_0.tar.gz" ]; then

echo "---Got the file, now continuing"

else

echo "---Could not find the file!"

exit

fi

tar -zxvf "boost_1_47_0.tar.gz"

else

echo "---You already have the tar.gz archive unzipped. Skipping the download"

fi

cd "boost_1_47_0"

echo "---I also need to use your password to install the library"

sudo chmod u+x bootstrap.sh

sudo chmod u+x ./tools/build/v2/engine/build.sh

echo "---Thank you"

echo "---This will take a while..."

sudo ./bootstrap.sh

#echo "---THIS WILL ALSO TAKE A LOOOOONG TIME..."

#sudo ./b2

echo "---ALMOST THERE..."

sudo ./bjam architecture=combined


echo "---DONE WITH INSTALLING BOOST!"

echo "...press enter to continue on with your life..."

read

clear

#END BOOST INSTALL



The terminal code is not the best in the world, but it does its job. And quite nicely. Well now comes part two, which changes if you decide to use g++/make or Xcode. In g++, you have to specify the libraries you are going to compile with, those commands are: -lboost_filesystem -lboost_system. The full makefile should look similar to:

CC = g++

CFLAGS = -Wall

PROG = game


SRCS := $(patsubst %.cpp,%.o,$(wildcard *.c*))

SRCS += $(patsubst %.cpp,%.o,$(wildcard */*.c*))

SRCS += $(patsubst %.cpp,%.o,$(wildcard */*/*.c*))

SRCS += $(patsubst %.cpp,%.o,$(wildcard */*/*/*.c*))


COMPILE = $(CC) $(CFLAGS) -c


ifeq ($(shell uname),Darwin)

LIBS = -framework OpenGL -framework GLUT -framework CoreFoundation

else

LIBS = -lglut

endif


all: $(PROG)


$(PROG): $(SRCS)

$(CC) $(CFLAGS) -lboost_filesystem -lboost_system -o $(PROG) $(SRCS) $(LIBS)


clean:

rm -f $(PROG)

rm -f *.o

rm -f */*.o

rm -f */*/*.o

rm -f */*/*/*.o


%.o: %.cpp

$(COMPILE) -o $@ $<

You might have noticed that I also added in -framework CoreFoundation. This framework is for SOIL (Simple Opengl Image Library).

To get Xcode to compile (in Xcode 4), you first need to include all the frameworks you use in your project. You probably have to include system none the less. To do this, in the "project navigator" (this is the left bar where all the files are) select the project title, this should be at the very top. Select the first item under project and use the filters: "All" and "Levels" under "Build Settings". Scroll down to "Search Paths" and under "User Header Search Paths" include "/usr/include/" (with the quotes). If nothing is there just put in "/usr/include" (with the quotes).
To add all the frameworks, select the first item under "Targets". Go to "Build Phases"->"Link binary with binaries". Click the plus and search for the framework you want.

SOIL does not need anything special to compile in Xcode, just do not include the "origional" folder. Soil will have quite a bit of warnings, but it should compile.

No comments: