Noob vs. compiler

Hi,

I’d like to write my own mixer application using SDL_audio, but I’ve been unable
to get past some difficulties in building the example code I found here:
http://de.wikibooks.org/wiki/SDL:_Audio
Compiling in Xcode gives me this:

“_SDL_main”, referenced from:
-[SDLMain applicationDidFinishLaunching:] in SDLMain.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Compiling from the command line yields more info:

$ gcc -Wall main.cpp
main.cpp: In function ‘void Callback(void*, Uint8*, int)’:
main.cpp:23: warning: comparison between signed and unsigned integer expressions
Undefined symbols:
"_SDL_OpenAudio", referenced from:
play() in ccZ1Afdo.o
"___gxx_personality_v0", referenced from:
___gxx_personality_v0$non_lazy_ptr in ccZ1Afdo.o
"_SDL_RWFromFile", referenced from:
play() in ccZ1Afdo.o
"_main", referenced from:
start in crt1.10.5.o
"_SDL_MixAudio", referenced from:
Callback(void*, unsigned char*, int)in ccZ1Afdo.o
"_SDL_Delay", referenced from:
SDL_main() in ccZ1Afdo.o
"_SDL_LoadWAV_RW", referenced from:
play() in ccZ1Afdo.o
"_SDL_Init", referenced from:
init_sdl() in ccZ1Afdo.o
"_SDL_PauseAudio", referenced from:
play() in ccZ1Afdo.o
"_SDL_Quit", referenced from:
_SDL_Quit$non_lazy_ptr in ccZ1Afdo.o
"_SDL_GetError", referenced from:
play() in ccZ1Afdo.o
"_SDL_SetVideoMode", referenced from:
init_sdl() in ccZ1Afdo.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

It’s probably pretty obvious that I’m relatively new both to C++ and to
developing on Unix-like system, so this compiler output has me somewhat
mystified. I’ve deciphered that the linker can’t resolve the SDL functions
referenced in the object file dropped by the compiler, but that doesn’t leave me
much the wiser regarding what to do about it. I’ve re-copied SDL.framework to
/Library/Frameworks/ from the distribution .dmg with no success, so I’m guessing
there’s something obvious I need to tell the linker… but what?
Could someone shed some light? I’d appreciate it.

Z

At the very least you need to be linking to SDL. In Mac OS X that’s
going to require this flag:

-framework SDL

That’ll also add the SDL headers to the #include search patch for your
compiler, IIRC. Also IIRC, when using SDL.framework, you’ll need to
make sure you’re including SDL/SDL.h instead of just SDL.h.

Lastly, you might still get an SDL_main linker error. Someone else can
help you out with that because I didn’t use the framework when I was
developing on Mac OS X.On Wed, Jan 21, 2009 at 4:05 PM, Z wrote:

Hi,

I’d like to write my own mixer application using SDL_audio, but I’ve been unable
to get past some difficulties in building the example code I found here:
http://de.wikibooks.org/wiki/SDL:_Audio
Compiling in Xcode gives me this:

“_SDL_main”, referenced from:
-[SDLMain applicationDidFinishLaunching:] in SDLMain.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Compiling from the command line yields more info:

$ gcc -Wall main.cpp
main.cpp: In function ‘void Callback(void*, Uint8*, int)’:
main.cpp:23: warning: comparison between signed and unsigned integer expressions
Undefined symbols:
"_SDL_OpenAudio", referenced from:
play() in ccZ1Afdo.o
"___gxx_personality_v0", referenced from:
___gxx_personality_v0$non_lazy_ptr in ccZ1Afdo.o
"_SDL_RWFromFile", referenced from:
play() in ccZ1Afdo.o
"_main", referenced from:
start in crt1.10.5.o
"_SDL_MixAudio", referenced from:
Callback(void*, unsigned char*, int)in ccZ1Afdo.o
"_SDL_Delay", referenced from:
SDL_main() in ccZ1Afdo.o
"_SDL_LoadWAV_RW", referenced from:
play() in ccZ1Afdo.o
"_SDL_Init", referenced from:
init_sdl() in ccZ1Afdo.o
"_SDL_PauseAudio", referenced from:
play() in ccZ1Afdo.o
"_SDL_Quit", referenced from:
_SDL_Quit$non_lazy_ptr in ccZ1Afdo.o
"_SDL_GetError", referenced from:
play() in ccZ1Afdo.o
"_SDL_SetVideoMode", referenced from:
init_sdl() in ccZ1Afdo.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

