问题
I download SDL source at 'https://www.libsdl.org'
I use cmake and get library.
libSDL2.a
libSDL2main.a
libSDL2-2.0.so
libSDL2-2.0.so.0
libSDL2-2.0.so.0.4.0
I write main.c to test SDL.
#include <SDL.h>
int main()
{
SDL_Init(SDL_INIT_VIDEO);
SDL_Quit();
return 0;
}
I make lib directory. I move *.a file and include directory.
vim main.c
mkdir lib
mv libSDL2.a libSDL2main.a ./lib
mv /home/gakgu/다운로드/SDL2-2.0.4/include ./
Then try compile.
gcc -W -Wall -o main main.c -Iinclude -Llib -lSDL2 -lSDL2main
but It is failed.
What's the problem?
回答1:
You must add -lpthread
before other libs to link threading support.
You should also enable a bit more warning option: -Wextra
-pedantic
So
gcc -W -Wall -Wextra -pedantic -o main main.c -Iinclude -lpthread -Llib -lSDL2 -lSDL2main
来源:https://stackoverflow.com/questions/38082665/how-to-use-sdl-with-gcc