#Trying to work with SDL

1 messages · Page 1 of 1 (latest)

thin wind
#

Beginner to C and I am incapable of making this library work. Everything I do it just doesnt find the SDL2/SDL.h file. its literally in the same folder. I tried to make a makefile using ai so that might be the issue.

sonic obsidianBOT
#

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.

thin wind
#
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)```
sonic obsidianBOT
#

@thin wind

It looks like you may have code formatting errors in your message

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

Markup

```c
int main() {}
```

Result
int main() {}
thin wind
#

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.
high topaz
#

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

thin wind
#

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

high topaz
#

what have you #included in your main.c file?

high topaz
# thin wind its just all very confusing i wish i could start from *the start* but idk if i h...

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)

thin wind
#

I am not an absolute beginner but I am new to c

high topaz
#

fair enough, read that as me projecting then. what do your #includes look like?

vapid moat
#

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?

thin wind
#

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

sonic obsidianBOT
#

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

vapid moat
#

thats just the intellisense. for future question i suggest you differentiate between it and the compiler. both are different

rotund knot
#

Btw why are you using SDL2 when SDL3 is already released?

thin wind
#

since whem

#

omg bro

rotund knot
#

January 22 apparently

thin wind
#

i might update it. i guess

#

honestly i want to use opengl but i wanted to atleast finish being able to use sdl.

rotund knot
#

IMO the best way to use OpenGL is in combination with SDL

thin wind
#

really how?

#

i thought open gl is just better sdl with 3d capability

rotund knot
#

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

thin wind
#

ah makes sense. yeah. ill probably use sdl

high topaz
rotund knot
#

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

high topaz
# rotund knot January 22 apparently

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()