8

I've just upgraded from 11.4 to 11.10 and at least one thing seems to be broken: I have a C++ program that is using SDL and OpenGL. I was able to compile and run it just fine before the upgrade. Now I get linker errors, for example

undefined reference to `SDL_Init'

I have libsdl1.2debian and libsdl1.2-dev packages installed, I believe that is all I need (but I might be wrong). I compile the program like this:

gcc -I /usr/include/SDL -lSDL -o test test.cpp

Any idea what can be causing this?

adam
  • 871

4 Answers4

18

Ok, solved. Apparently, for some mysterious reason, the order of the gcc options now matters. So when I do:

gcc -I /usr/include/SDL -o test test.cpp -lSDL

(moved the -lSDL option to the end) everthing works just fine. I'd love to know why it suddenly matters, when before if did not, but for now I'm happy that stuff works again.

adam
  • 871
1

For Eclipse: I've same problem, but I resolve.

  • Select project
  • Project>Properties
  • C/C++ Build>Settings - Tool Settings>GCC C Compiler - Include paths (-l)>"/usr/include/SDL"
  • C/C++ Build>Settings - Tool Settings>GCC C Linker - Libraries (-l)>"SDL"
  • Apply

...then build project and run...

1

A simple GNU Makefile for a project which uses SDL:

CXXFLAGS:=(shell pkg-config --cflags sdl2) $(CXXFLAGS)
LDLIBS:=$(shell pkg-config --libs sdl2) $(LDLIBS)

all: test

Where a file test.cpp exists in the same directory as the Makefile.

(Note that I've used sdl2 instead of sdl, since SDL 1.2 is basically dead now.)

GNU make will magically figure out the command for calling g++.

0

In my case, I was using G++ and it didn't work, and switching to GCC it works. I am writing in C though.

Using Code::Blocks, the library flag is -lSDL2