News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

Default sdl code won't compile in Code::Blocks

Started by Jerrac, August 09, 2009, 09:19:09 PM

Previous topic - Next topic

Jerrac

I am using the default SDL code provided by the SDL wizard in Codeblocks. It will not compile. Keeps giving me "undefined reference" errors for all the SDL_ functions.

I am using Ubuntu 9.04.

If I compile it manually like this:
Quotedavid@tux-alteria:~/workspace/ProjectWhite$ g++ `sdl-config --cflags` -c main.cpp
david@tux-alteria:~/workspace/ProjectWhite$ g++ -o main `sdl-config --libs` main.o
It works fine.

How can I get it to find the functions correctly?

Jenna

Please post the build log after changing compiler logging to full commandline (change "Settings -> Compiler and debugger... -> Global compiler settings -> [the compiler you use] -> Other settings(rightmost tab)" "Compiler logging" to "Full commandline") .

Jerrac

So, this?
Quote
-------------- Build: Debug in ProjectWhite ---------------

g++   -g      -c /home/david/workspace/ProjectWhite/main.cpp -o obj/Debug/main.o
g++  -o bin/Debug/ProjectWhite obj/Debug/main.o     
obj/Debug/main.o: In function `main':
/home/david/workspace/ProjectWhite/main.cpp:15: undefined reference to `SDL_Init'
/home/david/workspace/ProjectWhite/main.cpp:17: undefined reference to `SDL_GetError'
/home/david/workspace/ProjectWhite/main.cpp:22: undefined reference to `SDL_Quit'
/home/david/workspace/ProjectWhite/main.cpp:26: undefined reference to `SDL_SetVideoMode'
/home/david/workspace/ProjectWhite/main.cpp:29: undefined reference to `SDL_GetError'
/home/david/workspace/ProjectWhite/main.cpp:34: undefined reference to `SDL_RWFromFile'
/home/david/workspace/ProjectWhite/main.cpp:34: undefined reference to `SDL_LoadBMP_RW'
/home/david/workspace/ProjectWhite/main.cpp:37: undefined reference to `SDL_GetError'
/home/david/workspace/ProjectWhite/main.cpp:52: undefined reference to `SDL_PollEvent'
/home/david/workspace/ProjectWhite/main.cpp:76: undefined reference to `SDL_MapRGB'
/home/david/workspace/ProjectWhite/main.cpp:76: undefined reference to `SDL_FillRect'
/home/david/workspace/ProjectWhite/main.cpp:79: undefined reference to `SDL_UpperBlit'
/home/david/workspace/ProjectWhite/main.cpp:84: undefined reference to `SDL_Flip'
/home/david/workspace/ProjectWhite/main.cpp:88: undefined reference to `SDL_FreeSurface'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
14 errors, 0 warnings


Jenna

Did you install the libsdlx.x-dev package after creating the project ?
C::B caches the backticked expressions if they are first used.
If you install the appropriate package after the first use of the expressions, you have to close and reopen C::B (not only the project).

Jerrac

Ah, I did install the sdl dev package afterwards. Restarting Codeblocks worked. Thanks!