Undefined symbols: main... on OS X (Leopard)

I know this has been posted about before, but the threads I have seen
have not helped.

I am on OS 10.5.6. I have compiled SDL using ./configure;make;make install.

This is the code I am attempting to compile:
http://pastie.org/406982

This is the command I am using to compile it:
gcc test.c

The output is:
Undefined symbols:
"_main", referenced from:
start in crt1.10.5.o
"_SDL_Init", referenced from:
_SDL_main in ccd8bu8C.o
"_SDL_Quit", referenced from:
_SDL_main in ccd8bu8C.o
"_SDL_GetKeyName", referenced from:
_SDL_main in ccd8bu8C.o
"_SDL_GetError", referenced from:
_SDL_main in ccd8bu8C.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

I do not want to use XCode or anything related to it.

Any helps/ideas/pointers are much appreciated.

  • Daniel

Hi Daniel-

You’ll need to use a file called SDLMain.m (and possibly SDLMain.h in
older versions) which you can find on google. You’ll need to link your
application against that, and against Cocoa.framework using -framework
Cocoa in gcc. I personally suggest you consider using the SDL
frameworks which are available on libsdl.org as UB and linking against
them with -framework SDL.

AlastairOn 4 Mar 2009, at 10:53, Daniel Waite wrote:

I know this has been posted about before, but the threads I have seen
have not helped.

I am on OS 10.5.6. I have compiled SDL using ./configure;make;make
install.

This is the code I am attempting to compile:
http://pastie.org/406982

This is the command I am using to compile it:
gcc test.c

The output is:
Undefined symbols:
"_main", referenced from:
start in crt1.10.5.o
"_SDL_Init", referenced from:
_SDL_main in ccd8bu8C.o
"_SDL_Quit", referenced from:
_SDL_main in ccd8bu8C.o
"_SDL_GetKeyName", referenced from:
_SDL_main in ccd8bu8C.o
"_SDL_GetError", referenced from:
_SDL_main in ccd8bu8C.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

I do not want to use XCode or anything related to it.

Any helps/ideas/pointers are much appreciated.

  • Daniel

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

-------------- next part --------------
A non-text attachment was scrubbed…
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3912 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20090304/8e70a1b0/attachment.bin

Hi Alastair,

I had tried the -framework switch before, and it had alleviated some
error messages, but I came to believe that that switch is used to
invoke the SDL library in /Library/Frameworks/SDL.framework. I
subsequently removed the SDL.framework directory after compiling SDL
myself.

Also, I was able to fully resolve my undefined symbol errors by
actually following through with the content on this thread:
http://lists.libsdl.org/pipermail/sdl-libsdl.org/2005-April/049942.html

And this part in particular:
… you need to use the output of ‘sdl-config --cflags --libs’ in your
gcc command line …

I had run both commands earlier and, upon seeing the amount of
material I didn’t understand spewed onto the screen, ignored it. My
thoughts were, why wouldn’t the SDL READMEs for OS X mention ANY of
this? And if it was not mentioned it “shouldn’t” be relevant. (Goes to
show how much I know…)

Anywho, you DO need it, at least if you’re going to use GCC to compile
SDL programs written in C.

Thanks again Alastair for the quick response. I appreciate the help. :slight_smile:

  • Daniel—

On Wed, Mar 4, 2009 at 7:40 AM, Alastair Lynn wrote:

Hi Daniel-

You’ll need to use a file called SDLMain.m (and possibly SDLMain.h in older
versions) which you can find on google. You’ll need to link your application
against that, and against Cocoa.framework using -framework Cocoa in gcc. I
personally suggest you consider using the SDL frameworks which are available
on libsdl.org as UB and linking against them with -framework SDL.

Alastair

On 4 Mar 2009, at 10:53, Daniel Waite wrote:

I know this has been posted about before, but the threads I have seen
have not helped.

I am on OS 10.5.6. I have compiled SDL using ./configure;make;make
install.

This is the code I am attempting to compile:
http://pastie.org/406982

This is the command I am using to compile it:
gcc test.c

The output is:
Undefined symbols:
?"_main", referenced from:
? ? start in crt1.10.5.o
?"_SDL_Init", referenced from:
? ? _SDL_main in ccd8bu8C.o
?"_SDL_Quit", referenced from:
? ? _SDL_main in ccd8bu8C.o
?"_SDL_GetKeyName", referenced from:
? ? _SDL_main in ccd8bu8C.o
?"_SDL_GetError", referenced from:
? ? _SDL_main in ccd8bu8C.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

I do not want to use XCode or anything related to it.

Any helps/ideas/pointers are much appreciated.

  • Daniel

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

i assume you installed the unix way to /usr/local, sdl-config sould be in
/usr/local/bin.

