Author Topic: N00b needs help getting C::B to see SDL libraries =P  (Read 8360 times)

4matsy

  • Guest
N00b needs help getting C::B to see SDL libraries =P
« on: January 12, 2006, 08:43:03 am »
Hey there, fellow coders. C::B looks like an impressive piece of work indeed, and I look forward to many (relatively) happy late nights of programming in the future with its help. :D

...if I can get any external libraries working. :P



Okay, so I downloaded and installed C::B, MinGW Windows binaries, and SDL Windows binaries, and they're all living happily in their own lil' directories:
C:\cpp\codeblocks
C:\cpp\mingw\3.1.0
C:\cpp\sdl\SDL-1.2.9

So after having C::B auto-detect the MinGW install, I decided to go try out some of the example projects included with C::B.

The "Console Application" project works like a charm, compiling and running without a hitch.

The "SDL Application" example, on the other hand, is where I run into trouble. :P

A bunch of errors come up regarding main.cpp, saying "(insert SDL-related function here) undeclared"; preceding all these is "main.cpp:6:17: SDL.h: No such file or directory", pointing of course to the "#include <SDL/SDL.h>" line.

Apparently something somewhere doesn't know where the SDL libraries are located. Well, that doesn't seem too hard to fix, or so I thought. :roll:

The thing is, I know that somehow I've got to tell the compiler and/or linker where to look for SDL, but don't really know how to accomplish this.
I've already tried putting various directories (usually C:\cpp\sdl\SDL-1.2.9\lib) in the list under Project -> Build options -> Directories -> Linker, but that isn't doing the trick.



I get the feeling I've missed something ridiculously obvious here...does anyone have an idea what that might be?

Thanks in advance. :)

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Re: N00b needs help getting C::B to see SDL libraries =P
« Reply #1 on: January 12, 2006, 08:50:45 am »
Quote
A bunch of errors come up regarding main.cpp, saying "(insert SDL-related function here) undeclared"; preceding all these is "main.cpp:6:17: SDL.h: No such file or directory", pointing of course to the "#include <SDL/SDL.h>" line.
this is a compiler error  so the compiler cant find the SDL.h file. therefore add the directory to the
Project -> Build options -> Directories -> Compiler
list of directories where the compiler should search for files - isn't that easy ?
be shure, that you give the path to below the SDL directory, if you want  to include <SDL\SDL.h>

Quote
I've already tried putting various directories (usually C:\cpp\sdl\SDL-1.2.9\lib) in the list under Project -> Build options -> Directories -> Linker, but that isn't doing the trick.
that is ok and necessary too for the linker !!

Offline takeshi miya

  • Lives here!
  • ****
  • Posts: 1487
Re: N00b needs help getting C::B to see SDL libraries =P
« Reply #2 on: January 12, 2006, 08:54:18 am »
Go to Settings->Compiler Settings->Directories tab.

In the compiler tab, add C:\cpp\sdl\SDL-1.2.9\include\SDL.
In the linker tab, add C:\cpp\sdl\SDL-1.2.9\lib.

And in your main.cpp, replace the #include <SDL/SDL.h> by #include <SDL.h> which is the correct way to do it.

Hope that helps :)

EDIT: tiwag won me :P

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Re: N00b needs help getting C::B to see SDL libraries =P
« Reply #3 on: January 12, 2006, 09:07:42 am »
Go to Settings->Compiler Settings->Directories tab.

In the compiler tab, add C:\cpp\sdl\SDL-1.2.9\include\SDL.
In the linker tab, add C:\cpp\sdl\SDL-1.2.9\lib.
i prefer not to put these things globally because with time you maybe have several versions of the same library
and some of your older apps compile well only with older versions - see wxWidgets as good example for it.
So if you want keep your apps compiling as they were - it is a good advice to put all of your pathes needed for
linker and compiler and anything else what's needed to build your app into your project-information.
This initially is maybe a little bit more work, but saves you a lot of work in the future.

Quote
And in your main.cpp, replace the #include <SDL/SDL.h> by #include <SDL.h> which is the correct way to do it.
maybe it is a matter of taste, but i would let it be included as <SDL\sdl.h> and only give the right path that this works (no path necessary if copying the SDL header directory in your global mingw\include directory for example.
this way you see on the first sight, from which library your included headers come (if they have not a so obvious name than sdl.h :) )

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4291
    • Code::Blocks IDE
Re: N00b needs help getting C::B to see SDL libraries =P
« Reply #4 on: January 12, 2006, 09:12:19 am »
Look no further: Using SDL with Code::Blocks.
Be patient!
This bug will be fixed soon...

4matsy

  • Guest
Re: N00b needs help getting C::B to see SDL libraries =P
« Reply #5 on: January 12, 2006, 11:01:49 am »
That's odd...at one point I could've sworn I set the compiler directory too, but when I checked, sure enough it was blank...whoops! :oops:

Thanks so much for the help, guys. It's working perfectly now. :D

Offline takeshi miya

  • Lives here!
  • ****
  • Posts: 1487
Re: N00b needs help getting C::B to see SDL libraries =P
« Reply #6 on: January 13, 2006, 11:51:31 pm »
i prefer not to put these things globally because with time you maybe have several versions of the same library
and some of your older apps compile well only with older versions - see wxWidgets as good example for it.
So if you want keep your apps compiling as they were - it is a good advice to put all of your pathes needed for
linker and compiler and anything else what's needed to build your app into your project-information.
This initially is maybe a little bit more work, but saves you a lot of work in the future.
I have to disagree, it's adviced for libraries like wxWidgets, or libraries that changes often.

However, SDL API is extremely stable, the libraries are released with a very slow phase, so usually you'll change it one time in a year.
For a newbie, we shouldn't complicate things.

Another option could have been using Global Variables in the SDL project template.

maybe it is a matter of taste, but i would let it be included as <SDL\sdl.h> and only give the right path that this works (no path necessary if copying the SDL header directory in your global mingw\include directory for example.
this way you see on the first sight, from which library your included headers come (if they have not a so obvious name than sdl.h :) )
I have to disagree also here. It's not a matter of taste, because the standard way (of most SDL apps) is "sdl.h". In linux for example, there isn't any <SDL\sdl.h>, so your program willn't compile.

Also, putting slashes in that path is not portable between platforms and compilers.