I have a cpp program that uses SDL_TTF from SDL2. I use the functions TTF_OpenFont
, TTF_RenderText_Solid
and TTF_CloseFont
. I then try to compile the code in my Makefile into a library that I can load later with dl_open
from <dlfcn.h>
.
This is what my Makefike looks like
NAME = libSnakeSDL.so
SRC = SnakeSDL.cpp
SRC2 = SnakeSDL.cpp main.cpp
CC = LD_LIBRARY_PATH=$$PWD/SDL2/lib g++ -Wall -Wextra -Werror std=c++11
FLAGS = -L SDL2/lib -lSDL2 -lSDL2main -lSDL2_ttf -lfreetype
all: $(NAME)
$(NAME): fclean
@ # $(CC) -o snake $(SRC2) -I ../ -I SDL2/include $(FLAGS)
@ $(CC) -o $(NAME) -shared -fPIC $(SRC) -I ../ -I SDL2/include $(FLAGS)
clean:
@rm -fr $(NAME)
fclean : clean
re: fclean all
When I run make
I get this error
/usr/bin/ld: SDL2/lib/libSDL2_ttf.a(SDL_ttf.c.o): relocation R_X86_64_PC32 against symbol `TTF_CloseFont' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link failed: Bad value collect2: error: ld returned 1 exit status Makefile:25: recipe for target 'libSnakeSDL.so' failed make: *** [libSnakeSDL.so] Error 1
did some digging on what this error might mean and found something like You can't use fPIC on a library that doesn't support fpic
but I'm not familiar yet with fpic and shared libraries. How do I fix this problem/error?
Aucun commentaire:
Enregistrer un commentaire