#Trying to work with SDL
1 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
CFLAGS = -I./include/SDL2
LDFLAGS = -L./lib -lSDL2
TARGET = myprogram
SRC = main.c
all: $(TARGET)
$(TARGET): $(SRC)
$(CC) $(SRC) $(CFLAGS) $(LDFLAGS) -o $(TARGET)
clean:
rm -f $(TARGET)```
@thin wind
Note: Make sure to use back-ticks (`) and not quotes (')
Note: Make sure to specify a highlighting language, e.g. `cpp`, after the back-ticks
```c
int main() {}
```
int main() {}
makefile
and here is sdl with main.c
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/opt/homebrew/include/SDL2"
],
"defines": [],
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "macos-gcc-x64"
}
],
"version": 4
}```
maybe its the configurations? i am already so confused.
the configurations file should only apply to VSCode, i would think (if you're using VSCode -- the JSON format makes me think you are). does simply double-clicking on myprogram not work, or is that an old version? gcc shouldn't produce any program if it can't find all the files
double clicking on it just gives me a terminal but doesnt do anything
its just all very confusing i wish i could start from the start but idk if i have done too much damage to fix it lmao
what have you #included in your main.c file?
you definitely haven't done too much damage to fix it easily enough, though. matter of fact, i highly doubt you've done any damage at all. at this stage, you're very likely just playing with trying to make puzzle pieces fit together, and programming environments are generally very good at protecting themselves from beginners just smashing the pieces as we fumble about trying to fit them together. it might be confusing, but that's only because programming in general is confusing as a beginner (and also because the error messages are designed by people who know what they're doing, and have forgotten how little beginners actually know)
I am not an absolute beginner but I am new to c
fair enough, read that as me projecting then. what do your #includes look like?
Everything I do it just doesnt find the SDL2/SDL.h
what does this means? do you get compilation error(s)? or is it just the intellisense who can't find it?
main.c:1:10: fatal error: 'SDL2/SDL.h' file not found
1 | #include <SDL2/SDL.h>
| ^~~~~~~~~~~~
answer was downloading pkg-config
then making a tasks.json file
{
"version": "2.0.0",
"tasks": [
{
"label": "Build SDL2 Program",
"type": "shell",
"command": "bash",
"args": [
"-c",
"gcc -std=c18 -Wall -pedantic main.c $(pkg-config --cflags --libs sdl2) -o myprogram"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "Run SDL2 Program",
"type": "shell",
"command": "./myprogram",
"group": {
"kind": "test",
"isDefault": true
},
"problemMatcher": []
}
]
}
then it worked. wow. what an absolute pain of pain jesus chris
!solved
Thank you and let us know if you have any more questions!
This thread is now set to auto-hide after an hour of inactivity
thats just the intellisense. for future question i suggest you differentiate between it and the compiler. both are different
Btw why are you using SDL2 when SDL3 is already released?
bro what?
since whem
omg bro
January 22 apparently
i might update it. i guess
honestly i want to use opengl but i wanted to atleast finish being able to use sdl.
IMO the best way to use OpenGL is in combination with SDL
OpenGL can't be used alone, it needs a supporting library to open the window for it, manage input, etc. SDL is one of the libraries that can be used for it
ah makes sense. yeah. ill probably use sdl
ah, there's your problem. replace that line with #include <SDL.h>, or replace CLFAGS = -I./include/SDL2 with CLFAGS = -I./include, whichever suits your fancy. gcc is looking for SDL.h in ./include/SDL2/SDL2/, which obviously doesn't exist
The recommended approach for SDL2 was spelling the include as <SDL.h> and adjusting -I accordingly. If I remember correctly, they've folded in v3 and now <SDL3/SDL.h> is the recommended spelling
yeah i noticed it got updated a couple weeks ago and tore my hair out migrating from SDL2 to SDL3 in a codebase that's a whole 20 functional lines. one of the things i didn't notice them mentioning in the migration guide (although they might've -- i kinda skimmed it) is that they inverted the return value of SDL_Init()