SDL2 help in C++

Hi, I’m going crazy!

I’m intermediate in python and Luau with Roblox studio, so I decided to start learning game development with C++

I wanted to learn how to use SDL2

I’ve spoke to my Ai, and I’ve used the commands in the shell and installed SDL2 in replit.nix

I can’t find a really good tutorial to help me with doing this on replit, so could somebody please explain to me how to correctly install SDL2? Thanks!

Question:
I’m intermediate in Python and Luau (Roblox Studio), and decided to start learning C++ for game development. I have Replit core and the AI suggested SDL 2.

At first it was being dumb and explaining to me how to install it on Linux or Windows (even though, haha, this is replit, but I guess the AI forgot). Eventually it finally explained to me how to use Replit.nix, and I correctly installed it like this:

{ pkgs }: {
	deps = [
		pkgs.clang_12
		pkgs.ccls
		pkgs.gdb
		pkgs.gnumake
    pkgs.SDL2
	];
}

It told me to put commas after every item, which I did and got error, then it backpedaled and said for me not to put a comma. Next, this is what it recommended:

g++ main.cpp -o myApplication `sdl2-config --cflags --libs`

I entered it into the shell and got nil. Nothing printed, no reaction, LITERALLY NOTHING IM NOT JOKING.

I could go over every iteration the AI has suggested, I could go over every freaking thing I looked up and tried, but it’s all to no avail.

Am I just jumping the gun and starting to learn something too complex too early?

Or is the AI incorrectly telling me what to do?

Sorry if Im being a little vague and really frusturated (been working for this on 3 hours no [CENSORED] progress)

Thanks!

by the way I would upload a video but I’m a new user so I cant

You have to think an AI as a guidance for you through things, but that doens’t mean that AI is infallible.

About this part:

Is not necessarily wrong… But if we break down the command maybe you can see things more clearly.

g++ is the command to invoke the compiler.
main.cpp is the source file you’re compiling (so you need to make sure that your file is called main.cpp and you are using SDL2 headers)

-o is an option that tells g++ you’re going to specify the name of the output file. In this case myApplication

sdl2-config: is a tool provided by SDL2. it will provides the necessary compiler and linker flags that are required to compile a program using SDL2.

--cflags: This is a flag for the sdl2-config above, and it asks for the compiler the flags needed.

--libs: And this flag asks for the linker flags. The linker flags tell the compiler where to find the SDL2 library files necessary for linking your program.

The command is not necessarily wrong. What I do recommend is running the sdl2-config --cflags --libs separately in the shell to see if it outputs the correct compiler and linker flags.

2 Likes

This FINALLY gave me an output, but it is kind of just a random string I feel like of letters with a few comprehensible words, and I don’t think it’s worth it to enter it in, but i’ll do it anyways to here

sdl2-config --cflags --libs
-I/nix/store/xdhh9yzkk2vw7dy2xnl8bgp20gdijj4y-SDL2-2.24.2-dev/include/SDL2 -I/nix/store/xdhh9yzkk2vw7dy2xnl8bgp20gdijj4y-SDL2-2.24.2-dev/include/SDL2 -I/nix/store/xdhh9yzkk2vw7dy2xnl8bgp20gdijj4y-SDL2-2.24.2-dev/include/SDL2 -D_REENTRANT
-L/nix/store/bbmaci3xd9vgm1m3n0l2ymzjq0zfavcg-SDL2-2.24.2/lib -Wl,-rpath,/nix/store/bbmaci3xd9vgm1m3n0l2ymzjq0zfavcg-SDL2-2.24.2/lib -Wl,--enable-new-dtags -lSDL2

thanks for your help and support