In serious need of linking/compiling help with SDL, using cygwin

I have the following problems compiling an SDL application in windows, does
anyone know what these errors mean, and how best to deal with them? Nothing
I do seems to get rid of them. I’ve tried using both gcc and g++, but both
do hte same thing (someone had suggested they do different things a while
ago).

This only occures when I include a library I compiled for SDL (gil_app.o),
when I try the source file demonstrated in the visual C++ example
(http://pgdc.purdue.org/sdltutorial/sdl_setup.html), it works fine using the
same flags/options as TEST COMPILE 2 and TEST COMPILE 3.

CYGWIN: Downloaded roughly 2/1/2004
SDL: 1.2.6 - compiled and installed normally from .tar.gz

Compilation of the main source file (test.cpp)

==TEST COMPILE 1==

$ gcc -O2 test.cpp
src/gil_app.o -I/usr/local/include/SDL -L/usr/local/lib -lSDL -lSDLmain -lus
er32 -lgdi32 -lwinmm -L/usr/lib/mingw -DWIN32 -Uunix -mno-cygwin
/cygdrive/c/DOCUME~1/sjss/LOCALS~1/Temp/ccKHXhs9.o(.text+0x6b):test.cpp:
undefined reference to ___gxx_personality_sj0' /usr/lib/mingw/libmingw32.a(main.o)(.text+0x9b):main.c: undefined reference to_WinMain at 16’
collect2: ld returned 1 exit status

==TEST COMPILE 2==

$ gcc -O2 test.cpp
src/gil_app.o -I/usr/local/include/SDL -L/usr/local/lib -lSDL -lSDLmain -lus
er32 -lgdi32 -lwinmm
/cygdrive/c/DOCUME~1/sjss/LOCALS~1/Temp/ccAKIuB3.o(.text+0x69):test.cpp:
undefined reference to `___gxx_personality_sj0’
collect2: ld returned 1 exit status

==TEST COMPILE 3==

$ gcc -O2 test.cpp
src/gil_app.o -I/usr/local/include/SDL -L/usr/local/lib -lSDL -lSDLmain
/cygdrive/c/DOCUME~1/sjss/LOCALS~1/Temp/cc0oBtlW.o(.text+0x69):test.cpp:
undefined reference to `___gxx_personality_sj0’
collect2: ld returned 1 exit status

gil_app.cpp was compiled with the following command line:
gcc -c gil_app.cpp -L/usr/local/lib -I/usr/local/include/SDL/

==============SOURCE CODE CONTENT BELOW==============

==============CONTENT OF src/gil_app.cpp
#include “gil_app.h”

gil_app::gil_app() { this->screen = NULL; }

Sint32 gil_app::init(Uint32 h, Uint32 w, Uint32 b, Uint32 video_flags)
{
this->height = h; /set the height variable/
this->width = w; /set the width variable/
this->bpp = b; /set the bits per pixel variable/
this->videomode_flags = video_flags;

if(SDL_Init(SDL_INIT_VIDEO) < 0) /set fail bit on initialization/
{
return -1;
}
return 0;
}

//Sint32 gil_app::run()
//{
// /try getting a screen/
// if(!(this->screen = SDL_SetVideoMode(this->width,
// this->height,
// this->bpp,
// this->videomode_flags)))
//{
// return -1;
// }
// else
// {
// SDL_Delay(1000);
// }
// return 0;
//}

gil_app::~gil_app()
{
if(this->screen)
{
SDL_Quit();
}
}

==============CONTENT OF src/gil_app.h
#include <SDL.h>

#ifndef GIL_APP_H
#define GIL_APP_H

class gil_app
{
private:
Uint32 height, width;
Uint32 bpp;
SDL_Surface *screen;
Uint32 videomode_flags;
public:

gil_app();

Sint32 init(Uint32 h, Uint32 w, Uint32 b, Uint32 video_flags);

// Sint32 run();

~gil_app();

};

#endif

==============CONTENT OF test.cpp
#include “src/gil_app.h”
#include <stdio.h>

int main()
{
FILE *perr;
if(!(perr = fopen(“err.log”, “w”)))
{
return -1;
}
fprintf(perr, “Initializing\n”);

gil_app myapp;

fprintf(perr, “GIL object created\n”);

Sint32 err = myapp.init(640, 480, 32, SDL_HWSURFACE);
if(err < 0)
{
return -1;
}

fprintf(perr, “Initialized\n”);

fprintf(perr, “Terminating\n”);

fclose(perr);

return 0;
}

==TEST COMPILE 2==

$ gcc -O2 test.cpp
src/gil_app.o -I/usr/local/include/SDL -L/usr/local/lib -lSDL -lSDLmain -lus
er32 -lgdi32 -lwinmm
/cygdrive/c/DOCUME~1/sjss/LOCALS~1/Temp/ccAKIuB3.o(.text+0x69):test.cpp:
undefined reference to `___gxx_personality_sj0’
collect2: ld returned 1 exit status

If you build cpp files, you need to use g++ for compiling and linking.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

I am not entirely sure about your exactly errors under Cygwin. However, my
experience with building SDL under Cygwin has proven that using the older gcc
compiler is the only way to build the library to begin with. Try building with
the gcc version 2.96 package available off the Cygwin installer. You’ll have
the make sure it uses the new compiler, but after that, it should build without
any issues.