2

I'm trying to learn how to use SDL_TTF library. But i'm unable to solve an error of type : undefined reference to "TTF_INIT"

here is the simple code that im trying to compile and use :

#include <stdlib.h>
#include <stdio.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
int main(int argc, char *argv[]){
   TTF_INIT();
   TTF_Quit();
   return EXIT_SUCCESS;
}

Here is CFLAGS of my makefile :

CFLAGS= `sdl2-config --cflags --libs`-lSDL2_ttf

Thank you in advance for your answer.

PS: i used sudo apt to install SDL2 and SDL2_TTF

venilla
  • 61
  • 1
  • 9

2 Answers2

3

First, you are missing a space after your last backtick in CFLAGS. Even then, it should look more like:

CFLAGS=`sdl2-config --cflags`
LFLAGS=`sdl2-config --libs` -lSDL2_ttf

Also, TTF_Init() (note that it's not all caps) must come after SDL_Init().

Check out LazyFoo's tutorial all about this at http://lazyfoo.net/tutorials/SDL/16_true_type_fonts/index.php . You may want to start at the beginning, though (http://lazyfoo.net/tutorials/SDL/index.php).

edit: I thought I'd mention from the comments that while backticks work, it's more common to write $(shell sdl2-config --cflags)

contrapants
  • 775
  • 4
  • 16
1

You probably already solved it, but I got to this page and no, TTF_Init() doesn't need to come after SDL_Init as @contrapants sugested, as we can see in the chapter 2.2 of the manual.

So the problem with your code was really writing TTF_Init() in CAPS and missing the space between ` and -.

nb0me
  • 39
  • 4