ivanforum ivanforum
Forum for Iter Vehemens ad Necem
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   fchat fChat   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Compiling IVAN for Mac OS X

 
Post new topic   Reply to topic    ivanforum Forum Index -> Programming
View previous topic :: View next topic  
Author Message
lenox
zombie


Joined: 03 Jun 2005
Posts: 67
Location: suffering in a cave

PostPosted: Thu Jun 09, 2005 2:00 pm    Post subject: Compiling IVAN for Mac OS X Reply with quote

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)

Code:

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:

Code:

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:

Quote:

(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:

Quote:

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:

Code:

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
Back to top
View user's profile Send private message Visit poster's website AIM Address
lenox
zombie


Joined: 03 Jun 2005
Posts: 67
Location: suffering in a cave

PostPosted: Thu Jun 09, 2005 10:38 pm    Post subject: Reply with quote

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!).
Back to top
View user's profile Send private message Visit poster's website AIM Address
lenox
zombie


Joined: 03 Jun 2005
Posts: 67
Location: suffering in a cave

PostPosted: Sun Jun 12, 2005 12:14 am    Post subject: Reply with quote

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!
Back to top
View user's profile Send private message Visit poster's website AIM Address
lenox
zombie


Joined: 03 Jun 2005
Posts: 67
Location: suffering in a cave

PostPosted: Tue Jul 05, 2005 2:32 pm    Post subject: Reply with quote

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 (?)
Back to top
View user's profile Send private message Visit poster's website AIM Address
calum



Joined: 16 Oct 2005
Posts: 1

PostPosted: Sun Oct 16, 2005 4:20 pm    Post subject: Reply with quote

Just posting again so I can leave some contact details (calumr at mac dot com).
Back to top
View user's profile Send private message Visit poster's website
lenox
zombie


Joined: 03 Jun 2005
Posts: 67
Location: suffering in a cave

PostPosted: Fri Nov 25, 2005 6:00 pm    Post subject: Reply with quote

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!
Back to top
View user's profile Send private message Visit poster's website AIM Address
lenox
zombie


Joined: 03 Jun 2005
Posts: 67
Location: suffering in a cave

PostPosted: Sat Nov 26, 2005 1:21 am    Post subject: Reply with quote

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!
Back to top
View user's profile Send private message Visit poster's website AIM Address
Atomic
archangel


Joined: 12 Jan 2005
Posts: 1442
Location: In the fire

PostPosted: Mon Nov 28, 2005 2:23 am    Post subject: Reply with quote

Go go Lenox power!
_________________
"Also, I'm the only person I know capable of a pelvic pary and riposte." -- Squashmonster

I moderate in red.
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
unknown_entity
orc general


Joined: 20 Mar 2005
Posts: 806
Location: In your dreams...

PostPosted: Tue Nov 29, 2005 2:25 am    Post subject: Reply with quote

*catchy music*

Flying through space and time- It's Lenox!

*flashy time warp effect*
_________________
Sponges beat the devil because sponges are badass.~SquashMonster

~Petty Tyrant of the IVAN Forums~
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    ivanforum Forum Index -> Programming All times are GMT


Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group