xboxscene.org forums

Pages: [1] 2

Author Topic: The Linker From Hell  (Read 192 times)

MercuryTheWhite

  • Archived User
  • Newbie
  • *
  • Posts: 21
The Linker From Hell
« on: October 05, 2005, 06:42:00 PM »

Ok, this  a major problem because all the tuts im using are from the same site and they're all giving me the same error!! a sh*tload of linker errors!! ok herewe go
CODE

#include

 

// Interesting thing, depending which directories and libs you've got added

// in Tools->Options in the VC++ Directories - I've only got:

//

//    "Include files" -> C:\OpenXDK\include\

//    "Library files" -> C:\OpenXDK\lib\

//    "Executable files" -> C:\OpenXDK\bin\

// as I was following the doc setup, which means I have to specify the

// full path of the stdio.h file if I want to use i/o functions.  Alternatively

// just add the extra path to your include above, so you get away with

 

#include       // _open, _close etc...

#include                            // strlen(..)

 

VOID XBoxStartup()

{



      char Buffer[] = "Test text - simple but sweet";

 

      // These file functions are defined in stdio.h

      // e.g. int _open( char *filename, int oflag, int permission );

      int handle = _open( "D:\\test.txt", _O_RDWR|_O_BINARY|_O_CREAT|_O_TRUNC, 0 );

      int AmountRead = _write( handle, &Buffer[0], strlen(&Buffer[0]) );

      _close( handle );

      

      HalReturnToFirmware(ReturnFirmwareFatal);

}// End


alright thats the code, heres the make

CODE

Compiler: XBOX
Building Makefile: "C:\cygwin\usr\local\dev\Game\Makefile.win"
Executing  make clean
rm -f main.o  Game.exe

g++.exe -D__DEBUG__ -c main.cpp -o main.o -I"C:/cygwin/usr/local/openxdk/include"  -I"C:/cygwin/usr/local/openxdk/include/openxdk"    -c -g -ffreestanding -nostdlib -fno-builtin -fno-exceptions -mno-cygwin -march=i386 -DENABLE_XBOX -DDISABLE_CDROM -ansi -traditional-cpp -w -fexceptions -g3 -march=i386

g++.exe -D__DEBUG__ main.o  -o "Game.exe" -L"C:/cygwin/usr/local/openxdk/lib" -nostdlib -Wl,--file-alignment,0x20 -Wl,--section-alignment,0x20 -shared -Wl,--entry,_WinMainCRTStartup -Wl,--strip-all -lopenxdk -lhal -lc -lhal -lc -lusb -lxboxkrnl -lxinput -L"C:/cygwin/usr/local/dev/space_invaders/OpenXDK/lib"  -lobjc -g3 -march=i386

main.o: In function `XBoxStartup':
C:/cygwin/usr/local/dev/Game/main.cpp:45: undefined reference to `_open'
C:/cygwin/usr/local/dev/Game/main.cpp:47: undefined reference to `_write'
C:/cygwin/usr/local/dev/Game/main.cpp:49: undefined reference to `_close'
collect2: ld returned 1 exit status

make.exe: *** [Game.exe] Error 1

Execution terminated


I think after narrowing things down by annoying the AWESOME people on #C++ that this is a library problem! unfortunately librarys are compiled and if u try to open ' em u get greek so i just sorta have to give u guys the link! THE LINK

plz help! these are GOOD TUTS and id really like to be able to compile this stuff!
Logged

MercuryTheWhite

  • Archived User
  • Newbie
  • *
  • Posts: 21
The Linker From Hell
« Reply #1 on: October 06, 2005, 07:29:00 PM »

Ok back again with  more info. It seems that im getting errors from the libusb.a file
which is either the cause of or addition to my library-related woes   heres another makefile

CODE

Compiler: XBOX
Building Makefile: "C:\cygwin\usr\local\dev\SDLImageTest\Makefile.win"
Executing  make clean
rm -f main.o  sdlImageTest.exe

i386-pc-xbox-gcc -c main.c -o main.o -I"C:/cygwin/usr/local/openxdk/include"  -I"C:/cygwin/usr/local/openxdk/i386-pc-xbox/include"    -std=gnu99 -ffreestanding -nostdlib -fno-builtin -fno-exceptions -mno-cygwin -march=i386 -I/usr/local/openxdk/i386-pc-xbox/include -I/usr/local/openxdk/include