which sld-config should show where it is. if that fails, you might have
to check your PATH.

gcc sld-config --libs --cflags -o test test.c

-framework i thought was for linking to a library bundle, am i mistaken ?

i use osx, but mostly a gnu/linux.

mattOn Wed, 4 Mar 2009, Alastair Lynn wrote:

Hi Daniel-

You’ll need to use a file called SDLMain.m (and possibly SDLMain.h in older
versions) which you can find on google. You’ll need to link your application
against that, and against Cocoa.framework using -framework Cocoa in gcc. I
personally suggest you consider using the SDL frameworks which are available
on libsdl.org as UB and linking against them with -framework SDL.

Alastair

On 4 Mar 2009, at 10:53, Daniel Waite wrote:

I know this has been posted about before, but the threads I have seen
have not helped.

I am on OS 10.5.6. I have compiled SDL using ./configure;make;make install.

This is the code I am attempting to compile:
http://pastie.org/406982

This is the command I am using to compile it:
gcc test.c

The output is:
Undefined symbols:
"_main", referenced from:
start in crt1.10.5.o
"_SDL_Init", referenced from:
_SDL_main in ccd8bu8C.o
"_SDL_Quit", referenced from:
_SDL_main in ccd8bu8C.o
"_SDL_GetKeyName", referenced from:
_SDL_main in ccd8bu8C.o
"_SDL_GetError", referenced from:
_SDL_main in ccd8bu8C.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

I do not want to use XCode or anything related to it.

Any helps/ideas/pointers are much appreciated.

  • Daniel

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

i assume you installed the unix way to /usr/local, sdl-config sould
be in /usr/local/bin.

which sld-config should show where it is. if that fails, you might
have to check your PATH.

gcc sld-config --libs --cflags -o test test.c

-framework i thought was for linking to a library bundle, am i
mistaken ?

A framework is just the way on MacOSX to bundle a library (or multiple
libraries) together with headers, resources and other stuff.

With -framework, you link to a whole framework (so to all including
libraries and you also have the header search paths), with -l, you
just link to a single lib.

It is the standard way on MacOSX to bundle libraries together to such
frameworks which ideally don’t have further dependencies and can be
bundled also into an app bundle.Am 04.03.2009 um 19:52 schrieb mattmatteh at mac.com:


The SDL library in the SDL framework which can be downloaded is though
much different from SDL if you installed it yourself the Unix way to /
usr/local.

In short: The SDL framework is esp. prepared for running nativly on
MacOSX and for packaging your application to ship with it. And it is
working standalone and has no further dependencies. And it is a
Universal Binary.

You cannot ship your game if it is linked against the /usr/local/ SDL
lib.

  • Albert

i use osx, but mostly a gnu/linux.

matt

On Wed, 4 Mar 2009, Alastair Lynn wrote:

Hi Daniel-

You’ll need to use a file called SDLMain.m (and possibly SDLMain.h
in older versions) which you can find on google. You’ll need to
link your application against that, and against Cocoa.framework
using -framework Cocoa in gcc. I personally suggest you consider
using the SDL frameworks which are available on libsdl.org as UB
and linking against them with -framework SDL.

Alastair

On 4 Mar 2009, at 10:53, Daniel Waite wrote:

I know this has been posted about before, but the threads I have
seen
have not helped.
I am on OS 10.5.6. I have compiled SDL using ./configure;make;make
install.
This is the code I am attempting to compile:
http://pastie.org/406982
This is the command I am using to compile it:
gcc test.c
The output is:
Undefined symbols:
"_main", referenced from:
start in crt1.10.5.o
"_SDL_Init", referenced from:
_SDL_main in ccd8bu8C.o
"_SDL_Quit", referenced from:
_SDL_main in ccd8bu8C.o
"_SDL_GetKeyName", referenced from:
_SDL_main in ccd8bu8C.o
"_SDL_GetError", referenced from:
_SDL_main in ccd8bu8C.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
I do not want to use XCode or anything related to it.
Any helps/ideas/pointers are much appreciated.

  • Daniel

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

@Albert

Thanks for all that information. Especially good to know about
distribution! (Not that I intend to distribute anything in the near
future, but nevertheless good to know.)

@Matt

Nice hack there with the back ticks. I’m still new to the command
line, so any help is appreciated in that department.

Thanks again all.

  • Daniel—

On Wed, Mar 4, 2009 at 12:26 PM, Albert Zeyer <albert.zeyer at rwth-aachen.de> wrote:

Am 04.03.2009 um 19:52 schrieb mattmatteh at mac.com:

i assume you installed the unix way to /usr/local, sdl-config sould be in
/usr/local/bin.

which sld-config should show where it is. ?if that fails, you might have
to check your PATH.

gcc sld-config --libs --cflags -o test test.c