It’s probably pretty obvious that I’m relatively new both to C++ and to
developing on Unix-like system, so this compiler output has me somewhat
mystified. I’ve deciphered that the linker can’t resolve the SDL functions
referenced in the object file dropped by the compiler, but that doesn’t leave me
much the wiser regarding what to do about it. I’ve re-copied SDL.framework to
/Library/Frameworks/ from the distribution .dmg with no success, so I’m guessing
there’s something obvious I need to tell the linker… but what?
Could someone shed some light? I’d appreciate it.

Z


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


http://codebad.com/

You’ll need a file called SDLMain.m - importing that into your project
should fix the problem.

I suggest this version: http://github.com/prophile/xsera/blob/38f1b13866d04fe13520ceada15d169f6ebc3c2e/External/SDLMain.m

AlastairOn 21 Jan 2009, at 21:19, Donny Viszneki wrote:

At the very least you need to be linking to SDL. In Mac OS X that’s
going to require this flag:

-framework SDL

That’ll also add the SDL headers to the #include search patch for your
compiler, IIRC. Also IIRC, when using SDL.framework, you’ll need to
make sure you’re including SDL/SDL.h instead of just SDL.h.

Lastly, you might still get an SDL_main linker error. Someone else can
help you out with that because I didn’t use the framework when I was
developing on Mac OS X.

On Wed, Jan 21, 2009 at 4:05 PM, Z wrote:

Hi,

I’d like to write my own mixer application using SDL_audio, but
I’ve been unable
to get past some difficulties in building the example code I found
here:
http://de.wikibooks.org/wiki/SDL:_Audio
Compiling in Xcode gives me this:

“_SDL_main”, referenced from:
-[SDLMain applicationDidFinishLaunching:] in SDLMain.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Compiling from the command line yields more info:

$ gcc -Wall main.cpp
main.cpp: In function ‘void Callback(void*, Uint8*, int)’:
main.cpp:23: warning: comparison between signed and unsigned
integer expressions
Undefined symbols:
"_SDL_OpenAudio", referenced from:
play() in ccZ1Afdo.o
"___gxx_personality_v0", referenced from:
___gxx_personality_v0$non_lazy_ptr in ccZ1Afdo.o
"_SDL_RWFromFile", referenced from:
play() in ccZ1Afdo.o
"_main", referenced from:
start in crt1.10.5.o
"_SDL_MixAudio", referenced from:
Callback(void*, unsigned char*, int)in ccZ1Afdo.o
"_SDL_Delay", referenced from:
SDL_main() in ccZ1Afdo.o
"_SDL_LoadWAV_RW", referenced from:
play() in ccZ1Afdo.o
"_SDL_Init", referenced from:
init_sdl() in ccZ1Afdo.o
"_SDL_PauseAudio", referenced from:
play() in ccZ1Afdo.o
"_SDL_Quit", referenced from:
_SDL_Quit$non_lazy_ptr in ccZ1Afdo.o
"_SDL_GetError", referenced from:
play() in ccZ1Afdo.o
"_SDL_SetVideoMode", referenced from:
init_sdl() in ccZ1Afdo.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

It’s probably pretty obvious that I’m relatively new both to C++
and to
developing on Unix-like system, so this compiler output has me
somewhat
mystified. I’ve deciphered that the linker can’t resolve the SDL
functions
referenced in the object file dropped by the compiler, but that
doesn’t leave me
much the wiser regarding what to do about it. I’ve re-copied
SDL.framework to
/Library/Frameworks/ from the distribution .dmg with no success, so
I’m guessing
there’s something obvious I need to tell the linker… but what?
Could someone shed some light? I’d appreciate it.

Z


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


http://codebad.com/


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/20090121/e9098677/attachment.bin

Thanks for the prompt replies!
Building with the -framework SDL flag eliminated most of the undefined symbols.
Adding #include <SDLMain.m> to main.cpp got the rest, so something’s working
there, but all is not yet joyful happiness:

$ gcc -Wall main.cpp -framework SDL
main.cpp:3:21: error: SDLMain.m: No such file or directory

I don’t understand how it’s resolving the previously undefined symbols when it
can’t find the file it needed for just that. I’m sure there’s a perfectly
reasonable explanation; care to clue me in? I put SDLMain.m in the same
directory as main.cpp, which is where Xcode had already put its own version.
Donny, you said you didn’t use the framework, which prompted me to research the
alternative. I now realize I should have mentioned right away that I’m
interested in cross-platform compatibility, and would prefer to use a text
editor and gcc rather than Xcode anyway. To that end, I’ve downloaded and
successfully installed the tarball SDL distribution.
The compiler output is the same, however, whether I build with -framework SDL or
not. Assist please.