main.c: In function `XBoxStartup':
main.c:23: warning: implicit declaration of function `_IMG_Load'
main.c:23: warning: assignment makes pointer from integer without a cast
main.c:28: warning: assignment makes pointer from integer without a cast
main.c:33: warning: assignment makes pointer from integer without a cast
i386-pc-xbox-gcc main.o  -o "sdlImageTest.exe" -L"C:/cygwin/usr/local/OpenXDK/lib" -L"C:/cygwin/usr/local/openxdk/i386-pc-xbox/lib" -nostdlib -Wl,--file-alignment,0x20 -Wl,--section-alignment,0x20 -shared -Wl,--entry,_WinMainCRTStartup -Wl,--strip-all -L/usr/local/openxdk/i386-pc-xbox/lib -L/usr/local/openxdk/lib -lSDL -lopenxdk -lhal -lc -lhal -lc -lusb -lxboxkrnl  

main.o:main.c:(.text+0x2c): undefined reference to `__IMG_Load'
main.o:main.c:(.text+0x62): undefined reference to `__IMG_Load'
main.o:main.c:(.text+0x98): undefined reference to `__IMG_Load'
C:/cygwin/usr/local/OpenXDK/lib/libusb.a(usb.o):usb.c:(.text+0xe2e): undefined reference to `_snprintf'
C:/cygwin/usr/local/OpenXDK/lib/libusb.a(usb.o):usb.c:(.text+0xe6b): undefined reference to `_snprintf'
C:/cygwin/usr/local/OpenXDK/lib/libusb.a(usb.o):usb.c:(.text+0xea8): undefined reference to `_snprintf'
C:/cygwin/usr/local/OpenXDK/lib/libusb.a(hub.o):hub.c:(.text+0x1403): undefined reference to `_snprintf'
C:/cygwin/usr/local/OpenXDK/lib/libusb.a(hub.o):hub.c:(.text+0x142e): undefined reference to `_snprintf'
collect2: ld returned 1 exit status
make.exe: *** [sdlImageTest.exe] Error 1

Execution terminated


See what i mean?   i really hope someone responds soon, because I cant use SDL, USB, or I/O functions  almost at all


In case u noticed I re-downloaded OpenXDK, and re-installed Dev-Cpp
sad.gif
Logged

d0wnlab

  • Archived User
  • Sr. Member
  • *
  • Posts: 326
The Linker From Hell
« Reply #2 on: October 06, 2005, 08:06:00 PM »

hey.

Try compiling the samples package from the openxdk website, or openxdk CVS.  The first tutorial code you're using is ancient (you don't need to use _open or anything like that, just plain:

#include <stdio.h>

FILE *fp = fopen("d:/blah.txt", "r");
char buf[255];
fread(buf, sizeof(char), 1, fp);
fclose(fp);

etc..)

Let me know how that goes

Cheers,
Tom
Logged

Carcharius

  • Archived User
  • Sr. Member
  • *
  • Posts: 304
The Linker From Hell
« Reply #3 on: October 07, 2005, 04:02:00 AM »

Just change the order that the libs are linked in.

Swap the entry for lib usb with the one for libc that is to tjhe left of it.

So instead of reading
...-lc -lusb -lxboxkrnl  

it reads
...-lusb -lc -lxboxkrnl
Logged

MercuryTheWhite

  • Archived User
  • Newbie
  • *
  • Posts: 21
The Linker From Hell
« Reply #4 on: October 07, 2005, 10:52:00 AM »

sweet, got them working using charcharius' method
while doing so i noticed that i moved the library -lusb in between -lc and -lc

does everything in between the -lc 's get read as though it was written in C?

now i tried this new linker thing on another program tutorial im running which is just space invaders. I got it from xbdev and it also doesn't wanna work and is giving me simmilar errors. Is this because I need to update the code like d0wnlab said? I wouldnt be suprised if it was archaic because the site is no longer maintained. Just would love to get a game working. here's a link to the code.

thx for all ur support guys smile.gif
Logged

Carcharius

  • Archived User
  • Sr. Member
  • *
  • Posts: 304
The Linker From Hell
« Reply #5 on: October 07, 2005, 12:49:00 PM »

QUOTE
does everything in between the -lc 's get read as though it was written in C?

