Strange Error while compiling

Code:

/*

*/

#include “SDL/SDL.h” /* All SDL App’s need this */
#include

using namespace std;

int main(int argc, char * argv[]) {

cout << "Initializing SDL..." << endl;

/* Initialize defaults, Video and Audio */
if((SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)==-1)) {
    cout << "Could not initialize SDL:"<< endl << SDL_GetError() << endl;
    exit(-1);
}

cout << "SDL initialized." << endl;

cout << "Quitting SDL..." << endl;

/* Shutdown all subsystems */
SDL_Quit();

cout << "Quitting..." << endl;

exit(0);
return 0;

}

Line Run Inside Terminal:

c++ -o sdl -lSDL sdltest.cpp

Error given:

/usr/bin/ld: Undefined symbols:
_main
collect2: ld returned 1 exit status

Any help would be much appreciated.

Line Run Inside Terminal:

c++ -o sdl -lSDL sdltest.cpp

If this is Mac OS X, add -lSDLmain to the command line.

–ryan.

Code:

/*

*/

#include “SDL/SDL.h” /* All SDL App’s need this */
#include

using namespace std;

int main(int argc, char * argv[]) {

cout << "Initializing SDL..." << endl;

/* Initialize defaults, Video and Audio */
if((SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)==-1)) {
    cout << "Could not initialize SDL:"<< endl << SDL_GetError() << endl;
    exit(-1);
}

cout << "SDL initialized." << endl;

cout << "Quitting SDL..." << endl;

/* Shutdown all subsystems */
SDL_Quit();

cout << "Quitting..." << endl;

exit(0);
return 0;

}

Line Run Inside Terminal:

c++ -o sdl -lSDL sdltest.cpp

Error given:

/usr/bin/ld: Undefined symbols:
_main
collect2: ld returned 1 exit status

Any help would be much appreciated.

I assume you’re on OS X.

You need to link with sdl-config --libs and compile with sdl-config --cflags,
and the SDL header is “SDL.h” not “SDL/SDL.h”. While linking -lSDL
and including
"SDL/SDL.h" may work on Linux, neither will work on OS X, for example.
The portable ways - using the sdl-config script and “SDL.h” - are
better.

The actual problem in this case is that for Windows, OS X, and some
other platforms, SDL sets up its own main function and does some
preprocessor trickery to turn your main() into SDL_main(), and supply
main() itself. (This is necessary sometimes to do platform-specific
graphics initialization.) SDL’s main() is supplied in -lSDL_main, but
on OS X you need other flags: -framework Cocoa -framework OpenGL and
maybe some more. `sdl-config’ takes care of all of this for you.

Hope this helps.
– JoshOn 10/19/05, Lacuna Halogen <hybrid.basis at gmail.com> wrote:


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

I am on OS X, but there were a whole pile more issues when I compiled with
-lSDL_main.
Josh, would I compile it like this, then?
c++ -o sdl sdl-config sdltest.cpp
Thanks,
LacunaOn 10/19/05, Joshua Oreman wrote:

On 10/19/05, Lacuna Halogen <@Lacuna_Halogen> wrote:

Code:

/*

*/

#include “SDL/SDL.h” /* All SDL App’s need this */
#include

using namespace std;

int main(int argc, char * argv[]) {

cout << “Initializing SDL…” << endl;

/* Initialize defaults, Video and Audio */
if((SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)==-1)) {
cout << “Could not initialize SDL:”<< endl << SDL_GetError() << endl;
exit(-1);
}

cout << “SDL initialized.” << endl;

cout << “Quitting SDL…” << endl;

/* Shutdown all subsystems */
SDL_Quit();

cout << “Quitting…” << endl;

exit(0);
return 0;
}

Line Run Inside Terminal:

c++ -o sdl -lSDL sdltest.cpp

Error given:

/usr/bin/ld: Undefined symbols:
_main
collect2: ld returned 1 exit status

Any help would be much appreciated.

I assume you’re on OS X.

You need to link with sdl-config --libs and compile with sdl-config --cflags,
and the SDL header is “SDL.h” not “SDL/SDL.h”. While linking -lSDL
and including
"SDL/SDL.h" may work on Linux, neither will work on OS X, for example.
The portable ways - using the sdl-config script and “SDL.h” - are
better.

The actual problem in this case is that for Windows, OS X, and some
other platforms, SDL sets up its own main function and does some
preprocessor trickery to turn your main() into SDL_main(), and supply
main() itself. (This is necessary sometimes to do platform-specific
graphics initialization.) SDL’s main() is supplied in -lSDL_main, but
on OS X you need other flags: -framework Cocoa -framework OpenGL and
maybe some more. `sdl-config’ takes care of all of this for you.

Hope this helps.
– Josh


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

I am on OS X, but there were a whole pile more issues when I compiled with
-lSDL_main.
Josh, would I compile it like this, then?
c++ -o sdl sdl-config sdltest.cpp
Thanks,
Lacuna

Please see the ReadMeDevLite.txt in the SDL-1.2.9.dmg from the SDL
download page. I think I am quite explicit in there about how to build
a simple SDL program from the command line. If you find the
documentation inadequate, please send me feedback on how I might
improve it.

You should also read the relevant SDL FAQs at http://www.libsdl.org/faq.php

-Eric> From: Lacuna Halogen

c++ -o program program.cpp sdl-config --libs

the ` things are backticks, they are usually on the button under ESC( on a
mac i’m not sure…)On 10/20/05, Lacuna Halogen <hybrid.basis at gmail.com> wrote:

I am on OS X, but there were a whole pile more issues when I compiled with
-lSDL_main.
Josh, would I compile it like this, then?
c++ -o sdl sdl-config sdltest.cpp
Thanks,
Lacuna

yep, that’s where they are, right under the tilde(~).

It all works now though, thanks!On 10/20/05, Brian Barrett <brian.ripoff at gmail.com> wrote:

On 10/20/05, Lacuna Halogen <@Lacuna_Halogen> wrote:

I am on OS X, but there were a whole pile more issues when I compiled with
-lSDL_main.

Josh, would I compile it like this, then?

c++ -o sdl sdl-config sdltest.cpp

Thanks,

Lacuna

c++ -o program program.cpp sdl-config --libs

the ` things are backticks, they are usually on the button under ESC( on a
mac i’m not sure…)


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Hybrid.

“Evolution is Neccesary.”