Z

Z skrev:

Thanks for the prompt replies!
Building with the -framework SDL flag eliminated most of the undefined symbols.
Adding #include <SDLMain.m> to main.cpp got the rest, so something’s working
there, but all is not yet joyful happiness:

$ gcc -Wall main.cpp -framework SDL
main.cpp:3:21: error: SDLMain.m: No such file or directory

I don’t understand how it’s resolving the previously undefined symbols when it
can’t find the file it needed for just that. I’m sure there’s a perfectly
reasonable explanation; care to clue me in?
It does not try to resolve any symbols if it can not even compile the
source file because of a missing include.

Z <fiat42lux gmail.com> writes:

$ gcc -Wall main.cpp

Undefined symbols:

Undefined symbols are reported by the linker.
You have to link libSDL (which should be somwhere in your lib directory):
“gcc -Wall main.cpp -lSDL”

Erik <esigra gmail.com> writes:

It does not try to resolve any symbols if it can not even compile the
source file because of a missing include.

Um, right. Duh is me. Thanks.
So I read about including and changed my #include to use quotes instead of
angle-brackets. This appears to work, but now I get a mess that starts like
this:

$ gcc -Wall main.cpp
In file included from
/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:12,
from /System/Library/Frameworks/Cocoa.framework/Headers/Cocoa.h:12,
from SDLMain.m:11,
from main.cpp:2:
/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:124:
error: stray ‘@’ in program

…and continues for many pages, mentioning stray @s in various items in
/System/Library/Frameworks. Sigh. Any suggestions?

Z

SDLmain.m is an objectve-c source file, and you are including it as
part of C++ source code.

Remove the #include <SDLMain.m> directive and add SDLMain.m (full path
if necessary) to your compiler command. I think gcc will automatically
recognize the source type and compile it as Objective-C instead of as
C++ (gcc is after all the C compiler command, and it isn’t choking on
your C++ program, although perhaps you aren’t using any C++ syntax.)
In general the gcc compiler commands are pretty flexible in knowing
which compilers and which linkers and flags to add for the most
typical invocations.On Fri, Jan 23, 2009 at 10:54 AM, Z wrote:

Erik <esigra gmail.com> writes:

It does not try to resolve any symbols if it can not even compile the
source file because of a missing include.

Um, right. Duh is me. Thanks.
So I read about including and changed my #include to use quotes instead of
angle-brackets. This appears to work, but now I get a mess that starts like
this:

$ gcc -Wall main.cpp
In file included from
/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:12,
from /System/Library/Frameworks/Cocoa.framework/Headers/Cocoa.h:12,
from SDLMain.m:11,
from main.cpp:2:
/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:124:
error: stray ‘@’ in program

…and continues for many pages, mentioning stray @s in various items in
/System/Library/Frameworks. Sigh. Any suggestions?

Z


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


http://codebad.com/

I agree with Donny about SDLMain.m, but I wanted to make sure you are
linking all the necessary libraries correctly.

when I have used SDL on mac osx, I used something akin to:
-framework Cocoa -lSDL -lSDLmain -lSDL_mixer

in your case, you could try:
gcc main.cpp -Wall -framework Cocoa -lSDL -lSDLmain -lSDL_mixer

JohnOn Fri, Jan 23, 2009 at 10:15 AM, Donny Viszneki <donny.viszneki at gmail.com> wrote:

SDLmain.m is an objectve-c source file, and you are including it as
part of C++ source code.

Remove the #include <SDLMain.m> directive and add SDLMain.m (full path
if necessary) to your compiler command. I think gcc will automatically
recognize the source type and compile it as Objective-C instead of as
C++ (gcc is after all the C compiler command, and it isn’t choking on
your C++ program, although perhaps you aren’t using any C++ syntax.)
In general the gcc compiler commands are pretty flexible in knowing
which compilers and which linkers and flags to add for the most
typical invocations.

On Fri, Jan 23, 2009 at 10:54 AM, Z wrote:

Erik <esigra gmail.com> writes:

It does not try to resolve any symbols if it can not even compile the
source file because of a missing include.

Um, right. Duh is me. Thanks.
So I read about including and changed my #include to use quotes instead of
angle-brackets. This appears to work, but now I get a mess that starts like
this:

$ gcc -Wall main.cpp
In file included from
/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:12,
from /System/Library/Frameworks/Cocoa.framework/Headers/Cocoa.h:12,
from SDLMain.m:11,
from main.cpp:2:
/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:124:
error: stray ‘@’ in program