No, it just tells the linker that libusb depends on some stuff from libc. THere is something on openxdk.org that explains why -lc is there twice.


If I remember rightly the code examples on xbdev are for a long outdated version of the openxdk, so almost certainly won't work with the newest libs.
Logged

d0wnlab

  • Archived User
  • Sr. Member
  • *
  • Posts: 326
The Linker From Hell
« Reply #6 on: October 07, 2005, 12:50:00 PM »

yeah the code is ancient.

try pure SDL code instead of anything you find targetted for the openxdk online, as it's all going to be unuseable.


here, try this.  It's a little game I wrote when i was first learning SDL.

http://th0mas.xbox-s...eases/sdltron.c

It will take a (little) bit of porting to work with the openxdk.  namely:

initialize the joystick in SDL.
change the input handling code to look for joystick input instead of keyboard input.
change "int main(..)" to "void XBoxStartup()" and delete any "return (something)" lines in the function.

good luck!


Logged

MercuryTheWhite

  • Archived User
  • Newbie
  • *
  • Posts: 21
The Linker From Hell
« Reply #7 on: October 07, 2005, 01:53:00 PM »

laugh.gif awesome! much appreciated guys, glad to get things straightened out.
ill get right on that game!
 beerchug.gif
Logged

MercuryTheWhite

  • Archived User
  • Newbie
  • *
  • Posts: 21
The Linker From Hell
« Reply #8 on: October 07, 2005, 04:40:00 PM »

bump
Logged

MercuryTheWhite

  • Archived User
  • Newbie
  • *
  • Posts: 21
The Linker From Hell
« Reply #9 on: October 08, 2005, 03:26:00 PM »

ok everything works.... except the controller

CODE

            
             signed int up = 0x01;
 signed int down = 0x02;            
 signed int left = 0x04;
signed int right = 0x08;            
signed int hat;

SDL_JoystickEventState(SDL_ENABLE);
SDL_Joystick *joystick = SDL_JoystickOpen(0);
SDL_Event event;
//SDL_PollEvent( &event);
if (SDL_PollEvent(&event) && event.type == SDL_JOYHATMOTION)
     {
//   hat = SDL_JoystickGetHat(SDL_Joystick *joystick, int hat);
                
                if (event.jhat.value == up) {
   redDir = 0;
} else if (event.jhat.value == down) {
   redDir = 1;
   } else if (event.jhat.value == left) {
  redDir = 2;
} else if (event.jhat.value == right) {
   redDir = 3;
    //} else if (c == KEY_ESC) {
       //exitloop = 1;
   } else {
   SDL_Quit();
   }



How do i check to see the direction of the joystick? The way i did it doesnt work, although the program does compile.
Logged

d0wnlab

  • Archived User
  • Sr. Member
  • *
  • Posts: 326
The Linker From Hell
« Reply #10 on: October 10, 2005, 03:49:00 PM »

I'll compare it to some code tomorrow (at the GF's currently)

Tom
Logged

MercuryTheWhite

  • Archived User
  • Newbie
  • *
  • Posts: 21
The Linker From Hell
« Reply #11 on: October 11, 2005, 11:22:00 AM »

Thx cuz im at a loss...

 i cant use the HAL library to do it either =(
Logged

d0wnlab

  • Archived User
  • Sr. Member
  • *
  • Posts: 326
The Linker From Hell
« Reply #12 on: October 11, 2005, 01:21:00 PM »

Are you starting up SDL with

CODE

SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);


Otherwise try downloading and testing the sdlJoystick sample from
http://cvs.sourcefor...dk/Samples/src/

or try the padTest.c code.  Let us know how it goes.

Cheers,
Tom
Logged

MercuryTheWhite

  • Archived User
  • Newbie
  • *
  • Posts: 21
The Linker From Hell
« Reply #13 on: October 12, 2005, 06:52:00 AM »

Yea Im initiating the Joystick.
I tried SDL_Joystick and it works fine....
I dont have padTest.c tho

Im typing from school so ill post my entice source when i get home
Logged

MercuryTheWhite

  • Archived User
  • Newbie
  • *
  • Posts: 21
The Linker From Hell
« Reply #14 on: October 14, 2005, 11:00:00 AM »

sry for the late reply, i uh, sorta forgot  unsure.gif

CODE

