Setup SDL2 with CMake and Visual Studio (Game Development)

  Рет қаралды 9,204

constref

constref

Күн бұрын

In this video we create a new CMake project using Visual Studio and work with it directly within Visual Studio, without producing a VS project or solution. We then use find_package to add SDL2 as a 3rd party library and link to it in order to compile our sample SDL2 application. We use SDL_CreateWindow to setup a window and SDL_CreateRenderer to setup the renderer.
0:00 Introduction
0:43 Create CMake project
1:42 Add SDL2 using find_package
2:28 Use CMAKE_PREFIX_PATH to help find SDL2
4:55 Setup includes and linked libraries
6:38 SDL main function and library setup
9:51 SDL_Init and SDL_Quit
11:03 SDL2.dll file location
13:54 Clear the screen and draw a mighty dot!
Music: Bensound
License code: MJ7W9AT6VR0ZC89B

Пікірлер: 27
@vinii2815
@vinii2815 Ай бұрын
hey just wanted to tell you this video was very helpful, while it didn't work 100% because my text editor is /unusual/ I managed to get it working after 3 days thanks 😀 (I got it working just a few minutes after your video)
@iliyankovachev5721
@iliyankovachev5721 Жыл бұрын
Thanks, that really helped me set up my very first CMake project with SDL2.
@troybrunette9979
@troybrunette9979 Жыл бұрын
Thank you !!! I was going mad trying to figure out how to get this setup
@kingofdice66
@kingofdice66 9 ай бұрын
Thank you so much for this video. It helped A LOT.
@andrewtate8007
@andrewtate8007 Жыл бұрын
Thank you, this was really nice.
@alealfaro6236
@alealfaro6236 4 ай бұрын
And this did it! Stack overflow and other forums had it wrong or were confusing the whole time
@naseema4331
@naseema4331 11 ай бұрын
Very helpful
@malusmundus-9605
@malusmundus-9605 Жыл бұрын
Thanks! Been coding for a long time but needed microsoft's compiler to use nvapi so I'm switching from gcc... was a major pain to figure out how to properly link SDL.
@Akniy
@Akniy Жыл бұрын
I followed everything but I get this error: Could not find a configuration file for package "SDL2" that is compatible 1> [CMake] with requested version "".
@maartenofbelgium
@maartenofbelgium Жыл бұрын
Were you able to resolve this issue?
@hobotookmyname
@hobotookmyname 5 ай бұрын
Not sure if you're still interested, but the find_package stuff must be entered in the nested CMake, not the global one
@hobotookmyname
@hobotookmyname 5 ай бұрын
@@maartenofbelgium Not sure if you're still interested, but the find_package stuff must be entered in the nested CMake, not the global one
@itskobold
@itskobold 3 ай бұрын
@@hobotookmyname legend, thank you!
@mudkiptheengineer5339
@mudkiptheengineer5339 Жыл бұрын
any ideas on why it still fails to generate the files, even after editing the CMAKE_PREFIX_PATH and restarting VS?
@hobotookmyname
@hobotookmyname 5 ай бұрын
Not sure if you're still interested, but the find_package stuff must be entered in the nested CMake, not the global one
@somebody_2837
@somebody_2837 Жыл бұрын
which version of SDL2 did you download from github? I used the VC one.
@maartenofbelgium
@maartenofbelgium Жыл бұрын
At kzfaq.info/get/bejne/oNGdd6WL38nMkoU.html, the VC sdk was visible. The mingw sdk has a completely different folder structure.
@somebody_2837
@somebody_2837 Жыл бұрын
​@@maartenofbelgiumThe question was asked six months ago when I didn't really understand SDL. Anyway, thanks
@andybub46
@andybub46 9 ай бұрын
I followed all your steps and the CMake files generate fine but when I try to include SDL.h in the main file I get a "Cannot open include file" error. Do you know what could be causing this issue? Edit: Adding #define SDL_MAIN_HANDLED to the top of my main file fixed this but I don't know what that does specifically if anyone can explain that
@constref1983
@constref1983 9 ай бұрын
Don't set the SDL_MAIN_HANDLED define, this causes SDL to not perform important platform specific setup. If you use pastebin and send me a couple of links to your CMakeLists.txt and main.cpp I can take a look and help.
@ezphantom
@ezphantom Жыл бұрын
Is there any way to not copy required dlls to exe directory manually? I mean it looks like a dirty hack I found smth like: set(CMAKE_INSTALL_RPATH ".") set(CMAKE_BUILD_WITH_INSTALL_RPATH true) But I'm not sure it is a clear way as well. Any other ideas? Thanks
@ezphantom
@ezphantom Жыл бұрын
# copy the .dll file to the same folder as the executable on Windows if (WIN32) add_custom_command( TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ VERBATIM) endif()
@NickEnchev
@NickEnchev Жыл бұрын
@@ezphantom Putting stuff in your project file to copy DLLs around is a far dirtier hack in my opinion. I don't like copying the DLL directly either, but I also don't care enough to waste any more time to do it some hypothetical "right" way. I went down the rabbit hole once and didn't wasted a bunch of time, I may try it again, if I do I'll let you know ;)
@mariusz5682
@mariusz5682 Жыл бұрын
Manual or post build copying of dll can be avoided directly in Visual Studio: right click project -> Properties -> Configuration Properties -> Debugging -> Environment: (for the relevant configuration and platform!) I hope there is a way to do this from within CMake - and for any generator, not just VS, but i haven't figured it out yet. If anyone knows, please tell. I appreciate the video!
@bhavikyadav2934
@bhavikyadav2934 3 ай бұрын
hey can i get your wallpaper ?
@naxxtor
@naxxtor 7 ай бұрын
In the interests of portability, rather than installing SDL2 at the system level I've included the SDL2 development package within my project (under a folder dep) and use ``` set(SDL2_DIR ${CMAKE_CURRENT_LIST_DIR}/dep/SDL2/cmake/) ``` to allow find_package to find it. Also to ensure the DLL gets copied to the build directory I've added this to automate this step (where my-project is the project name) ``` add_custom_command(TARGET my-project POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy -t $ $ COMMAND_EXPAND_LISTS ) ``` Rather than manually copying the DLL (which I'll probably forget when setting the project up on a new machine).
Debugging C/C++ with LLDB Tutorial
40:06
constref
Рет қаралды 24 М.
Mom's Unique Approach to Teaching Kids Hygiene #shorts
00:16
Fabiosa Stories
Рет қаралды 38 МЛН
Spot The Fake Animal For $10,000
00:40
MrBeast
Рет қаралды 195 МЛН
How to Properly Setup C++ Projects
32:46
The Cherno
Рет қаралды 102 М.
JPEG is Dying - And that's a bad thing
8:09
2kliksphilip
Рет қаралды 19 М.
Introduction to CMake Crash Course
14:08
PunchedTape
Рет қаралды 13 М.
Why do we use SDL with C & C++?
16:26
pikuma
Рет қаралды 42 М.
BEST WAY to make Desktop Applications in C++
26:00
The Cherno
Рет қаралды 900 М.
The only CMake tutorial you will ever need (easy CMake setup tutorial)
12:50
Low Level Game Dev
Рет қаралды 116 М.
Making Simple Shared Object (.so) in C on Linux
5:48
Nir Lichtman
Рет қаралды 8 М.
Creating and Using Libraries in CMake [Ep3]
13:51
sudocpp
Рет қаралды 11 М.
CMake, How it Works (At Three Different Levels)
4:36
Kea Sigma Delta
Рет қаралды 10 М.
Nokia 3310 top
0:20
YT 𝒯𝒾𝓂𝓉𝒾𝓀
Рет қаралды 4,3 МЛН