Search code examples
clinkersdlsdl-ttf

SDL_TTF : undefined reference to "TTF_INIT"


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


Solution

  • 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)