Author Topic: How can I use SDL_ttf with code blocks?  (Read 12165 times)

Offline Zamp

  • Multiple posting newcomer
  • *
  • Posts: 26
How can I use SDL_ttf with code blocks?
« on: October 13, 2007, 03:07:54 am »
I've been learning SDL recently by using Lazy Foo's tutorials, and I can't get get SDL_ttf to work. I'm using the Sept 10 build of Code Blocks for openSUSE 10.2.

I went to the SDL website, and downloaded the development rpm file, and when I did that it got installed with openSUSEs Install Software program, and it said it installed successfully, so I thought everything was fine. Then I tried to use it in my current program I'm making, and it doesn't work. In the Build Options then linker settings, I added 'SDL_ttf' ( no quotes), and added #include <SDL_ttf.h> to the top and it doesn't work. When I installed SDL_image, all I did was install the rpm and add 'SDL_image' to the linker options, and #include <SDL_image.h>, and that works fine. So how exactly do I get it to work? I even copy and pasted Lazy Foo's whole program and tried to compile it, but it didn't work either.

When I try to compile it, I get this error:

Code
:: === Pong, Debug ===
/usr/lib/libSDL_ttf.a(SDL_ttf.o):: In function `TTF_Quit':
(.text+0x269):: undefined reference to `FT_Done_FreeType'
/usr/lib/libSDL_ttf.a(SDL_ttf.o):: In function `Find_Glyph':
(.text+0x3af):: undefined reference to `FT_Load_Glyph'
/usr/lib/libSDL_ttf.a(SDL_ttf.o):: In function `Find_Glyph':
(.text+0x4ed):: undefined reference to `FT_Render_Glyph'
/usr/lib/libSDL_ttf.a(SDL_ttf.o):: In function `Find_Glyph':
(.text+0x727):: undefined reference to `FT_Get_Char_Index'
/usr/lib/libSDL_ttf.a(SDL_ttf.o):: In function `Find_Glyph':
(.text+0x745):: undefined reference to `FT_Render_Glyph'
/usr/lib/libSDL_ttf.a(SDL_ttf.o):: In function `Find_Glyph':
(.text+0x7a1):: undefined reference to `FT_Outline_Transform'
/usr/lib/libSDL_ttf.a(SDL_ttf.o):: In function `TTF_SizeUNICODE':
(.text+0x1252):: undefined reference to `FT_Get_Kerning'
/usr/lib/libSDL_ttf.a(SDL_ttf.o):: In function `TTF_RenderUNICODE_Blended':
(.text+0x15f5):: undefined reference to `FT_Get_Kerning'
/usr/lib/libSDL_ttf.a(SDL_ttf.o):: In function `TTF_RenderUNICODE_Shaded':
(.text+0x19d1):: undefined reference to `FT_Get_Kerning'
/usr/lib/libSDL_ttf.a(SDL_ttf.o):: In function `TTF_RenderUNICODE_Solid':
(.text+0x2077):: undefined reference to `FT_Get_Kerning'
/usr/lib/libSDL_ttf.a(SDL_ttf.o):: In function `TTF_CloseFont':
(.text+0x21bf):: undefined reference to `FT_Done_Face'
/usr/lib/libSDL_ttf.a(SDL_ttf.o):: In function `TTF_OpenFontIndexRW':
(.text+0x2349):: undefined reference to `FT_Open_Face'
/usr/lib/libSDL_ttf.a(SDL_ttf.o):: In function `TTF_OpenFontIndexRW':
(.text+0x2399):: undefined reference to `FT_Set_Pixel_Sizes'
/usr/lib/libSDL_ttf.a(SDL_ttf.o):: In function `TTF_OpenFontIndexRW':
(.text+0x2457):: undefined reference to `FT_Set_Char_Size'
/usr/lib/libSDL_ttf.a(SDL_ttf.o):: In function `TTF_OpenFontIndexRW':
(.text+0x2475):: undefined reference to `FT_MulFix'
/usr/lib/libSDL_ttf.a(SDL_ttf.o):: In function `TTF_OpenFontIndexRW':
(.text+0x2491):: undefined reference to `FT_MulFix'
/usr/lib/libSDL_ttf.a(SDL_ttf.o):: In function `TTF_OpenFontIndexRW':
(.text+0x24b8):: undefined reference to `FT_MulFix'
/usr/lib/libSDL_ttf.a(SDL_ttf.o):: In function `TTF_OpenFontIndexRW':
(.text+0x24d4):: undefined reference to `FT_MulFix'
/usr/lib/libSDL_ttf.a(SDL_ttf.o):: In function `TTF_OpenFontIndexRW':
(.text+0x24ed):: undefined reference to `FT_MulFix'
/usr/lib/libSDL_ttf.a(SDL_ttf.o):: In function `TTF_Init':
(.text+0x2698):: undefined reference to `FT_Init_FreeType'
:: === Build finished: 20 errors, 0 warnings ===

Offline Auria

  • Almost regular
  • **
  • Posts: 152
