1

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?

Gakgu
  • 123
  • 4
  • 9
  • If you link with static library you're supposed to pull all its dependencies (in that given case it is `-lpthread`, but there may be more). Shared libraries have dependency information embedded so it isn't requred. – keltar Jun 29 '16 at 12:04

1 Answers1

3

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
genpfault
  • 51,148
  • 11
  • 85
  • 139
LPs
  • 16,045
  • 8
  • 30
  • 61