0

I have installed SDL with the command:

brew install sdl2

However, I don't know what to include in my .c file. Can anyone help me?

I tried to #include <SDL.h>, <SDL2.h>, <SDL/SDL2.h>, <SDL/SDL2_main.h> and compile with the command:

gcc `sdl-config --cflags --libs` -o main.x main.c

Thank you all for your answers and advices, I resolved the problem by making a Makefile using this flag :

CFLAGS = -Wall -Wextra -std=c11 -I/usr/local/include/SDL2

See you on another question.

pintel
  • 1
  • 1
  • 1
    What have you tried in particular (show us the code!), what are the errors you're getting? – AKX Mar 02 '23 at 13:45
  • I haven't really tried any code yet, just this so I make sur it compiles (but it doesn't) : `#include int main() { return 0;}`. I get this error : – pintel Mar 02 '23 at 15:57
  • `main.c:3:10: fatal error: 'SDL2/SDL_main.h' file not found #include ^~~~~~~~~~~~~~~~~ 1 error generated.` – pintel Mar 02 '23 at 16:00
  • I heard that I need a cmake project, is that true ? – pintel Mar 02 '23 at 16:01
  • You don’t _need_ a cmake project. It helps to use automatic creation tools. That way you don’t have to write many compilation commands when you have a big project. – SafelyFast Mar 03 '23 at 03:09
  • @pintel please next time add vital information to question by [edit]ing it not by posting comments. This way it will be easier to answer your question without scanning comments under. Note you've posted multiline information to place which do not support multiple lines. – Marek R Mar 03 '23 at 15:38

1 Answers1

0

This seems to be a bug in the sdl2-config script:

$ clang -### $(sdl2-config --cflags --libs) -o sdl-test.x sdl-test.c
[snip] 
".../clang" [...snip...] "-I" "/usr/local/include/SDL2 -D_THREAD_SAFE" [...snip...] "-x" "c" "sdl-test.c"
".../ld" [...snip...] "-L/usr/local/lib -lSDL2"

For some reason, the script outputs the -D_THREAD_SAFE and -lSDL2 arguments as if they were a part of the -L and -I arguments, and naturally you don't have a directory called SDL2 -D_THREAD_SAFE.

Spelling things out makes it work:

$ gcc -I/usr/local/include/SDL2 -D_THREAD_SAFE -L/usr/local/lib -lSDL2 -o sdl-test.x sdl-test.c
$
AKX
  • 152,115
  • 15
  • 115
  • 172
  • have you tried to include a function call in your test? like SDL_Init(SDL_INIT_EVERYTHING); does it work in Mac OS Ventura? –  Jun 23 '23 at 11:59