*  ttmt -> tom's ten minute tron */
  
#include

#define TICK_INTERVAL   20

int board[100][80];
int redX, redY, blueX, blueY;
int redDir, blueDir;
int redScore, blueScore;

volatile int count;
int lastcount;
static Uint32 next_time;

SDL_Surface *screen;
SDL_Event event;

int exitloop;
void drawBoard();
void redCrash();
void blueCrash();
void clearBoard();
void moveBlue();

Uint32 time_left(void)
{
   Uint32 now;
   
   now = SDL_GetTicks();
   if (next_time <= now)
  return 0;
   else
  return next_time - now;
}

void startGame()
{
   clearBoard();
   
   redX = 25;
   redY = 40;
   redDir = 0;
   
   blueX = 75;
   blueY = 40;
   blueDir = 0;
   
   board[25][40] = 1;
   board[75][40] = 2;
   
}

void clearBoard()
{
   int a,b;
   for (a=0;a<100;a++)
   {
  for (b=0;b<80;b++)
  {
     if (a == 0 || a == 99 || b == 0 || b == 79)
    board[a]=3;
     else
    board[a]=0;
  }
   }
}

void drawBoard()
{
   char text[20];
   SDL_Rect r;
   //clear_to_color(buffer,makecol(50,50,50));
   //SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 50,50,50));
   r.w = 500;
   r.h = 400;
   r.x = 70;
   r.y = 40;
   SDL_FillRect(screen, &r, SDL_MapRGB(screen->format, 0,0,0));
   
   //rectfill(buffer, (SCREEN_W-500)/2, (SCREEN_H-400)/2, 500 + ((SCREEN_W-500)/2), 400 + ((SCREEN_H-400)/2),makecol(0,0,0));
   int a,b;
   r.w = 5;
   r.h = 5;
   for (a=0;a<100;a++)
   {
  for (b=0;b<80;b++)
  {
     r.x = 70 + (a*5);
     r.y = 40 + (b*5);
     if (board[a] == 1)
    SDL_FillRect(screen,&r,SDL_MapRGB(screen->format, 255,0,0));
     else if (board[a] == 2)
    SDL_FillRect(screen,&r,SDL_MapRGB(screen->format, 0,0,255));
     else if (board[a] == 3)
    SDL_FillRect(screen,&r,SDL_MapRGB(screen->format, 0,200,0));
  }
   }
   
   //sprintf(text, "%i", redScore);
   //textout(buffer,font,text,25,25,makecol(255,0,0));
   //sprintf(text, "%i", blueScore);
   //textout(buffer,font,text,SCREEN_W-25,25,makecol(0,0,255));
   
   //blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
   SDL_Flip(screen);
}

void counter ()
{
   count++;
}

int nextObj(int dirA)
{
   int a;
   int moveX, moveY;
   moveX = 0;
   moveY = 0;
   if (dirA == 0)
   {
  moveY = -1;
   } else if (dirA == 1) {
  moveX = 1;
   } else if (dirA == 2) {
  moveY = 1;
   } else if (dirA == 3) {
  moveX = -1;
   }
   
   for (a=1;a<15;a++)
   {
  /*if (blueX+(moveX*a) < 100 && blueY+(moveY*a) < 80 && blueX+(moveX*a) > -1 && blueY+ (moveY*a) > -1)
  {*/
     if (board[blueX+(moveX*a)][blueY+(moveY*a)] != 0)
    return a;
  /*}*/
   }
   return a;
}
   
   
void moveBlue()
{
   int moveX = 0;
   int moveY = 0;
   int a;
   int trouble= 0;
   int choiceA;
   int choiceB;
   /*
   if (blueDir == 0)
   {
  moveY = -1;
   } else if (blueDir == 1) {
  moveX = 1;
   } else if (blueDir == 2) {
  moveY = 1;
   } else if (blueDir == 3) {
  moveX = -1;
   }
   
   for (a=1;a<4;a++)
   {
  if (blueX+(moveX*a) < 100 && blueY+(moveY*a) < 80)
  {
     if (board[blueX+(moveX*a)][blueY+(moveY*a)] != 0)
    trouble = 1;
  }
   } */
   if (nextObj(blueDir) < 5 || rand() % 50 == 7)
   {

  choiceA = blueDir + 1;
  choiceB = blueDir - 1;
  if (choiceB < 0) choiceB = 3;
  if (choiceA > 3) choiceA = 0;
  if (nextObj(choiceA) > nextObj(choiceB))
  {
     blueDir = choiceA;
  } else if (nextObj(choiceA) < nextObj(choiceB)) {
     blueDir = choiceB;
  } else if (nextObj(choiceA) != 1){
    a = (rand() % 2);
    if (a == 0) a = -1;
    blueDir+= a;
    if (blueDir < 0) blueDir = 3;
    if (blueDir > 3) blueDir = 0;
     }   
  }
}

