0

I am working on this SDL project and so far everything was looking good until I added the SDL_tff library.

I made sure to add ...

  • lib files (.a & .la files in /lib)
  • the SDL_ttf.h header file
  • the .dll in the build dir
  • and added the -lSDL_tff flag to the linker

when I build with make command, then is returns this error.

undefined reference to `TTF_RenderText_Solid'
undefined reference to `SDL_CreateTextureFromSurface'
undefined reference to `SDL_FreeSurface'
undefined reference to `SDL_Init'
undefined reference to `SDL_CreateWindowAndRenderer'
undefined reference to `TTF_Init'
undefined reference to `TTF_OpenFont'
undefined reference to `SDL_PollEvent'
undefined reference to `SDL_SetRenderDrawColor'
undefined reference to `SDL_RenderClear'
undefined reference to `SDL_RenderCopy'
undefined reference to `SDL_RenderCopy'
undefined reference to `SDL_RenderPresent'
undefined reference to `SDL_DestroyTexture'
undefined reference to `SDL_DestroyTexture'
undefined reference to `TTF_Quit'
undefined reference to `SDL_DestroyRenderer'
undefined reference to `SDL_DestroyWindow'
undefined reference to `SDL_Quit'

This is my make file

#OBJS specifies which files to compile as part of the project
OBJS = src/main.c 

#CC specifies which compiler we're using
CC = gcc

#COMPILER_FLAGS specifies the additional compilation options we're using
# -w suppresses all warnings
COMPILER_FLAGS = -w

#LINKER_FLAGS specifies the libraries we're linking against
LINKER_FLAGS = -I./include -L./lib -Lmingw32 -LSDLmain -LSDL -lsdl2_ttf

#OBJ_NAME specifies the name of our exectuable
OBJ_NAME = main 

#This is the target that compiles our executable
all : $(OBJS)
    $(CC) $(COMPILER_FLAGS) $(LINKER_FLAGS) $(OBJS) -o build/$(OBJ_NAME)

I tried to the x64 and x86 versions of SDL_ttf and also I tried 10+ diffirent linker options.

EVERYTHING that I do ruins the project or makes it unworkable...

genpfault
  • 51,148
  • 11
  • 85
  • 139
Gustav
  • 1
  • 1
  • Why does `LINKER_FLAGS` contain a compiler flag (`-I`)? – genpfault Apr 11 '23 at 15:35
  • You might want to have your `$(LINKER_FLAGS)` after your `$(OBJS)` in your invocation of `$(CC)`. – pmacfarlane Apr 11 '23 at 15:54
  • `-I` includes header files from some specified directory. Or that is at least what I am familiar with. And also changing `$(LINKER_FLAGS)` has changed nothing. still has the same error... – Gustav Apr 11 '23 at 19:15
  • If there is some alternative for `SDL_ttf` that is as easy as it is, then please notify. Because manually creating a text renderer is WAY out of my skill level. – Gustav Apr 11 '23 at 19:18
  • Library list should be after sources/object files, `-Lmingw32 -LSDLmain -LSDL` should all have lowercase `-l` (read what it means, don't blindly copy; also this is described in SDL FAQ, may be a good read), it looks like you're using SDL2 so `-lSDL2` instead of `-lSDL`. And as long as you have `-w` asking questions is a bad idea, this flag literally means "i want as many problems as possible please". – keltar Apr 12 '23 at 01:45
  • Does this answer your question? [How do I use SDL2 in my programs correctly?](https://stackoverflow.com/questions/64396979/how-do-i-use-sdl2-in-my-programs-correctly) – HolyBlackCat Apr 12 '23 at 06:46
  • @HolyBlackCat No. Unfortunately, I found the specified problem fix. Either I implemented it wrong or it just doesn't work. – Gustav Apr 12 '23 at 13:37
  • All other libraries work except SDL_ttf. Is there a reason it is so hard to just add text? – Gustav Apr 12 '23 at 13:45
  • Both the link and Keltar mention that `-l`s must be to the right of `.o`. – HolyBlackCat Apr 12 '23 at 14:03

0 Answers0