Я пытаюсь скомпилировать общую библиотеку, разработанную из SDL
, поэтому я использую флаги компоновщика
-lSDL2 -lSDL2_ttf -lm
, но при тестировании он не связывает
Makefile:
CC := gcc
CFLAGS := -Wall -Werror -fPIC -lSDL2 -lSDL2_ttf -lm
CTFLAGS := -Wall -lSDL2 -lSDL2_ttf -lm -L/home/mz37/programming/MZSDL
LDFLAGS = -shared
RM = rm -f # rm command
TARGET_LIB = libSGK.so # target lib
SRCS = src/mzsdl.c src/container.c
OBJS = $(SRCS:.c=.o)
all: ${TARGET_LIB}
test-container.out: ${TARGET_LIB} test/container-test.c
$(CC) $(CTFLAGS) -o $@ test/container-test.c -lSGK
$(TARGET_LIB): $(OBJS)
$(CC) ${LDFLAGS} -o $@ $^
$(SRCS:.c=.d):%.d:%.c
$(CC) $(CFLAGS) -MM $< >$@
include $(SRCS:.c=.d)
clean:
-${RM} ${TARGET_LIB} ${OBJS} $(SRCS:.c=.d)
и результат при тестировании моего файла test-container.out
:
gcc -Wall -Werror -fPIC -lSDL2 -lSDL2_ttf -lm -MM src/container.c >src/container.d
gcc -Wall -Werror -fPIC -lSDL2 -lSDL2_ttf -lm -MM src/mzsdl.c >src/mzsdl.d
gcc -Wall -Werror -fPIC -lSDL2 -lSDL2_ttf -lm -c -o src/mzsdl.o src/mzsdl.c
gcc -Wall -Werror -fPIC -lSDL2 -lSDL2_ttf -lm -c -o src/container.o src/container.c
gcc -shared -o libSGK.so src/mzsdl.o src/container.o
gcc -Wall -lSDL2 -lSDL2_ttf -lm -L/home/mz37/programming/MZSDL -o test-container.out test/container-test.c -lSGK
/usr/bin/ld: /tmp/ccm0XYCK.o: in function `main':
container-test.c:(.text+0x5b): undefined reference to `SDL_Init'
/usr/bin/ld: container-test.c:(.text+0x7a): undefined reference to `TTF_Init'
/usr/bin/ld: container-test.c:(.text+0xb2): undefined reference to `SDL_CreateWindow'
/usr/bin/ld: container-test.c:(.text+0xe9): undefined reference to `SDL_CreateRenderer'
/usr/bin/ld: container-test.c:(.text+0x139): undefined reference to `SDL_CreateRGBSurface'
.....
.....
/usr/bin/ld: /home/mz37/programming/MZSDL/libSGK.so: undefined reference to `SDL_GetError'
/usr/bin/ld: /home/mz37/programming/MZSDL/libSGK.so: undefined reference to `sqrt'
/usr/bin/ld: /home/mz37/programming/MZSDL/libSGK.so: undefined reference to `TTF_RenderText_Blended'
collect2: error: ld returned 1 exit status
make: *** [Makefile:17: test-container.out] Error 1