Re: How can I use SDL_ttf with code blocks?
« Reply #1 on: October 13, 2007, 03:34:10 am »
Seems like you need to install FreeType and link against it

Offline Zamp

  • Multiple posting newcomer
  • *
  • Posts: 26
Re: How can I use SDL_ttf with code blocks?
« Reply #2 on: October 13, 2007, 04:05:23 am »
Ah alright thanks. That seemed to fix it =D

Offline Zamp

  • Multiple posting newcomer
  • *
  • Posts: 26
Re: How can I use SDL_ttf with code blocks?
« Reply #3 on: October 13, 2007, 04:10:29 pm »
I have another question. Like I said before, I'm using the Sept 10 CodeBlocks build for openSUSE 10.2. How can I compile a project so there is an executable that I can run the game from? Right now the only way I know how to run it is open up C::B and click the build and run button, but lets say I made a cool program I wanted to share with my friends and they didn't have Code::Blocks, how could I make an executable or some kind a file that will run the game without needing Code::Blocks installed?

In the folder where the project is saved, theres a folder called bin and inside that are two more folders called Debug and Release. In both of those folders is a file called Pong and it says it is executable, but when I try to run it, it opens up real quick and closes. So yeah...

>__> Hopefully that made sense. Basically, how can I run the program without having to open up Code::Blocks first?

Offline Auria

  • Almost regular
  • **
  • Posts: 152
Re: How can I use SDL_ttf with code blocks?
« Reply #4 on: October 13, 2007, 05:24:26 pm »
The executable you're mentionning is what you want. Try running it from the terminal to see what's going wrong.

They will also need to install required dependencies, of course. You may want to read about making debs/rpms/autopackages/etc. for more info on distribtuing stuff on linux (i don't know what suse uses)

Offline JGM

  • Lives here!
  • ****
  • Posts: 518
  • Got to practice :)
Re: How can I use SDL_ttf with code blocks?
« Reply #5 on: October 13, 2007, 06:16:59 pm »
>__> Hopefully that made sense. Basically, how can I run the program without having to open up Code::Blocks first?

Maybe your executable use resources that can't find in the bin directory. When you run the program from codeblocks it uses the main project directory as the Current Working Directory. For example, if your file structure is like this:

MainProject //main project directory
  - bin //where executables reside
  - images //Some resources
  - include
  - src

Well, if you run the executable directly from bin it will not find the images, so you will have to copy the folder of images inside the folder where the executable resides. Hopes it helps.

Offline Zamp

  • Multiple posting newcomer
  • *
  • Posts: 26
Re: How can I use SDL_ttf with code blocks?
« Reply #6 on: October 13, 2007, 06:23:39 pm »
When I try to run from the terminal it just does the same thing, show the black screen then disappear. It doesn't say anything in the terminal about it, all it says the folder name that it always shows before you type a command.

And I'm not really trying to distribute this, I was just saying that to help make what I said make more sense. >___>

Also, I put the images and .ttf file I was using in the same directory as the bin, and it still doesn't work. I even put the executable in the main project folder and tried to run it, but it still didn't work =/

Offline Auria

  • Almost regular
  • **
  • Posts: 152
Re: How can I use SDL_ttf with code blocks?
« Reply #7 on: October 13, 2007, 07:58:21 pm »
It sounds like your code does not perform any error checking. When your code loads resources, you should check for success and display an error message upon failure.

Offline Zamp

  • Multiple posting newcomer
  • *
  • Posts: 26
Re: How can I use SDL_ttf with code blocks?
« Reply #8 on: October 13, 2007, 09:49:05 pm »
I do have error checking, I just never had it do anything except close the program. >_> But I just added error messages and it still doesn't say anything.

But if I try to run the Debug one from the terminal it will run, and I put a message at the end saying it finished, and it shows that in the terminal, but it won't run if I just click on it. Also, I can't get the one in the Release folder to run at all. It just closes right away, even in the terminal, and doesn't display any message at all.

Offline Auria

  • Almost regular
  • **
  • Posts: 152
Re: How can I use SDL_ttf with code blocks?
« Reply #9 on: October 13, 2007, 10:30:18 pm »
Add some sort of logging to your app to know where it goes... Use a debugger from the terminal... etc.

Offline Zamp

  • Multiple posting newcomer
  • *
  • Posts: 26
Re: How can I use SDL_ttf with code blocks?
« Reply #10 on: October 13, 2007, 11:47:16 pm »
How could I add a logging thing to the program? I put 'cout<<"Hello";' on the very first line of the main function, and it still doesn't show up when I try to run the Release prorgam in the terminal. And it only shows up after I close the program when I run the Debug one.

And how would I use a debugger from the terminal? >_>

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: How can I use SDL_ttf with code blocks?
« Reply #11 on: October 14, 2007, 12:08:01 am »
Use cerr instead of cout or add endl at the end of every cout.

You may want to search a GDB tutorial and have a Quick Reference at hand if you want to debug using the console. The most recent GDB Quick Reference I found is right here.