Trout Wars and TTF

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

Trout Wars and TTF

Postby laymanofsdl » Sun Jul 31, 2005 12:42 pm

So I've been meaning to do the Trout Wars tutorials for a long time. Finally I get round to doing it and everything's ok for a while until, naturally, I hit a snag. Unfortunately it seems that the forums have been updated and anything anyone might have written about Trout Wars has gone:( So I don't know if anyone here has any clue what I'm on about but I'd love some help.

So I'm trying to compile the second tutorial in LXF54. Particularly the fonts part. The first part compiled fine but the second part is coming up with errors I don't understand. Here they are.

Code: Select all
richard@ubuntu:~$ g++ TroutWars.cpp -o TroutWars `sdl-config --libs`
/tmp/ccQmHnPf.o(.text+0x59): In function `CTWGame::CTWGame[not-in-charge]()':
: undefined reference to `TTF_Init'
/tmp/ccQmHnPf.o(.text+0x70): In function `CTWGame::CTWGame[not-in-charge]()':
: undefined reference to `TTF_OpenFont'
/tmp/ccQmHnPf.o(.text+0x7a): In function `CTWGame::CTWGame[not-in-charge]()':
: undefined reference to `TTF_Quit'
/tmp/ccQmHnPf.o(.text+0xdb): In function `CTWGame::CTWGame[not-in-charge]()':
: undefined reference to `TTF_RenderText_Blended'
/tmp/ccQmHnPf.o(.text+0x1cb): In function `CTWGame::CTWGame[in-charge]()':
: undefined reference to `TTF_Init'
/tmp/ccQmHnPf.o(.text+0x1e2): In function `CTWGame::CTWGame[in-charge]()':
: undefined reference to `TTF_OpenFont'
/tmp/ccQmHnPf.o(.text+0x1ec): In function `CTWGame::CTWGame[in-charge]()':
: undefined reference to `TTF_Quit'
/tmp/ccQmHnPf.o(.text+0x24d): In function `CTWGame::CTWGame[in-charge]()':
: undefined reference to `TTF_RenderText_Blended'
/tmp/ccQmHnPf.o(.text+0x319): In function `CTWGame::~CTWGame [not-in-charge]()':: undefined reference to `TTF_CloseFont'
/tmp/ccQmHnPf.o(.text+0x363): In function `CTWGame::~CTWGame [in-charge]()':
: undefined reference to `TTF_CloseFont'
collect2: ld returned 1 exit status
richard@ubuntu:~$


As far as I know I've got all the sdl ttf stuff installed and my code is exactly as it describes it in the mag. I seem to have misplaced the disc that came with the mag so I can't even check this. But I don't think it's the codes fault. I'm stumped. Thanks for any help
laymanofsdl
 
Posts: 2
Joined: Sun Jul 31, 2005 12:31 pm

Postby laymanofsdl » Sun Jul 31, 2005 1:03 pm

I've solved it myself. Wasn't so much of a mystery after all. A quick look in some SDL_ttf.h documentation and i realise that i should be using "$ g++ TroutWars.cpp -o TroutWars `sdl-config --libs` -lSDL_ttf" and not "$ g++ TroutWars.cpp -o TroutWars `sdl-config --libs".

I had another problem but that was just to do with setting up the path to my font correctly. Sorry for taking up forum space for a problem i could solve myself:)
laymanofsdl
 
Posts: 2
Joined: Sun Jul 31, 2005 12:31 pm

Postby mota » Sun Aug 07, 2005 9:12 pm

Glad to meet a fellow procrastinator. Also, I'm glad you "wasted space" with your observations.

I just went throught the first toutorial and was getting segfaults. Googling around I found some references to segfaults in TroutWars, but couldn't find anysolutions (parts of the old forums were still cached).

This was my gdb output:
Code: Select all
(gdb) s
33        while(done==0){
(gdb) s
35          while ( SDL_PollEvent(event)){
(gdb) s

Program received signal SIGSEGV, Segmentation fault.
0x00002aaaaabfe7ea in SDL_PeepEvents () from /usr/lib/libSDL-1.2.so.0
(gdb) s
Single stepping until exit from function SDL_PeepEvents,
which has no line number information.
0x00002aaaaad3cc20 in __pthread_sighandler () from /lib/libpthread.so.0
(gdb) s
Single stepping until exit from function __pthread_sighandler,
which has no line number information.
Fatal signal: Segmentation Fault (SDL Parachute Deployed)

Program exited with code 0365.



I replaced:
Code: Select all
void CTWGame::Play(){
  int done=0;
  while(done==0){
    SDL_Event* event;
    while ( SDL_PollEvent(event)){
      if(event->type==SDL_QUIT) done=1;
    }
    DrawScene();
  }
}


With:
Code: Select all
void CTWGame::Play(){
  int done=0;
  while(done==0){
    SDL_Event event;
    while ( SDL_PollEvent(&event)){
      if(event.type==SDL_QUIT) done=1;
    }
    DrawScene();
  }
}


Now everthing runs as expected. Unfortunatly I couldn't figure out why the origional code broke. If anyone could explain what was wrong with the previous code...or if something was off in my SDL environment I'd be very grateful. If it matters I'm running on gentoo on an AMD64 architecture.
mota
 
Posts: 2
Joined: Sun Aug 07, 2005 8:47 pm


Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest