【发布时间】:2020-01-02 13:59:19
【问题描述】:
我第一次开始使用 SDL 库,我使用 apt-get install 将它下载到 windows 子系统 (Ubuntu)。当我从 SDL 库调用函数然后运行 makefile 时,我会看到:
/home/display.c:13: undefined reference to `SDL_Init'
/home/display.c:14: undefined reference to `SDL_GetError'
/home/display.c:17: undefined reference to `SDL_CreateWindow'
/home/display.c:19: undefined reference to `SDL_GetError'
/home/display.c:22: undefined reference to `SDL_CreateRenderer'
/home/display.c:24: undefined reference to `SDL_GetError'
makefile 看起来像:
gcc -Wall -Werror -Wextra -Wunused -std=gnu99 -g -O0 -Wpedantic -lpthread -lSDL2main -lSDL2
我认为问题出在链接上,编译器找不到 SDL 所在的位置。但是,如果是这种情况,应该会出现一个错误,指出找不到#include SDL2/SDL.h。这可能是安装问题还是我在生成文件中链接 SDL 的方式有问题?
【问题讨论】:
-
使用库时,您需要了解构建 C 程序的两个独立步骤:编译和链接。如果编译器 找不到一些头文件,你会得到关于丢失头文件的错误。您得到的是来自 linker 的错误,无法解析对
SDL_...的引用。也许它需要一些帮助才能找到库文件,例如libSDL2.a。