void playgame()
{
   int c;
   startGame();
   lastcount = count;
   next_time = SDL_GetTicks() + TICK_INTERVAL;
   //while ();
   while (exitloop == 0)
   {
  while (time_left() > 0)
  {        
                        

if (SDL_PollEvent(&event) && event.type == SDL_JoyHatMotion)
{

if (event.jhat.value  == SDL_HAT_UP)
{
reDir = 0;
}
else if (event.jhat.value == SDL_HAT_RIGHT)
{
reDir = 1;
}
else if (event.jhat.value == SDL_HAT_DOWN)
{
reDir = 2;
}
else if (event.jhat.value == SDL_HAT_LEFT)
{
reDir = 3;
}
else
{
SDL_Quit();
}


}
/*
     //SDL_PollEvent( &event);
     if (SDL_PollEvent(&event) && event.type == SDL_KEYDOWN)
     {
    if (event.key.keysym.sym == SDLK_UP && redDir != 2) {
       redDir = 0;
    } else if (event.key.keysym.sym == SDLK_RIGHT && redDir != 3) {
       redDir = 1;
    } else if (event.key.keysym.sym == SDLK_DOWN && redDir != 0) {
       redDir = 2;
    } else if (event.key.keysym.sym == SDLK_LEFT && redDir != 1) {
       redDir = 3;
    //} else if (c == KEY_ESC) {
       //exitloop = 1;
    } else {
       SDL_Quit();


    }
*/                 }
  }
  next_time+= TICK_INTERVAL;
  if (redDir == 0) {
     if (board[redX][redY-1] == 0)
     {   
    redY--;
    board[redX][redY] = 1;
     } else {
    redCrash();
     }
  } else if (redDir == 1) {
     if (board[redX+1][redY] == 0)
     {
    redX++;
    board[redX][redY] = 1;
     } else {
    redCrash();
     }
  } else if (redDir == 2) {
     if (board[redX][redY+1] == 0)
     {   
    redY++;
    board[redX][redY] = 1;
     } else {
    redCrash();
     }
  } else if (redDir == 3) {
     if (board[redX-1][redY] == 0)
     {   
    redX--;
    board[redX][redY] = 1;
     } else {
    redCrash();
     }
  }
  moveBlue();
  if (blueDir == 0) {
     if (board[blueX][blueY-1] == 0)
     {   
    blueY--;
    board[blueX][blueY] = 2;
     } else {
    blueCrash();
     }
  } else if (blueDir == 1) {
     if (board[blueX+1][blueY] == 0)
     {
    blueX++;
    board[blueX][blueY] = 2;
     } else {
    blueCrash();
     }
  } else if (blueDir == 2) {
     if (board[blueX][blueY+1] == 0)
     {   
    blueY++;
    board[blueX][blueY] = 2;
     } else {
    blueCrash();
     }
  } else if (blueDir == 3) {
     if (board[blueX-1][blueY] == 0)
     {   
    blueX--;
    board[blueX][blueY] = 2;
     } else {
    blueCrash();
     }
  }
  drawBoard();
  lastcount = count;
   }
}
Void XboxStartup(int argc, char *argv[])
{
   int a=0;
   exitloop = 0;
   SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK);
   
   screen = SDL_SetVideoMode(640,480,32, SDL_HWSURFACE | SDL_DOUBLEBUF);
   
   int c;
   count = 0;
   
   //LOCK_VARIABLE(count);
   //LOCK_FUNCTION(counter);

   //install_int_ex(counter, BPS_TO_TIMER(40));
   playgame();
   
}

//END_OF_MAIN();


void redCrash()
{
   blueScore++;
   playgame();
}

void blueCrash()
{
   redScore++;
   playgame();
}




there ya go...  gl
Logged
Pages: [1] 2