I went to compile a project of mine, which uses SDL, SDL_ttf, OpenAL, and GTK. All of which are outputting errors like the following:
TxtFunc.cpp:(.text+0x61): undefined reference to `TTF_OpenFont'
TxtFunc.cpp:(.text+0x8c): undefined reference to `TTF_RenderText_Solid'
TxtFunc.cpp:(.text+0xf6): undefined reference to `SDL_UpperBlit'
TxtFunc.cpp:(.text+0x108): undefined reference to `TTF_CloseFont'
TxtFunc.cpp:(.text+0x114): undefined reference to `SDL_FreeSurface'
for every library call. I am compiling with the following link options:
sdl-config --libs
pkg-config gtk+-2.0 --libs
pkg-config openal --libs
-lalut -lSDL_ttf
I have all of these packages installed, and there are no "file not found" errors. Just a lot of undefined references... It didn't make sense, so I wrote up a quick test application:
#include "SDL/SDL.h"
int main()
{
SDL_Init(SDL_INIT_VIDEO);
return 0;
}
and compile like so:
g++ `sdl-config --libs --cflags` -o sdl-test ./sdl-test.cpp
I have even tried linking directly to "/usr/lib/libSDL-1.2.so.0" or "/usr/lib/libSDL.a" instead
all of these options end up with the same output:
/tmp/cc05XT8U.o: In function `main':
sdl-test.cpp:(.text+0xa): undefined reference to `SDL_Init'
collect2: ld returned 1 exit status
Anybody have any ideas?
Gah, which pillock got the idea to change the compiler to rely now on the order of options in the command line?
Well,that fixed my problem too, just moved ($CFLAGS) after ($OBJS) in my Makefile and all my linking problems with unknown references to SDL libs are gone >.<
Generally you need to have your -l options after the files that use the symbols on the command line. Perhaps try moving the
sdl-config --libs --cflags
to the end of the command? i.e. for your test program:In case you use SDL_ttf, you need to