How to use SDL with gcc?

社会主义新天地 提交于 2020-12-27 07:15:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!