我正在尝试使用SDL2库进行编译,但没有成功。
OS: MacOS 10.13.2
Visual Studio Code 1.43.1
Language: c++
我正在使用Lazy Foo的非常基本的示例代码。这是我收到的消息:
[Running] cd "/Users/martinjoselizondocolomes/Programacion/01_hello_SDL/" && g++ 01_hello_SDL.cpp -o 01_hello_SDL && "/Users/martinjoselizondocolomes/Programacion/01_hello_SDL/"01_hello_SDL
Undefined symbols for architecture x86_64:
"_SDL_CreateWindow", referenced from:
_main in 01_hello_SDL-a16d96.o
"_SDL_Delay", referenced from:
_main in 01_hello_SDL-a16d96.o
"_SDL_DestroyWindow", referenced from:
_main in 01_hello_SDL-a16d96.o
"_SDL_FillRect", referenced from:
_main in 01_hello_SDL-a16d96.o
"_SDL_GetError", referenced from:
_main in 01_hello_SDL-a16d96.o
"_SDL_GetWindowSurface", referenced from:
_main in 01_hello_SDL-a16d96.o
"_SDL_Init", referenced from:
_main in 01_hello_SDL-a16d96.o
"_SDL_MapRGB", referenced from:
_main in 01_hello_SDL-a16d96.o
"_SDL_Quit", referenced from:
_main in 01_hello_SDL-a16d96.o
"_SDL_UpdateWindowSurface", referenced from:
_main in 01_hello_SDL-a16d96.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[Done] exited with code=1 in 0.168 seconds
构建C ++代码需要三个阶段:
Preprocessor处理宏和#include
指令,因此在此步骤中需要您的头文件。
Compiler生成目标文件。这样就可以在源文件中检查语法了。
Linker将目标文件和库组合成可执行文件,因此您的运行时库必须可用并且已指定给链接器。
对于g ++,您可以通过在命令行上给出库的全名来指定库,或使用-l
快捷方式来找出正确的前缀(lib)和后缀。因此,根据您的情况,我相信您可以添加-lSDL
。