-framework i thought was for linking to a library bundle, am i mistaken ?

A framework is just the way on MacOSX to bundle a library (or multiple
libraries) together with headers, resources and other stuff.

With -framework, you link to a whole framework (so to all including
libraries and you also have the header search paths), with -l, you just link
to a single lib.

It is the standard way on MacOSX to bundle libraries together to such
frameworks which ideally don’t have further dependencies and can be bundled
also into an app bundle.


The SDL library in the SDL framework which can be downloaded is though much
different from SDL if you installed it yourself the Unix way to /usr/local.

In short: The SDL framework is esp. prepared for running nativly on MacOSX
and for packaging your application to ship with it. And it is working
standalone and has no further dependencies. And it is a Universal Binary.

You cannot ship your game if it is linked against the /usr/local/ SDL lib.

  • Albert

i use osx, but mostly a gnu/linux.

matt

On Wed, 4 Mar 2009, Alastair Lynn wrote:

Hi Daniel-

You’ll need to use a file called SDLMain.m (and possibly SDLMain.h in
older versions) which you can find on google. You’ll need to link your
application against that, and against Cocoa.framework using -framework Cocoa
in gcc. I personally suggest you consider using the SDL frameworks which are
available on libsdl.org as UB and linking against them with -framework SDL.

Alastair

On 4 Mar 2009, at 10:53, Daniel Waite wrote:

I know this has been posted about before, but the threads I have seen
have not helped.
I am on OS 10.5.6. I have compiled SDL using ./configure;make;make
install.
This is the code I am attempting to compile:
http://pastie.org/406982
This is the command I am using to compile it:
gcc test.c
The output is:
Undefined symbols:
"_main", referenced from:
? ?start in crt1.10.5.o
"_SDL_Init", referenced from:
? ?_SDL_main in ccd8bu8C.o
"_SDL_Quit", referenced from:
? ?_SDL_main in ccd8bu8C.o
"_SDL_GetKeyName", referenced from:
? ?_SDL_main in ccd8bu8C.o
"_SDL_GetError", referenced from:
? ?_SDL_main in ccd8bu8C.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
I do not want to use XCode or anything related to it.
Any helps/ideas/pointers are much appreciated.

  • Daniel

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hi Daniel-

If you’re going for distribution of a game you’ll need to build an
application bundle, and whilst that’s possible from the command line,
you’ll probably find it easier to use Xcode :slight_smile:

AlastairOn 4 Mar 2009, at 20:54, Daniel Waite wrote:

@Albert

Thanks for all that information. Especially good to know about
distribution! (Not that I intend to distribute anything in the near
future, but nevertheless good to know.)

@Matt

Nice hack there with the back ticks. I’m still new to the command
line, so any help is appreciated in that department.

Thanks again all.

  • Daniel

On Wed, Mar 4, 2009 at 12:26 PM, Albert Zeyer <albert.zeyer at rwth-aachen.de> wrote:

Am 04.03.2009 um 19:52 schrieb mattmatteh at mac.com:

i assume you installed the unix way to /usr/local, sdl-config
sould be in
/usr/local/bin.

which sld-config should show where it is. if that fails, you
might have
to check your PATH.

gcc sld-config --libs --cflags -o test test.c

-framework i thought was for linking to a library bundle, am i
mistaken ?

A framework is just the way on MacOSX to bundle a library (or
multiple
libraries) together with headers, resources and other stuff.

With -framework, you link to a whole framework (so to all including
libraries and you also have the header search paths), with -l, you
just link
to a single lib.

It is the standard way on MacOSX to bundle libraries together to such
frameworks which ideally don’t have further dependencies and can be
bundled
also into an app bundle.


The SDL library in the SDL framework which can be downloaded is
though much
different from SDL if you installed it yourself the Unix way to /
usr/local.

In short: The SDL framework is esp. prepared for running nativly on
MacOSX
and for packaging your application to ship with it. And it is working
standalone and has no further dependencies. And it is a Universal
Binary.

You cannot ship your game if it is linked against the /usr/local/
SDL lib.

  • Albert

i use osx, but mostly a gnu/linux.

matt

On Wed, 4 Mar 2009, Alastair Lynn wrote:

Hi Daniel-

You’ll need to use a file called SDLMain.m (and possibly
SDLMain.h in
older versions) which you can find on google. You’ll need to link
your
application against that, and against Cocoa.framework using -
framework Cocoa
in gcc. I personally suggest you consider using the SDL
frameworks which are
available on libsdl.org as UB and linking against them with -
framework SDL.

Alastair

On 4 Mar 2009, at 10:53, Daniel Waite wrote:

