SDL2 Setup Tutorial - SDL Tutorial Series #1 - Game Dev With C++
HTML-код
- Опубликовано: 23 ноя 2024
- In this video we will be setting up sdl2 with vscode
links mentioned:
sdl2 - libsdl.org/
sdl_image - www.libsdl.org...
vscode: code.visualstu...
twitter:
main - / scoopydevy
2nd - / scoopydevy2
#gamedev #sdl2 #sdl2setup #sdl2_vscode
all:
g++ -Iinclude -Iinclude/sdl -Iinclude/headers -Llib -o Main src/*.cpp -lmingw32 -lSDL2main -lSDL2 -lSDL2_image
on linux use this to get all sdl2 headers
`pkg-config --cflags --libs sdl2 SLD2_image`
then the include is
#include
Description nextime
@@m4rt_ Bro you wrote SLD2_image instead of SDL2_image. How you gonna fuck me up like that I wasted like 30 minutes 💀
@@ЖукОбычниик it was a typo
Makefile:2: recipe for target 'all' failed
mingw32-make: *** [all] Error 1
help please
dude, I literally spent 3 hours trying to get SDL to work on VS code, already watched like 3 tutorials and none of them worked. This is the only tutorial that shows how to really make it work. Thank you!
awww thanks man! More videos to come :)
m quite late, but what was it that made it work
@@averagecornenjoyer6348hey can you help me in installing sdl2 in vscode
I got an error while entering the make comand it says make (e=2) the system cannot find the file specified HOW DO I FIX IT @@vaderdev
Glad you made it work, but if you use visual studio is actually easier.
undefined reference to `WinMain@16'
If you are getting the above error, define SDL_MAIN HANDLED and include the SDL header file. Copy and paste the two lines mentioned below:
#define SDL_MAIN_HANDLED
#include
Thanks for the tutorial, helped me a alot.
Thanks a lot! Gonna add your name to the special thanks section in my game's credits when it comes out after 12 years! (if I don't forget LOL)
@@pastifier9349 Don't worry.I'll remind you,
thank you!!
This fixed the undefined reference to 'WinMain@16' error, but I still had other problems. I copied a basic window creation program using SDL to test if it works, but the compiler threw errors such as "undefined reference to SDL_Init".
To solve this problem I had to replace the 64-bit SDL files (lib, include folders and .dll files from folder x86_64-w64-mingw32) with 32-bit SDL files (the same files but from folder i686-w64-mingw32). It worked, but I want to make the 64-bit files work, so please help if anyone knows!
edit: turns out it's quite trivial, I had installed MinGW which can only compile 32-bit programs. I needed MinGW-W64 for 64-bit :p
Thank you!
OMG you don't know how long I have been trying to get this to work, like all the other tutorials don't explain anything. You did, Thank you so much.
I think this is the first tutorial for installing a framework that I've went through without one single error, thank you so much!
Thank you so much! This is the only setup tutorial I followed that actually worked (and the only tutorial in which it is explained so clearly what each step does).. Have a great day!
haha thanks! have a gr8 day aswell :)
Man you're totally legend, after searching enourmous data on the internet I finally got a tutorial that completely shows step by step from install to Makefile with vscode, great job dude.
This is the only video that I use SDL2 and it works perfectly! Thanks for the vid
i know u probably will not even see this comment but i really want to thank you for this, it may seem crazy but i think i watched at least 20 tutorials and this is the one that worked, i even switched from codeblocks to vs code for this, have a great day if u read this! and thanks again ♥
For those looking for a good SDL2 setup tutorial, THIS IS THE ONE!
Bro I have been trying to get SDL to download for 4 hours... You are a life saver. Thanks a ton!!
hey what is the difference between visual and mingw . Why did he used mingw when he used vs studio could you explain i am new
@@lazzzy5514 dunno if you still care but but mingw and visual c++ are just compilers on windows. He isn’t using visual studio, the IDE, he’s using vscode which doesn’t pre-install with a default c++ compiler. Unless you use the IDE, most people just use mingw. Personally I prefer gcc though.
@@retrogalaksi honestly I don't remember. It was through some package manager on windows. But mingw is probably better or at least easier to setup. Or use Linux where gcc is there by default.
Why is it always the one who is helpful is always the most underrated in RUclips
ikr pls do share the video so others can find it to
thanks for making these videos bro you dont know how much your helping people
thanks man appreciate it :)
Oh main you are such a life saver! It took me a day to set up SDL.
FINALLY! YES, OH YES! I read the documentation, github readme files, youtube videos and none of them worked, then I as my last hope, i stumbled up on this c++ video and it finally worked, I know im 1 year late but thank you very much. just letting you know I'm grateful for this tutorial. ♥
lmao i made this vid for fun didnt know it would help so many peeps
Umm.. There is something I don't understand, the thing is that the dll files added in the file explorer don't seem to exist while looking from VS code, only the include and lib directories are shown 11:20
Plz solve my issue
g++: error: src/*.cpp: Invalid argument
MakeFile:2: recipe for target 'all' failed
mingw32-make: *** [all] Error 1
best EVER so far. THANKS MAN.
YOU SAVED MY LIFE....
After hours of searching how to use SDL2 , it finaly works! TY and have a great day!
you too
i keep getting this error help :((( 'mingw32-make' is not recognized as an internal or external command,
operable program or batch file.
Man this took 5 hours but your video helped me, kudos bro
It works man! I watched more videos on youtube but none of them wrk. But you great teacher❤
finally a sane tutorial for setting up sdl2,thanks dude
haha np
why did you did it with mingw , cant we do it with visual ?
and can we use mingw as compiler after coding in vs studio sorry i am new i dont have much knowledge about it pls help me out
If you have an error which says lSDL2main and lSDL2 directories could not be found, then go to the normal SDL folder (not the image) that was extracted and copy the stuff from the lib into the lib we have on Vscode. Don't replace since we need the image one too. Had this issue and resolved it this way.
when i type mingw32-make it says its not recognized but i have mingw added to my path? even when i try to type mingw in the bin folder of mingw it doesnt work
I have no idea how but it worked, mingw couldn't find the reference to SDL apparently, but after changing literally nothing it started working.
It must be those damn cosmic rays !
I keep getting this lmao:
src/Main.cpp:1:17: fatal error: SDL.h: No such file or directory
#include
^
compilation terminated.
MakeFile:2: recipe for target 'all' failed
mingw32-make: *** [all] Error 1
can i get help with this? Thx
I just redid the last bit of the tutorial and it worked fine
thank you so mu8ch all i needed was the image one now i can use them lol thank you!
sir u deserve more than you have thank you so much
thanks man!
You just saved me with this video. Thanks a lot
Your awesome, dude. This tutorial really works
the only working non indian tutorial!!! (not hate speech, don't sue me pls)
jokes on u i am indian
if you're like me and everything worked but when compiled an error saying "undefined reference to `WinMain`" pops up, just add before the SDL.h header a define directive with the SDL_MAIN_HANDLED macro, seemed to work for me
can u explain me how
getting undefined reference to winmain error
#define SDL_MAIN_HANDLED
#include "SDL.h"
ADD it to the top
now my error is fixed
“Always do everything the easy way, not the hard way.”
*Uses C++*
But yeah great tutorial
I get this error :()
g++ main.cpp -Iinclude -Llib -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -o main
process_begin: CreateProcess(NULL, g++ main.cpp -Iinclude -Llib -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -o main, ...) failed.
make (e=2): El sistema no puede encontrar el archivo especificado.
make: *** [all] Error 2
some ;(
Bro, where did you get those dll files? None of them except SDL2 and SDL2 Image got downloaded for me.
Cmd error it says 'mingw32-make' is not recognized as an internal or external command,
operable program or batch file.' FIX
ruclips.net/video/qLh84CmdBJ0/видео.html
Apart from the video being recorded in 720p @ 15hz, great video and explained really well!
Mannnn you really save me. Thanks a lot.
this tutorial is amazing, however for some reason it gives me an error for "#include", any idea why?
well its because of the c/cpp extension. So basically its nothing wrong with yuor current setup just vscodes problem so u can hover over it the error and click on the quick fix button and then click on the disable error squiggly or something
oh ok thankzs
@@vaderdev I tried and it gives me an error when executing and it marks an error in that part
@@Mabox-sc5iz you probably don't have the SDL.h file
@@creshfream3729 how would i go about geting that file if im missing it?
mingw32-make: *** No targets. Stop.
I got the error above after typing the same command in cmd(17:00). Help
SDL.h: No such file or directory gcc, i get this error :) could someone help me? i set up everthing the exact same as he did.
Creating the "headers" folders for each of the "i686-w64-mingw32" and "x86_64-w64-mingw32" folders plus replacing "-Iinclude/sdl" with "-Iinclude/SDL2" from the MakeFile worked for me. Please note that the SDL folders' names change after updates. SDL2 may change once SDL3 become available or 20 depending when you read this.
thanks bhai appreciate it accha tutorial hai
Sld_image has move to another site, now I don't know how to download. Can someone help me please??
triangle dev made new video 😳😳😳😳
ayyo man i love this video and your profile picture tho :o
haha thanks man!
Me hears analogy "ummm these are all the uhh each individual file is like a bone for SDL and it's glued together by duck tape" me ok ok
no script
@@vaderdev alr
hi guys may i ask why i followed the step but it show SDL.h: not such file or directory? n MakeFile cant compile
me too trying to slove it it happen to me with raylib too 2 days and im cracking it!
Hi scup I honestly found this really useful, so thank you. Do you know why my Main.exe file closes immediately after opening? This is an old video so I won't be surprised if you don't reply, but if you do that would be amazing.
I have done some research but I am curious as to why yours didn't need any extra lines of code.
are u returning 0?
@@vaderdev haha no for some reason i completely missed the cin.get(). i don’t know how. thank you for replying though
my compiler does not recognize the flags used in Makefile
For me this also was the only to work. But I didn't have the SDL.h file, and I don't have the #include even at first download, but it seems to be working with #include, does that work the same or should I solve this?
Got this problem.
mingw32-make: MakeFile: No such file or directory
mingw32-make: *** No rule to make target 'MakeFile'. Stop.
Any idea what's the culprit?
i get this aswell, have you managed to solve it ?
Nope, I gave up
@@eskay7501 soooo have you managed to solve this man ? xd
Noice!
haha thanks!
I got this error "g++: error: src/*.cpp: invalid argument"
Dang, thanks for this man. Good vid OwO b
Also gotta say, I like your humour
aww thanks man! Just being myself infront of a computer lol
@@vaderdev lol
all i get is "undefined reference to 'WinMain@16' ". Happens regardless of whether I use the makefile or type it out myself in the terminal.
Hey, bro. I don't know if you've resolved it. I also encountered the same problem, and I have two solutions to offer for reference. The first one is to add "#undef main" before "int main()." The second one is to download the "Code Runner" plugin, go to settings, search for "save," and find "Code-Runner: Save All Files Before Run" and check it.
when i try to run the program on vscode i get this error: "fatal error: SDL.h: No such file or directory". Does anyone know how to fix this? thanks in advance
hmmm how are u including sdl?
@@vaderdev i got the same problem, but the Main.exe is working and in cmd its it shows the same line as in the video above, did everythink exacly like in your vid.
@@vaderdev #define SDL_MAIN_HANDLED
#include "SDL.h"
Could you make a tutorial on how to fix the includePath update ? It's really annoying, I looked for several answers on internet, trying to find the solution, but it just didn't work...
yea ok ill make a brief video
@@theamazinganimator7022 Thanks
@@ventresurpates2659 apperently this guy made the vid already.. go check it out lol
@@theamazinganimator7022 can u share the link
That makefile is god damn horrifying and my GOD i wish I had found it like. 2 years ago lmao
On one hand, ew. On the other hand, it actually explains what it's doing and isn't hidden under a layer of `$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp` cruft
This tutorial is awesome for less experienced windows devs, and REALLY highlights how badly windows needs a package manager lmao
Personally i would recommend the MSys2 environment, it configures most stuff for you and it comes with pacman, which Just Works:tm: most of the time.
Bro while doing the Makefile thing in the cmd, it gave me a collect2.exe Id returned 1 exit status error and recipe for target 'all' failed.
And I did not get a Makefile.exe
Every time we want to run the program after editing we have to "makeflie" on cmd? too complicated!! anyone have a way to run them directly on vscode?
I tried running the cmd, however it tells me mingw32-make is not recognised as an internal or external command, I believe I copied everything over properly so I'm not sure what's going wrong
install mingw
Also make sure mingw\bin in C:\ is included in path
@@kenetramirez6358 I installed MingW and added it to path but i get this error
mingw32-make: MakeFile: No such file or directory
mingw32-make: *** No rule to make target 'MakeFile'. Stop.
@@sruffolo9303 what minute of the video are you in sorry?
@@kenetramirez6358 the part where he explains the command of how to run the main.cpp file
When I cut the folders in the SDL_image folder, It didnt create new DLL's like zlib
Its probably because they just made it more efficient after 1 year
My command is not working and saying that it is non-recognizable command even I have written the code
10:43 My bin file for image-devel only has three files, only the dll files... 😔 😔
EDIT: i followed through the tutorial anyway and it worked! the window displayed the message, i guess nothing else really mattered other than the dll files,
thanks a million!
What is the "MakeFile" because I don't get nothing called make file besides the name, what type of file is it.
The sdl image file does not appear as a zip file for me, and I am using the exact file you showed, any idea
it gives the massage "#include error detected. Please update your includePath...".Can u help me?
my Bin folder is missing the libjpeg.dll files. Why would it be so?
Mine gives the following error: fatal error: SDL.h: No such file or directory
#include
HELP ME!
you probably forgot to take a file?
you probably forgot to include sdl
bro it's "mingw32-make -f MakeFile"
You probably didn't set an include path. Just click on the error in the code and press "Quick fix", VSCode will generate a file to set up your include path. (Also install the C/C++ extension maybe)
Pls help i have this error: g++: error: src/*.cpp: No such file or directory can you help me pls?
hmm, is this series gonna end up like any other sdl tutorial? stop half way?
I hope not... I think i will finish a full game for this series but each video will be uploaded with a large time gap between them since i will have school
99% guaranteed.
I followed the tutorial and it seemed to go well, but when I try to run the Main.exe I get a windows error saying that the program can't run on my pc. I'm new to this kind of thing so I don't know what could be the cause(mingw, sdl ?), so it would be great if someone knew what causes this
sorry for the late reply but make sure to add the dll's into the folder where the exe is stored
Thank you!
np glad i could help :)
Alternatively, someone could just provide a downlaod link for the sdl_image
collect2.exe: error: ld returned 1 exit status
MakeFile:2: recipe for target 'all' failed
mingw32-make: *** [all] Error 1
this is the error im getting
Is MinGW the best option? i though is kinda dead. I am using MSYS2 / UCRT64 actually.
UCRT64 will work, but it was so inconsistent it only works on my desktop and not my laptop. So far I've seen success on my laptop with the equally inconsistent Cygwin setup and installing all the mingw libraries as needed.
and how to run it in visual studio code? please help me!!!
very nice tutorial please do more :(
there are 3 more vids :)
thank you +1 subscribers
this sdl2 image thing just doesnt exist or sth please help
don't answer me .... it's worked thanks man
oh lol ye it happens and it is quite annoying but thats c++ for yeh
bro, in the website download page there are source code, for what is that? and why you don't download it?
cuz i dont want to compile the code
10:01 If you cut the folder don't delete it :)
lmao
i dont have a many dll as you i faind just two dll files
it work
Tank You Very Much man !!!
not working its not showing in vs code it says error
yey
Please help,
So, I typed exactly the same as of video in CMD
mingw32-make -f MakeFile
after that it shows this:
g++ -Iinclude -Iinclude/sdl -Iinclude/headers -Llib -o Main src/*.cpp -lmingw32 -lSDL2main -lSDL2 - lSDL_image
g++: error: -E or -x required when input is from standard input
MakeFile:2: recipe for target 'all' failed
mingw32-make: *** [all] Error 1
Is it possible to install SDL globally so you don't have to copy the files everytime you create a new project
yes
in the makefile you will have to specify the path of both the lib and include folder of the path you plan on using
but it isnt recommended for projects which will be shipped to multiple platforms
Ok thank you make great videos
Is there a way to doit without a make file? I cant make it work with hpp files.
try h files then if hpp isnt working
else make a bat file if ur on windows
Makefile: no such file or directory
No rule to make target 'Makefile'. Stop.
in CMD
thx bro
Hey bro! Thanks for the awesome tutorial but i have a question. When I run the MakeFile on the cmd I get this error.
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
MakeFile:2: recipe for target 'all' failed
mingw32-make: *** [all] Error 1
On my vscode I have all the .dll in the main directory, maybe thats the problem? Thanks so much again!
Hi, I had the same issue, and I read an article that instructed me to include the line :-
#define SDL_MAIN_HANDLED before including "SDL.h".. Worked for me, and I hope it does for you too!
Cheers
@@c4rbon_free521 thank you soooo much!!
@@joshrayner7167 hey look into SDL_SetMainReady
SDL Wiki
SDL_SetMainReady /. /this is the function
Circumvent failure of SDL_Init() when not using SDL_main() as an entry point.
Syntax
void SDL_SetMainReady(void);
Remarks
This function is defined in SDL_main.h, along with the preprocessor rule to redefine main() as SDL_main(). Thus to ensure that your main() function will not be changed it is necessary to define SDL_MAIN_HANDLED before including SDL.h.
Version
This function is available since SDL 2.0.0.
Code Examples
#define SDL_MAIN_HANDLED
#include "SDL.h"
int main(int argc, char *argv[])
{
SDL_SetMainReady();
SDL_Init(SDL_INIT_VIDEO);
...
SDL_Quit();
return 0;
}
Related Functions
SDL_Init
@@SuperShortAndSweet thanks!
@@joshrayner7167 so since sdl_main isn't the entry point your main needs to be the same as above because you're now handling windows api, so you loses your portability because you now invoke window api then you provoke sdl api . I don't do it but I imagine you could use cmake to build window api which can sdl2 api (take all this with grain of salt (mainly the cmake stuff))
thanks PolyMars
in the cmd it shows me that the command mingw32-make cant be found or is wrong written. can you help me out?
ofc! I think u need to add mingw to ur path so if ur on windows u can hit windows and search for env and add it to ur system or environmental variables
@@vaderdev sry bud i couldnt follow up im kinda new into these things could u give me a depth instruction how to do what ? :(
@@dedmem3.666 its kind of hard to explain here on youtube do u use discord?
I have the same problem, and mingw is in my path
with g++ --version (in cmd) it showed me, that i had instlled it
@@marcelvelasquez_1 hmmmm well maybe u installed a wrong one like an older version of mingw so i guess download the newest version and see if it works
Your Discord isn't in the description D':
discord.gg/spVQfM92Jn
ayo
it says "mingw32-make" is either spelled wrong or doesnt exist.
u have a idea how i fix this?
great tutorial to this point btw
uh did u install mingw?
@@vaderdev i installed it now, still not working
@@spekulatiu did u add it to ur systempath
@@vaderdev what is a system path
Do you mean the Weird environment variables?
you windows guys are lucky
lol now im on linux... lmao
what the game you make I install?