Even more keyboard in OSX... - Att. Max Horn

Hi again - this is for Max Horn

Thanks for your reply, I’ve been trying to get rid of the #undef main hack for
ages now… How?

I’m including SDL.h and linking libSDL into my program, and if I don’t #undef,
then I get the error that _main is undefined. If I include SDL_main.h and link
to libSDLmain, then hell is raised, and I get all kinds of errors, that tell me
that various stuff is indirectly referenced in other libraries. Could you
possibly post a template with the right includes (in the right order), and the
right libraries to link to…? That would be very helpfull :slight_smile:

Thanks in advance!

  • Andreas

buding at daimi.au.dk wrote:

Thanks for your reply, I’ve been trying to get rid of the #undef main
hack for ages now… How?

I’m including SDL.h and linking libSDL into my program, and if I
don’t #undef, then I get the error that _main is undefined. If I
include SDL_main.h and link to libSDLmain, then hell is raised, and I
get all kinds of errors, that tell me that various stuff is
indirectly referenced in other libraries. Could you possibly post a
template with the right includes (in the right order), and the right
libraries to link to…? That would be very helpfull :slight_smile:

The correct include is just:
#include “SDL.h”

The correct way to compile your program is:
cc -o myprog myprog.c sdl-config --cflags --libs

This works on Linux and Mac OS X.

You should make sure that your main function is defined:
int main(int argc, char **argv)

Fred

Thanks Fred, this seems like more solid facts :slight_smile:

One question though - what does the ‘sdl-config --cflags --libs’ mean? When I
include SDL.h, and edit main(int argc, char *argv[]) to main(int argc, char
**argv) i get the exact same error: ld: undefined symbols: _main.
That is, compiling with

cc Skvulp.c -o Skvulp -L/Users/buding/lib -lSDL -lobjc

What is sdl-config and --cflags…? I’m fairly new to C, and especially linking
and such, obviously :slight_smile:

Thanks again!

Andreas

buding at daimi.au.dk wrote:

One question though - what does the 'sdl-config --cflags --libs’
mean? When I include SDL.h, and edit main(int argc, char *argv[]) to
main(int argc, char **argv) i get the exact same error: ld: undefined
symbols: _main. That is, compiling with

cc Skvulp.c -o Skvulp -L/Users/buding/lib -lSDL -lobjc

This does not include libSDLmain.a. You should use:
cc Skvulp.c -o Skvulp sdl-config --cflags --libs
You can just run sdl-config --cflags --libs to see what it adds to your
compile line on Mac OS X. Notice that this is different to what it adds
on Linux.

What is sdl-config and --cflags…? I’m fairly new to C, and
especially linking and such, obviously :slight_smile:

sdl-config is a script that ships with SDL that takes care of getting
your include path and linking flags right when compiling programs that
use SDL. It means that you don’t need to worry about the right values
when moving from one OS to another.

I recommend you look for the book “Programming Linux Games” which covers
a lot of the basics of using SDL. If you don’t want to buy a paper copy,
the author made it available on the web for free download, check out
Google. You should also read all the docs

Fred

— buding at daimi.au.dk wrote:

I’ve been trying to get rid
of the #undef main hack for
ages now… How?

Maybe this has already been mentioned, but if you
don’t provide the correct arguments to your main
routine’s function definition, it won’t be replaced by
SDL’s macro. Using “main(int argc, char **argv)” is
the best thing to do.__________________________________
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.