Compiling IVAN for Mac OS X Been trying to work on this lately, as running the game in virtualpc is certainly no fun, and the compile seems to die just at the end, so I am hoping we can figure this out!
First of all, here's the output of the configure script (this is on a mac with 10.3, and SDL was installed from source by fink, a package manager)
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking build system type... powerpc-apple-darwin7.9.0
checking host system type... powerpc-apple-darwin7.9.0
checking target system type... powerpc-apple-darwin7.9.0
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking for style of include used by make... GNU
checking dependency style of gcc... none
checking for gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ANSI C... (cached) none needed
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking dependency style of g++... none
checking for sdl-config... /sw/bin/sdl-config
checking for SDL - version >= 1.2.0... yes
checking for a BSD-compatible install... /usr/bin/install -c
checking for ranlib... ranlib
configure: creating ./config.status
config.status: creating Makefile
config.status: creating FeLib/Makefile
config.status: creating FeLib/Include/Makefile
config.status: creating FeLib/Source/Makefile
config.status: creating Script/Makefile
config.status: creating Graphics/Makefile
config.status: creating Main/Makefile
config.status: creating Main/Include/Makefile
config.status: creating Main/Resource/Makefile
config.status: creating Main/Source/Makefile
config.status: executing depfiles commands
The compile dies with this error:
g++ -g -O2 -o ivan actset.o areaset.o charset.o charsset.o command.o
coreset.o dataset.o dungeon.o game.o godset.o iconf.o id.o igraph.o
itemset.o levelset.o main.o materset.o message.o object.o roomset.o
script.o slotset.o trapset.o wmapset.o wskill.o
../..//FeLib/Source/libFeLib.a -L/sw/lib -lSDLmain -lSDL -framework Cocoa -framework OpenGL
ld: Undefined symbols:
_SDL_main
make[2]: *** [ivan] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all-recursive] Error 1
I did some research into the error, and it seems that there's some differences with mac os x and sdl as compared to linux and sdl. Here's what I found:
(from the sdl macintosh faq)
Just like main() is the entry point for C programs (inc. C++,
Objective-C, and Objective-C++), SDL_main() is the main entry point for SDL
programs. However, you don't actually write an SDL_main() function. The
header file "SDL_main.h" remaps your main() function to the SDL_main()
function with a function macro. Your SDL_main() function is called after
the code in SDLMain.m has performed the required "bootstrap"
initializations to support the SDL runtime.
There are three things you have to do:
You must include either SDLMain.m/.h or libSDLmain in your application,
because this is the code that defines SDL's entry point. If you fail to
do this, it is likely that "_main undefined" will be thrown by the
linker.
You must give your main() procedure the following prototype:
int main(int argc, char*argv<>);
You must make sure the file containing your main() procedure #includes
SDL.h.
Otherwise, the macro will not remap main() to SDL_main(), you will get
an undefined _main error, or the bootstrap process will not run, and
SDL will behave strangely or your application will crash or hang.
I also found this little thread in a mailing list:
Jamieson M. Cobleigh wrote:
> I'm trying to port a piece of software from Linux to Apple's OS X
that
> makes use of SDL. When I try to do the final linking:
> g++ custom/lib/DROD.a custom/lib/FrontEndLib.a custom/lib/DRODLib.a
> custom/lib/BackEndLib.a -lmk4 -lz -lexpat -lfmod -lSDL_ttf
-L/sw/lib
> -lSDLmain -lSDL -framework Cocoa -framework OpenGL -o
custom/bin/drod
>
> I get the following:
> ld: Undefined symbols:
> _SDL_main
>
> I installed SDL 1.2.7 using the Fink package manager. I looked at
the
> FAQ for OS X and ensured that the class that defines main
> (DROD/Main.cpp) includes SDL_main.h and SDL.h. The main function
> starts like this:
> int main(int argc, char *argv<>)
> which is the format that the FAQ claims is wanted. I ran gcc -E on
> Main.cpp, and the main method is getting renamed to SDL_main.
>
> Can anyone tell me what the problem is and what I need to do to get
> the program to compile?
>
> Thanks!
>
> Jamie
On some operating systems (OS X but not Linux), SDL defines its own
main() function which calls yours, hence the rename to SDL_main.
When using C++, you've got to declare your main() function like this:
extern "C" int main(int argc, char *argv<>)
{
// Code here
}
Now I am no stranger to compiling but I get lost in C++ quickly. I did some editing to Main.cpp following these suggestions, but always seemed to run into either the same error, or even worse ones, after making clean and recompiling.
I know the devs are very busy with other more important things and none of them have a mac, making this sort of thing nearly impossible to test on their side, but I would very much like to get this to work on mac...so if anyone familiar with the code has any ideas, feel free to let me know and I will try them and see what happens!
oops, that reminds me! hexi did suggest I use this line for configuration:
LDFLAGS='-L/sw/lib' CPPFLAGS='-I/sw/include' ./configure
but I ended up getting the same error. I think it's finding my sdl lib stuff correctly, but ivan's code isn't expecting for SDL to call it's own main() function, so it's not remapping it to SDL_main(). I am sure this is a very simple thing for a more experienced coder to fix....so I hope one reads this post :wink:
lenox- 06-09-2005
With hexi's help, I've been able to get IVAN compiled onto mac. There's a few issues but mostly it runs fine!
I'll whip up a quick guide after I return from my show (wish me luck!).
lenox- 06-11-2005
Ok, so if you've read the sticky in general discussion you'll know that I've come across a few quirks in my build of IVAN on os x.
I'm writing here because my knowledge of c++ and ivan's code is limited so maybe someone might know what to do.
1) The keyboard error, probably just requires an if or case statement in FeLib's whandler.cpp but I am not sure how to remap delete or define that it's been compiled on mac os x. Any clues?
2) The color issue...I tried changing the default fullscreen depth to 32 and 24 bit in FeLib's graphics.cpp but all I did was make it worse, all squashed to the side and with even funkier colors, as if I was forcing the graphics card into the wrong mode, and IVAN was still outputting 16 bit color.
3) The bus error when descending into town or dungeon. This is probably way math-intensive and beyond my realm of understanding... probably a problem with porting it over to a big-endian architecture.
Unless I stumble upon some kind of documentation that could help me further, I'm nearly at the end of my realm of knowledge here. I doubt there's much interest in helping, but if an IVAN dev was willing or patient enough I'd be glad to setup an ssh/vnc connection to my macintosh if it would help them. Who knows, these might be quick fixes for someone who knows the code?
Thanks for your time!
lenox- 07-05-2005
I'm pretty sure it'd be a matter of making the code endian-agnostic when it comes to data paths and color registers...someone's gotta have a better idea than I (?)
calum- 10-16-2005
Just posting again so I can leave some contact details (calumr at mac dot com).
lenox- 11-25-2005
hey, awesome! it's been so long since i've worked on this, i have a few questions...so I am going to email you if you don't mind!
lenox- 11-25-2005
Cool! Using that tip, I was able to descend into a town or dungeon. However, I do think we're going to have to figure this one out, because once I walk around for a bit, or try to go back to the world map, it crashes again, with either 'bus error' or segmentation fault.
Getting closer!
Atomic- 11-27-2005
Go go Lenox power!
unknown_entity- 11-28-2005
*catchy music*
Flying through space and time- It's Lenox!
*flashy time warp effect*
Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.