…and continues for many pages, mentioning stray @s in various items in
/System/Library/Frameworks. Sigh. Any suggestions?

Z


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


http://codebad.com/


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

Not if he’s using the SDL and SDL_mixer frameworks. It’s clear that
he’s using the SDL framework, and he’s probably using the SDL_mixer
framework.

In that case the Apple extensions to gcc allow you to use a simpler
command line option for specifying flags like -L -l and -I, which is
just the -framework option.

Also, if you are using the SDL_mixer framework, you can’t #include
SDL/SDL_mixer.h, you’ll have to include SDL_mixer/SDL_mixer.h

I don’t know if this is the best option, I’ve seen people use
different macros over the years, but I use #if defined(MACH) &&
defined(APPLE) to check for the Mac OS X platform and then I
assume I’m using frameworks. The boilerplate CPP macros at the
beginning of each file will look pretty much like this:

#if defined(MACH) && defined(APPLE)

include <SDL/SDL.h>

include <SDL/SDL_mixer.h>

include <OpenGL/GL.h>

include <OpenGL/GLU.h>

include <GLUT/GLUT.h>

#else

include <SDL.h>

include <SDL_mixer.h>

include <GL/gl.h>

include <GL/glu.h>

include <GL/glut.h>

#endif

I can’t remember the actual case on the Mac OS X header filenames, but
the default Mac OS X filesystems are case-insensitive anyhow, so you
don’t have to worry about that.

Also, obviously don’t include the GL, GLU, or GLUT headers if you
don’t need them, I was just giving the demonstration for posterity.On Fri, Jan 23, 2009 at 11:23 AM, John Magnotti <john.magnotti at auburn.edu> wrote:

I agree with Donny about SDLMain.m, but I wanted to make sure you are
linking all the necessary libraries correctly.

when I have used SDL on mac osx, I used something akin to:
-framework Cocoa -lSDL -lSDLmain -lSDL_mixer

in your case, you could try:
gcc main.cpp -Wall -framework Cocoa -lSDL -lSDLmain -lSDL_mixer


http://codebad.com/

Not if he’s using the SDL and SDL_mixer frameworks. It’s clear that
he’s using the SDL framework, and he’s probably using the SDL_mixer
framework.
I thought he mentioned downloading the tar’d sources and using the
libraries he built. my bad :slight_smile:

John

John Magnotti <john.magnotti auburn.edu> writes:

Not if he’s using the SDL and SDL_mixer frameworks. It’s clear that
he’s using the SDL framework, and he’s probably using the SDL_mixer
framework.
I thought he mentioned downloading the tar’d sources and using the
libraries he built. my bad :slight_smile:

Actually you thought right. If possible I’d like to avoid tying my application
to OS X – ideally it would run on all platforms supported by SDL, so I’m really
hoping to get away from frameworks sooner or later. Might I perhaps be better
off bootcamping a Linux distro for development instead?
As for SDL_mixer, actually I mean my application to replace it. My (initial)
purpose isn’t to write something better, but rather to acquire an understanding
of the issues involved in software mixing and audio DSP, so I’d like to get as
close as possible to the bare metal, so to speak. Basically I’d like to SDL
solely to save myself the hassle of dealing with audio file formats…

Z

Actually you thought right. If possible I’d like to avoid tying my application
to OS X – ideally it would run on all platforms supported by SDL, so I’m really
hoping to get away from frameworks sooner or later. Might I perhaps be better
off bootcamping a Linux distro for development instead?

Installing a supplementary operating system is your prerogative, but
don’t do it to get away from Mac OS X dependence. Here’s why:

The C macros I gave you make it easy to write code that will compile
on Mac OS X as well as GNU/Linux. Frameworks work better on Mac OS X
than libs installed the traditional GNU/Linux way just because more
users use them. It’s also fairly easy to build your own .app bundle so
you can distribute your app the way that every other OS X application
is.

As for SDL_mixer, actually I mean my application to replace it. My (initial)
purpose isn’t to write something better, but rather to acquire an understanding
of the issues involved in software mixing and audio DSP, so I’d like to get as
close as possible to the bare metal, so to speak.

Have fun! I recommend downloading the SDL_mixer source code!

Honestly, though, unless you are doing something very interesting,
there is no compelling reason not to use SDL_mixer. You can do DSP
with SDL_mixer using hooks which allow you to do post-processing after
the mixing is done.

Basically I’d like to SDL
solely to save myself the hassle of dealing with audio file formats…

SDL can only load WAV files. Did you mean SDL_mixer?On Fri, Jan 23, 2009 at 12:53 PM, Z wrote:


http://codebad.com/