user3321051
user3321051

Reputation: 41

Linker error in g++ while trying to link to SDL_ttf shared object files

I am trying to use the SDL_ttf development library in an Ubuntu environment. I started by downloading the dev libraries via:

sudo apt-get install libsdl-ttf2.0-dev

Next, I imported the header file in my code as so:

#include <SDL_ttf.h>

When I compile with the command:

g++ -g -I /usr/include/SDL Main.cpp -lSDL -lSDL_image -lSDL_ttf land.cpp PerlinNoise.cpp Util.cpp org.cpp Init.cpp `sdl-config --libs`

I get the following output:

/tmp/ccpLKljA.o: In function `init()':
/home/zoo/Desktop/World-A/Util.cpp:39: undefined reference to `TTF_Init'
/home/zoo/Desktop/World-A/Util.cpp:42: undefined reference to `TTF_Quit'
/home/zoo/Desktop/World-A/Util.cpp:48: undefined reference to `TTF_OpenFont'
/home/zoo/Desktop/World-A/Util.cpp:52: undefined reference to `TTF_Quit'
collect2: ld returned 1 exit status

I understand this is a linker error however I do not know what to do to fix it. I know that the -lSDL_ttf command is not doing anything because removing it does not change anything. I tried to reference the .so file however that didn't change the results. I did this reference via the command: -LlibSDL_ttf-2.0.so.0.6.3. I am able to view the .so file and it does contain the commands listed above.

Upvotes: 0

Views: 709

Answers (1)

user26347
user26347

Reputation: 604

You have to put land.cpp, and the rest of the CPP files, before the libraries on the command line.

Upvotes: 1

Related Questions