Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 6 down vote accepted

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.

share|improve this answer
    
Maybe you should check the release notes for the version of gcc in 11.10. –  Oxwivi Oct 19 '11 at 14:56
1  
Thanks, very helpfull. You can also completly turn around the order to gcc -o test test.cpp -I /usr/include/SDL -lSDL which is useful when you use pkg-config as you can then still get the cflags and libs in one go like gcc -o test test.cpp `pkg-config --cflags --libs sdl` –  Eelke Jun 15 '12 at 4:51

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...

share|improve this answer

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++.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.