Pregunta

I'm working with the SDL and SDL_mixer library and am getting the following errors when I compile:

....
game.cpp:(.text+0x88f): undefined reference to `Mix_OpenAudio'
Jukebox.o: In function `Jukebox::~Jukebox()':
Jukebox.cpp:(.text+0x17): undefined reference to `Mix_FreeChunk'
Jukebox.cpp:(.text+0x27): undefined reference to `Mix_FreeChunk'
Jukebox.cpp:(.text+0x37): undefined reference to `Mix_FreeChunk'
Jukebox.cpp:(.text+0x47): undefined reference to `Mix_FreeChunk'
....

And so on and so forth or all instances when I use a SDL_mixer function.

I'm fairly confident that the error lies within the Makefile because it compiles just fine in another test program I made.

My Makefile

SDL= -lSDL -lSDL_mixer

OBJ=game.o Jukebox.o ...

all:    main

main:   $(OBJ)
        g++ $(SDL) $(OBJ) -o main

%.o:    %.cpp
        g++ $(SDL) -c $<

clean:
        rm -f *.o *~ main
        rm -f */*~

Where is the error?

¿Fue útil?

Solución

I think the problem is the order of your arguments.

Instead of

main:   $(OBJ)
        g++ $(SDL) $(OBJ) -o main

try

main:   $(OBJ)
        g++ -o main $(OBJ) $(SDL) 

While the position of -o main is not really important, the order of the link libraries is. Compilers resolve the symbols in the order the libraries appear on the command line.

Otros consejos

It seems that you linker cannot find where the libraries are located. Identify where they were installed and pass this path to the linker via -L directive.

Put something like this: SDL= -L/path/to/installed/SDL/libraries -lSDL -lSDL_mixer

Note that, in: g++ $(SDL) -c $< the variable $(SDL) is irrelevant, once your are not linking into your program, but just generating the objects.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top