![constref](/img/default-banner.jpg)
- Видео 18
- Просмотров 93 454
constref
Канада
Добавлен 30 дек 2018
This channel is about general programming, but focusing a lot on C++, game development and web programming.
Creating CMake Libraries - That others can find and use.
In this video we're going to create a CMake library, and then configure that library so that we can generate everything needed for it to be properly built, installed and distributed. We'll go over installing files with cmake, generating the required cmake files so users can install and find it on their system, and finally build and link against it!
github.com/constref/cmake-examples/tree/master/cmake-library
00:00 - Introduction
01:25 - The build configuration
02:48 - Setting up include directories
04:36 - Creating the EXPORT target
05:40 - Installing the EXPORT target
07:35 - Installing the public header
09:06 - Making it findable!
10:02 - Find vs Config Scripts
11:36 - Creating the Config File
14:...
github.com/constref/cmake-examples/tree/master/cmake-library
00:00 - Introduction
01:25 - The build configuration
02:48 - Setting up include directories
04:36 - Creating the EXPORT target
05:40 - Installing the EXPORT target
07:35 - Installing the public header
09:06 - Making it findable!
10:02 - Find vs Config Scripts
11:36 - Creating the Config File
14:...
Просмотров: 669
Видео
Build, install and find C/C++ dependencies, CMake and find_package
Просмотров 3,5 тыс.11 месяцев назад
This tutorial shows how to add 2 different libraries into an example project. In one case we add the SDL2 development library provided by SDL2 using find_package(). In the 2nd example we first build and install the Freetype2 library, then we tell CMake how to find it and add it to our project with find_package() alongside SDL2. We'll be doing this all Visual Studio 2022 and using a CMake projec...
Setup SDL2 with CMake and Visual Studio (Game Development)
Просмотров 10 тыс.Год назад
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...
MSYS2 - GCC/MinGW on Windows (C/C++ Development)
Просмотров 19 тыс.Год назад
In this video I demonstrate how to install and setup MSYS2 on Windows. We install GCC and compile a small C program for Windows. We also look at installing packages using pacman, using Windows Terminal as well as upgrading MSYS2. ArchWiki pacman: wiki.archlinux.org/title/pacman 0:00 Introduction 0:29 Installation 2:12 MSYS2 Environments 4:53 MSYS2 vs WSL2 7:38 Installing Packages 10:34 Windows ...
Boiler Game Engine Development Update 5/5/2021
Просмотров 2223 года назад
In this video I show off the GLTF loader, animation system, skybox support, deferred renderer, dynamic light and much improved frame rate of the Vulkan renderer.
Compile-time vs run-time polymorphism with C++
Просмотров 3,8 тыс.3 года назад
In this video we go over runtime, virtual function based polymorphism, and then we look at how we can achieve polymorphic code using compile-time methods while avoiding any performance penalties due to virtual function dispatch. The method presented here may be helpful when trying to optimize a game/engine main-loop, avoiding indirection due to virtual calls.
Advent of Code 2020 - Day 3 (C++ Problem Solving)
Просмотров 3343 года назад
In this video we solve day 3 of Advent of Code (AOC) 2020 using a pretty basic iterative approach and some modulus.
Advent of Code 2020 - Day 2 (Problems 1 & 2)
Просмотров 1843 года назад
Here I solve the AOC day 2 problems. Using string::find() stoi() and substr() to easily parse the string and validate the password. I know I could have counted only the letter in question in each policy, but my brain gravitated towards the reusable code :) Here's a link to my LLDB Debugging video: ruclips.net/video/2GV0K9Y2MKA/видео.html
Sorted arrays faster to process than unsorted ones? Stack Overflow Questions
Просмотров 1253 года назад
"Why is processing a sorted array faster than processing an unsorted array?" A stack overflow user asks why processing a sorted or unsorted version of an array results in a drastic performance difference. We discuss CPU branch prediction and why it can be important for optimization. Using std::sort from STL Original post: stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-fas...
Advent of Code 2020: Day 1, Problem 1 (C++ Problem Solving, 2 Solutions)
Просмотров 6823 года назад
In this video we're solving the day1a problem in two approaches. First approach is a slow, crappy O(n^2) solution, and then a faster approach using binary search.
Boiler 11/16/2020 (Littlest Tokyo)
Просмотров 1953 года назад
Demo of the current state of Boiler game engine rendering "littlest tokyo".
Debugging C/C++ with LLDB Tutorial
Просмотров 26 тыс.3 года назад
In this tutorial, I demonstrate how to get familiar with and make use of LLDB from the terminal/command line and debug your C and C programs. We go over starting LLDB, setting breakpoints, inspecting variables and using watchpoints. Part 2 will come soon with a deeper dive into more LLDB features.
Algorithms: FrogJmp
Просмотров 2383 года назад
Solving the FrogJmp problem from Codility. In this video we learn about ternary and modulus.
Algorithms: BinaryGap (C++)
Просмотров 2,2 тыс.3 года назад
Showing how I solved the BinaryGap challenge on the Codility website, using C . The method can be applied to other languages such as Java and JavaScript.
Boiler - Jul 2, 2020
Просмотров 1344 года назад
Just got properly texturex GLTF scenes loaded and rendered correctly.
CMake Tutorials - 3. Project and C++ Configuration
Просмотров 1,5 тыс.4 года назад
CMake Tutorials - 3. Project and C Configuration
CMake Tutorials - 2. Add 3rd party library with find_package
Просмотров 22 тыс.5 лет назад
CMake Tutorials - 2. Add 3rd party library with find_package
CMake Tutorials - 1. Create a project, and add_executable
Просмотров 3,3 тыс.5 лет назад
CMake Tutorials - 1. Create a project, and add_executable
Hi, nice video, I found it very helpful to understand some concepts, and some lines of cmake. Although I got some questions, if you don't mind. Basically, when I built the project it throws me an error saying it was not able to find my headers, so in the cmake of my project I added an include_libreries with the path to those headers, when I reran the build command again It throws me an error saying that it didn't identify the namespace that are in the hpp files, something like this "error: ‘MyNamespace::secondNamespace’ has not been declared MyNamespace::secondNamespace::Myfunction" and highlights the second Namespace, to be honest I don't know what could be causing this error could you help me to understand? by the way I'm working with ubuntu and the library has several headers and their own cpp file. thank you again for the video
Wilson Kimberly Moore Jennifer Lee Linda
This is the best cmake tutorial I ever seen on youtube, Thanks man. I have a one question, I currently working on project that uses "glfw3" as an external library, After precompiling It, when I use "find_package(glfw3 REQUIRED)". it does find that library but when I trying link with it.... it gives me a linker error... I'm doing something like this "target_link_libraries(<my_lib> PRIVATE glfw3)", I don't know what is going on, when I change "glfw3" to "glfw" it works, Is it something to do with library it self, or Is it me doing something wrong.....but my qustion is how can find the package name is, when i'm trying to use find_package function... and the other thing is "namespace" can you explain it little bit....
Hey thanks for the kind words. I just cmake-installed glfw on my system, and I'll give you a tip of something I tend to do. When I'm not sure what the targets/namespace setup is like for the library I wish to link to, I go to the "lib\cmake\" folder and I look for the Targets file, the same file I showed how to generate in this video here. In this case, when I poke around in "lib\cmake\glfw3", the targets file seems to export a "glfw" target, meaning, you should probably be linking to that, rather than glfw3, as there is no target defined with the name "glfw3". The package name you're looking for, and the target name you link to DO NOT have to be the same, they are very different things. You can have a package named "foo", so you'd find_package(foo, but foo might export a bunch of libraries called "bar1", "bar2", "bar3", and it's namespace might be "foo". So when you're linking you might end up doing target_link_libraries(myapp foo:bar1 foo::bar3... etc). Hope this makes sense and helps, let me know if you have any other questions.
Why even make a video when there's no github link to example project?
Here you go: github.com/constref/cmake-examples/tree/master/cmake-library
Nice Video, you are accually the first guy on youtube who explained it. But I have a question: 20:40 - When I use this command, it says that the source directory does not appear to contain CMakeLists.txt - And indeed, there is no file like this in the whole file tree after using cmake --install. What should I do? I have to use Qt so its a bit different I quess
Hey, there should be no CMakeLists.txt in the tree AFTER doing a --install. You are installing the library and the CMakeLists.txt file is the instructions on how to build/install. After installing, you would have the other scripts that I outline in the video which other projects would use to find all your headers and libs. What I'm showing at 20:40 is how one would pass the CMAKE_PREFIX_PATH variable to CMake if they weren't using Visual Studio/IDE and wanted to actually find and link with our library. This part of the video was a test project showing that we had set things up correctly and can actually find and link with our library. If you have gotten to that part, was able to build and install your library, and the files in installed directory match what I showed earlier in the video, congratulations, you did things correctly :)
What happens to all that on Windows? Is there a Windows equivalent to the linux usr/lib system?
The entire video is based in Windows. What are you having trouble with? There is no standard usr/lib equivalent, check the video again, I go over how to install a package and how to then find it on Windows.
This is god sent stuff.
Excellent explanation!!! In my case, cleared up a lot of confusion. thank you so much.
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)
Excellent video! Would you be able to do a similar video on Google Protobuf?
I was just curious where you were able to find all the information for this, CMake has some rather verbose documentation which seems to be a trend for C++ and so I wanted to know what resources you used or if you're just a CMake Wizard
no sudo?
why this guy doesn't have more subscribers!!! wow sir your channel is a gem
Thanks for explanation. Can you just explain what would be the difference if I use: 1. package installed with apt-get (and where it is stored) 2. package installed in conda-env (and where it is stored)
Please continue! Very descriptive and clear! Thanks!
hey can i get your wallpaper ?
thank you, this was really enlighting! I enjoyed how you resolved my questions that just came up on the go intuively
Great tutorial! It is not only a good lldb tutorial, but it is also a good general debugging overview for newcomers.
That was actually very useful. The main reason why I was trying to find some other ways to include third party libs (by now I've just either downloaded source files and compiled them, or used precomopiled binaries) is that I wanted to share my project across different platforms, and now I find it very convenient to have users download dependencies themselves and simply include the paths in DCMAKE_PREFIX_PATH, or if they're on linux it's handled even more.. "practically". So yea, thanks for the video!
This video makes zero sense to me. Your alternate solution has just built another layer on top of the application. You haven't added or changed any lower layers which is actually calling the RENDER function, which was our purpose for having it virtual in the first place. The solution doesn't even show the new implementation of the render function. How do we make it so it has the same signature as all other renderers? What if I have 10 methods that have the same signature but needs to be handled differently by each renderer? The code duplication would be insane, no? I guess, if one doesn't care about the signature being consistent we could just not bother but the whole point of virtual functions is that they inherit the same signature but with a different body. How is this solved?
Its not "another layer", its using a different template specialization to remove the need for virtual dispatch and indirection on the hot path. It replaces the virtual calls which would otherwise be INSIDE the loop, with a single virtual call OUTSIDE the loop. In an application like a game engine, removing virtual calls from the hot-path can lead to significant improvements in speed, for various reasons. Obviously it doesn't replace virtual calls, that's not the point of the video. As for the signature thing, I'm not sure what you're asking me, but each type of render function would need to have the same signature, otherwise the code inside run() wouldn't compile if a particular render() specialization has the wrong signature. Let me know if this makes sense.
@@constref1983 I just wanna start off by saying that I sounded unnecessarily harsh in my original comment. Sorry for that. What you are saying does make sense when just reading it but in the context of the video, it didn't make much sense. After rewatching the video now after 2 months, I understand why I must have been confused. At 7:18, you show two different classes for renderer but they do not inherit from anything. You do say that you had the code stripped down just for saving time, but they didn't even inherit from anything still. The whole point of polymorphism seemed to be lost and there would be no guarantee that some renderer actually implemented all the same functions. It made it seem like the solution was to create decoupled render classes that will be used through templates, but in actuality, the render classes would still use polymorphism. By giving the template type as the super class it would indeed prevent having to enter the v-table. I must have misunderstood that part, which was silly. I think simply having them inherit from something would have made it clearer but I can also see how that should be implied. My bad. The solution is interesting and I definitely learned some tricks. It's a great video, which I should have mentioned in my original comment!
And this did it! Stack overflow and other forums had it wrong or were confusing the whole time
Thank you. But I cannot figure out why I don't see the "Cmake settings" button after right-clicking to the CMakeLists.txt
Has anyone told you how much you look like Ben Affleck?
Sadly visual studio only opens the cmake settings as a json file for me :-(
Are you seeing a cmake presets JSON file or cmake settings?
In your example of changing out the renderer via template argument, how does one even know T is actually a renderer? it could be a fat melting factory for all we know, no?
You don't, the compiler will simply give you an error if you try to call methods on an object which doesn't have those methods. This is where concepts can be helpful in enforcing some of the rules, video coming on that topic.
I wish people would quantify the "performance penalty" When talking about virtual methods for the last 3 decades. It's the same cost as adding 1+1, no? Or de-referencing a pointer. Are we scared to add 1+1 and talk about performance every time we do? Even in embedded or game programming, I don't know why people are so scared of dynamic polymorphism. ... and as far as I know you HAVE to have dynamic polymorphism in order to mock in your unit tests. You at minimum need to use an interface and have a concrete class. Maybe I'm wrong, but noone has ever shown me otherwise. I'd love to learn if I am wrong.
The conversation regarding pointer dereferencing is very different depending on the context. I've written many businesses applications where you're 100 percent correct, it's not a real cost, and the benefit of cleaner abstractions and runtime polymorphism far outweighs any virtual call cost. If you've ever worked on software with low latency requirements, that dereference is a very real cost, if it happens on the hot path. Anything you do 60 times or more per per second needs to be measured and optimized (within reason). I didn't give a renderer example just by chance. In my own game engine, when writing code in the hot path, these considerations have to be made, as well as other things such as how often you allocate memory, how you fragment your memory, avoid CPU cache misses or play nice with the branch predictor, etc.
How do one find proper segmentation error in lldb I use mac
This is how I wanted it ❤
I've been struggling for around 3 days to successfully compile SDL2 packages. I've managed to compile the core SDL2 package, but I can't figure out how to do the same for the others (SDL2_image, SDL2_ttf, etc.). My goal is to write a CMakeLists.txt that will compile all of the packages together, and then I can comment out which ones I don't need for each project. I don't know if it's a cruel twist of fate or what, but I ended up figuring it out as I was writing this comment. I'll put what I did here-> After downloading the VC version of the packages, I extracted the folders into a folder dedicated to all my SDKs. Then, I made an environment variable named "CMAKE_PREFIX_PATH" and set it to the path of the folder holding all of the SDKs. Now, in the CMakeLists.txt : I put a "find_package(PACKAGE_NAME REQUIRED)" statement for each package needed above the "add_executable()" line. Following the "add_executable()" line is the "target_link_libraries()" statement. This is the line I was having issues with for so long. It kept saying that the target couldn't be found. This is what worked on my machine: "target_link_libraries(${PROJECT_NAME} PRIVATE SDL2::SDL2 SDL2::SDL2main SDL2_ttf::SDL2_ttf SDL2_image::SDL2_image)". I imagine the bit before the double colons is the target and the bit following the colon is the lib. I'm not experienced with CMake in the slightest, but my file seems simpler compared to everything I found when debugging. Hope this helps
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 $<TARGET_FILE_DIR:my-project> $<TARGET_RUNTIME_DLLS:my-project> COMMAND_EXPAND_LISTS ) ``` Rather than manually copying the DLL (which I'll probably forget when setting the project up on a new machine).
Amazing video, but how to actually build such cmake libraries that actually produces this kind of install & cmake also produce the config.cmake automaticly
Is it possible to be as efficient in terminal lldb as a gui based debugger? To me it just seems annoying having to prompt everytime where as something like visual studio displays all the information while your stepping through.
Use the "gui" command
Nah, its good to know if you need to use it, but I use Visual Studio 95% of the time, and hop into Qt Creator from time to time. You can certainly get pretty speedy with LLDB in the terminal, but setting breakpoints, hopping around the call stack and inspecting is definitely going to be far quicker and easier using a GUI. Back when I thought I was cool because I didn't use an IDE, and ran LLDB in a terminal window, I always knew in the back of my head that I was objectively being inefficient, just so that I could feel like I'm somehow coding more old-school. Some people will be like "IDEs are slow", but that is only true on startup. I mostly use Visual Studio, and while it definitely takes more time to start up, once your project is open and you're coding, compiling and debugging in a cycle, its certainly quicker in the IDE, especially debugging. Anybody that tells you that they are faster when they alt-tab around between Vim, LLDBing via commands or staring at non-syntax-highlighted code are just lying. Something that really inspired me to not be a dork and focus on being productive was listening to John Carmack on Lex Fridman's podcast, particularly his answer when asked about Emacs vs Vim, and preferred editor.
Why does Renderer need to inherit from App? Wondering if it would be best to overload the App.run function to take a type render1 or render2 pointer. No inheritance needed.
I recommend you watch again, Renderer does not inherit from Application, Application specializes for a particular Renderer implementation at compile-time. Why would you prefer overloads anyways? Are you going to overload everywhere your application needs access to the renderer? When you want to avoid code duplication between your overloads, what will you do, use a base pointer to the renderer?
@constref1983 I was talking about the inheritance and polymorphism in the first example. Really just pointing out alternatives, maybe templates can be avoided and specialization isn't part of the conversation. All comes down to implementation.
Thank you so much for this video. It helped A LOT.
Thank you. Nice to know how to do this with Visual Studio. I'm just wondering if you will come out with a static linked tutorial in the future? This way we don't have to worry about including DLL's with the exe.
That's a good idea.
why don't you upload the code, people have a hard time moving back and fort to read your code.
8:53 9:53 11:06 mainapp 10:20 mainapp 13:55
Excellent explanation!!! In my case, cleared up a lot of confusion. Also the segment on adding a NEW profile in the Windows Terminal was very helpful.
Glad to hear I was helpful!
agree on that
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
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.
Thanks for the great tutorial! If you had experience, could you also do a tutorial using the IDE from JetBrains? In conjunction with the clang compiler and ninja generator. I think there is not enough information on the internet right now on how to build anything via cmake on windows and your knowledge is a treasure.
That's an excellent suggestion, I bet I can whip something up soon.
Great video. Thank you!
You're welcome!
Good and clear explanation
What if you do this? Let's say in the engine we only use the renderer interface - the header file, that is, essentially pointers to functions. And for each backend we implement it in dll. Thus, when starting the application, we decide which dll needs to be loaded, and if we want to use another one, we can ask to restart the application. This is how we solve the problem of virtual functions. We do not solve the problem of the minimum application size, but for example, for mobile platforms we can supply only one dll that will be used there. And we do not load all dlls into RAM, just one. What do you think about this?
You have to ask yourself what that DLL will provide. It will very likely be a concrete implementation of an abstract class or interface, which would generally mean virtual method calls.
Thank you!!
You're welcome!
Thanks a lot!!!
You're welcome!
Thank you <3
Thank you for your guidance
You're welcome!
Very helpful
Nice tutorial!! Really helpfull and valuable!!
Glad it was helpful!
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 "".
Were you able to resolve this issue?
Not sure if you're still interested, but the find_package stuff must be entered in the nested CMake, not the global one
@@maartenofbelgium Not sure if you're still interested, but the find_package stuff must be entered in the nested CMake, not the global one
@@hobotookmyname legend, thank you!