I know this has been posted about before, but the threads I have
seen
have not helped.
I am on OS 10.5.6. I have compiled SDL using ./configure;make;make
install.
This is the code I am attempting to compile:
http://pastie.org/406982
This is the command I am using to compile it:
gcc test.c
The output is:
Undefined symbols:
"_main", referenced from:
start in crt1.10.5.o
"_SDL_Init", referenced from:
_SDL_main in ccd8bu8C.o
"_SDL_Quit", referenced from:
_SDL_main in ccd8bu8C.o
"_SDL_GetKeyName", referenced from:
_SDL_main in ccd8bu8C.o
"_SDL_GetError", referenced from:
_SDL_main in ccd8bu8C.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
I do not want to use XCode or anything related to it.
Any helps/ideas/pointers are much appreciated.

  • Daniel

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

-------------- next part --------------
A non-text attachment was scrubbed…
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3912 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20090304/eb3e2b43/attachment.bin

@Alastair

nods I will definitely keep that in mind when the time comes. Thanks again. :slight_smile:

  • Daniel—

On Wed, Mar 4, 2009 at 1:13 PM, Alastair Lynn wrote:

Hi Daniel-

If you’re going for distribution of a game you’ll need to build an
application bundle, and whilst that’s possible from the command line, you’ll
probably find it easier to use Xcode :slight_smile:

Alastair

On 4 Mar 2009, at 20:54, Daniel Waite wrote:

@Albert

Thanks for all that information. Especially good to know about
distribution! (Not that I intend to distribute anything in the near
future, but nevertheless good to know.)

@Matt

Nice hack there with the back ticks. I’m still new to the command
line, so any help is appreciated in that department.

Thanks again all.

  • Daniel

On Wed, Mar 4, 2009 at 12:26 PM, Albert Zeyer <albert.zeyer at rwth-aachen.de> wrote:

Am 04.03.2009 um 19:52 schrieb mattmatteh at mac.com:

i assume you installed the unix way to /usr/local, sdl-config sould be
in
/usr/local/bin.

which sld-config should show where it is. ?if that fails, you might have
to check your PATH.

gcc sld-config --libs --cflags -o test test.c

-framework i thought was for linking to a library bundle, am i mistaken
?

A framework is just the way on MacOSX to bundle a library (or multiple
libraries) together with headers, resources and other stuff.

With -framework, you link to a whole framework (so to all including
libraries and you also have the header search paths), with -l, you just
link
to a single lib.

It is the standard way on MacOSX to bundle libraries together to such
frameworks which ideally don’t have further dependencies and can be
bundled
also into an app bundle.


The SDL library in the SDL framework which can be downloaded is though
much
different from SDL if you installed it yourself the Unix way to
/usr/local.

In short: The SDL framework is esp. prepared for running nativly on
MacOSX
and for packaging your application to ship with it. And it is working
standalone and has no further dependencies. And it is a Universal Binary.

You cannot ship your game if it is linked against the /usr/local/ SDL
lib.

  • Albert

i use osx, but mostly a gnu/linux.

matt

On Wed, 4 Mar 2009, Alastair Lynn wrote:

Hi Daniel-

You’ll need to use a file called SDLMain.m (and possibly SDLMain.h in
older versions) which you can find on google. You’ll need to link your
application against that, and against Cocoa.framework using -framework
Cocoa
in gcc. I personally suggest you consider using the SDL frameworks
which are
available on libsdl.org as UB and linking against them with -framework
SDL.

Alastair

On 4 Mar 2009, at 10:53, Daniel Waite wrote:

I know this has been posted about before, but the threads I have seen
have not helped.
I am on OS 10.5.6. I have compiled SDL using ./configure;make;make
install.
This is the code I am attempting to compile:
http://pastie.org/406982
This is the command I am using to compile it:
gcc test.c
The output is:
Undefined symbols:
"_main", referenced from:
? start in crt1.10.5.o
"_SDL_Init", referenced from:
? _SDL_main in ccd8bu8C.o
"_SDL_Quit", referenced from:
? _SDL_main in ccd8bu8C.o
"_SDL_GetKeyName", referenced from:
? _SDL_main in ccd8bu8C.o
"_SDL_GetError", referenced from:
? _SDL_main in ccd8bu8C.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
I do not want to use XCode or anything related to it.
Any helps/ideas/pointers are much appreciated.

  • Daniel

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

My
thoughts were, why wouldn’t the SDL READMEs for OS X mention ANY of
this? And if it was not mentioned it “shouldn’t” be relevant. (Goes to
show how much I know…)

This IS all documented.

  1. Read the ReadMeDevLite.txt (included in the devel-lite folder of the
    official SDL dmg binary distribution).

  2. See the official SDL-devel-extras for OS X package. It includes ready to
    use Xcode templates so you don’t really need the above details. A bunch of
    documentation is included in there too.

  3. The Mac OS X section of the SDL FAQ.

-Eric