0

I'm having a problem linking SDL_ttf library with C++ compiler. I have tried three different programs and i couldn't solve the problem in any of them. I've tried Dev C++, Eclipse and CodeBlocks. In all of them it appeared a different error, but all related to not finding -lSDL_ttf or not recognizing the functions of that library. I'm following this tutorial http://lazyfoo.net/SDL_tutorials/ and have done everything i have found on the internet. I copy the .h file inside /include/SDL/ directory, the .dll files inside the project directory, and the files within /lib directory into the /lib directory that i am using. I think the error might be here, as SDL_image for example, have ".lib" files, and in ttf there is no such file. They are all ".a" or ".la". I'm new to C++ so i don't know if i am doing something wrong. Thank anyone for his help.

The error in code blocks is the following:

ld.exe cannot find -lSDL_ttf

Martin G
  • 17,357
  • 9
  • 82
  • 98
user2976095
  • 1
  • 1
  • 2
  • Could you paste error message? – igleyy Nov 10 '13 at 12:47
  • in Dev C++ the error was several lines like these: [Linker error] undefined reference to `TTF_Quit' [Linker error] undefined reference to `TTF_Init' in code blocks, the one i wrote above – user2976095 Nov 10 '13 at 13:31
  • 1
    Linker cannot find SDL_ttf library. In Codeblocks find linker options and add path to libSDL_ttf.a or libSDL_ttf.la. It should fix you problem. Check http://www.learncpp.com/cpp-tutorial/a3-using-libraries-with-codeblocks/. – igleyy Nov 10 '13 at 13:56
  • Ok, i have added the path to those files and now the error is different, i guess it finds the library, but doesn't recognize functions. It says: 'undefined reference to 'TTF_Init'' and similar messages in every line i call a TTF function – user2976095 Nov 10 '13 at 14:10
  • I suspect that you need to add path to header files in 'Compiler' section (you can see it on screenshot at website I put in my previous comment). If problem is still there please paste actual error message. – igleyy Nov 10 '13 at 14:16
  • I have already done that. Checked it many times. The error says: 'In function 'Z4initv': undefined reference to TTF_init' 'In function 'Z10load_filesv': undefined reference to 'TTF_OpenFont'' and more lines the same as these. – user2976095 Nov 10 '13 at 15:03
  • Get newest headers and runtime binaries from http://www.libsdl.org/projects/SDL_ttf/ and put it to your project. I've checked, there is .dll file. Your linker clearly still doesn't find library. – igleyy Nov 10 '13 at 15:12
  • I've done it and still no changes. The headers are the .h file in the development libraries, aren't them? Do i have to extract it inside /include/DSL? or do i have to create a 'SDL2' folder? Anyway, i have tried both and it doesn't work. – user2976095 Nov 10 '13 at 15:41
  • Okey, i have managed it to compile correctly. But now when i try to run it an error window appears and says "the aplication couldn't initializa correctly (0xc000007b). Click on Accept to close it". In the compiler an error appears saying: "Checking for existence: D:\CARLOS\Code Blocks\Tutoriales\Tutorial\bin\Debug\Tutorial.exe Executing: "D:\CARLOS\Code Blocks\Tutoriales\Tutorial\bin\Debug\Tutorial.exe" (in D:\CARLOS\Code Blocks\Tutoriales\Tutorial\.) Process terminated with status -1073741701 (0 minutes, 1 seconds)" – user2976095 Nov 10 '13 at 16:16
  • This happens even with files that worked already properly before i did this. – user2976095 Nov 10 '13 at 16:17
  • Place .dll file in folder where executable is and try again. – igleyy Nov 10 '13 at 16:24
  • I have placed all .dll files in the folder where the project is, and also in the /project/bin/debuger/ where there is an executable. But still have this problem. – user2976095 Nov 10 '13 at 16:46
  • Just to make sure, you also provided path to SDL2.dll and put it project folder? – igleyy Nov 10 '13 at 17:01
  • The only SDL2 i think i have is referent to TTF, i mean i haven't any 'SDL2.dll' file, only 'SDL2_ttf.dll' and that one is in the project folder, and is the path is provided when writing on the linker '-lSDL2_ttf', right? – user2976095 Nov 10 '13 at 17:25
  • I thought that SDL2_ttf is dependent on SDL2 but I was wrong. If you set properly headers path, library path and you have library in your application folder I have no more ideas :(. – igleyy Nov 10 '13 at 17:31
  • I have tried doing everything a hundred of times and still doesn't work. My limitated knowledge doesn't allow me to find any solution. Even though, thank you very much for your time :) – user2976095 Nov 10 '13 at 18:18

1 Answers1

1

Make sure you downloaded the correct version of the library. If you have ".a" files, you probably downloaded the mingw version. And for that you have to use a mingw compiler. If you are using something like Visual Studio, you need the version with -VC.zip at the end.

Hope it was useful.

Good coding ;-)

Rick Smith
  • 9,031
  • 15
  • 81
  • 85
ThomTom
  • 11
  • 1