2017-06-27 1 views
0

J'utilise sdl2 lib pour créer un jeu simple. Testé avec succès les fenêtres sdl et la manipulation du clavier. Le problème est que je ne peux pas utiliser TTF pour mettre un texte dans la fenêtre, TTF_Init ne se trouve pas (référence non définie à TTF_Init())Référence indéfinie à TTF_Init

fichier CMake:

cmake_minimum_required(VERSION 3.6) 
project(untitled17) 

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lmingw32") 
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++") 


include_directories(${PROJECT_SOURCE_DIR}/include) 
link_directories(${PROJECT_SOURCE_DIR}/lib) 

set(SOURCE_FILES main.cpp) 
add_executable(untitled17 ${SOURCE_FILES}) 

target_link_libraries(untitled17 mingw32 SDL2main SDL2) 

main.cpp

#include "include/SDL2/SDL.h" 
#include "include/SDL2/SDL_ttf.h" 

using namespace std; 

int main(int argc, char* argv []) { 

SDL_Init(SDL_INIT_EVERYTHING); 
    TTF_Init(); 
    TTF_Quit(); 


    return 0; 
} 

Clion sortie de la construction:

[ 50%] Building CXX object CMakeFiles/untitled17.dir/main.cpp.obj 
[100%] Linking CXX executable untitled17.exe 
CMakeFiles\untitled17.dir/objects.a(main.cpp.obj): In function `SDL_main': 
C:/Users/1/ClionProjects/untitled17/main.cpp:14: undefined reference to `TTF_Init' 
C:/Users/1/ClionProjects/untitled17/main.cpp:15: undefined reference to `TTF_Quit' 
collect2.exe: error: ld returned 1 exit status 
mingw32-make.exe[3]: *** [untitled17.exe] Error 1 
CMakeFiles\untitled17.dir\build.make:96: recipe for target 'untitled17.exe' failed 
mingw32-make.exe[2]: *** [CMakeFiles/untitled17.dir/all] Error 2 
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/untitled17.dir/all' failed 
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/untitled17.dir/rule' failed 
mingw32-make.exe[1]: *** [CMakeFiles/untitled17.dir/rule] Error 2 
Makefile:117: recipe for target 'untitled17' failed 
mingw32-make.exe: *** [untitled17] Error 2 

Répondre

1

Vous devez lier contre le SDL_ttf librar y. (Doit être ajouté à target_link_libraries)

target_link_libraries(untitled17 mingw32 SDL2main SDL2 SDL_ttf)