How to Install Libraries in C++ (via CMake and Vcpkg) [READ DESC]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone today we'll be doing a cmake and vc package tutorial to install and use c plus libraries now if you're on windows you'll need visual studio 2022 or another c plus plus compiler like msis mg mingw something like that you know gcc clang on windows but i'll be using visual studio 2022 for the compiler that doesn't mean that if you're on another operating system that you can't make use of the tutorial because i'll also be using visual studio code now so yeah you can you could also install this i'll be doing a tutorial with visual studio code as well next you want to install cmake you want to make sure you're using cmake 3.22 and up because only these versions support visual studio 2022 if you try using visual studio 2022 with a older virtual cmake it won't work next up is a bit more harder to install its vc package it's not as easy as downloading something and running it you actually have to clone something you can either clone it or you could just download it into github desktop or download the zip i've already used github desktop and downloaded it here and from here you want to open a terminal and i've opened a terminal over here and what you want to do is bc vc package won't be available yet you want to actually run the bootstrap you can see it's called bootstrap bc package.bat so what do we have boot strap vc package.bat and then we want to disable the metrics we disable the metrics and we've installed vc package but we want to actually integrate the installation so that we can use it in visual studio or ms build this is also helpful if we want to use vc package with vs code so keep this path in just remember how you can get the path you can run this command anytime you want it'll return a path for you to use in it as a tool chain path next up to actually use vc package system wide we have to add this folder to our path we can do that here we can add it i've already added it somewhere here i don't know if you can spot it it's right here and next we want to create a new environment variable called vc package default triplet it is x64-windows why because that is the architecture and operating system i'm running and if i didn't set this vc package would install libraries and build them for 32-bit windows that is a huge problem because 64-bit should be the default right now and it is the default on visual studio 2022 not to mention 32-bit should not be used anymore because it's it's old technology after we've done that you want to make sure you can in a new terminal you want to make sure you can spot it since i've already added vc package we can actually spot it we can it's detectable but if you haven't if you just added it to path you need to open a new terminal now since we've installed vc package we can do an example of installing the library we can do vc package install cpr cpr is the library i'm going to be using as my example on how to actually making an http request now you'll see that when you install stuff you have it gives some information out that's why you don't want to install in a terminal and not have a project open so let's actually open up or create a new project what i'll be doing is i'll be doing a project in visual studio 2022 i'll be creating a new project in visual studio code and then lastly i'll be opening up the visual studio project in vs code so that's three things we'll be doing you can see i've done it i've done this step multiple times so you want to create a new project select cmake project and click create the first thing you want to do when you get here is configure cmake let us see what is going on but here we go you want to manage the configurations how so you want to actually set the cmake toolchain file to vc package.cmake this is so that you can actually use libraries the next thing you want to do is create a new file called vc package you want to create a new file called vc package rf.txt rf stands for response file because if you look at the documentation real quickly i will pull it up you can see that it takes something in and why do we do this because we can just when we when if we need to go back to this project and we need to see what libraries we use we have this file called the vc package rf.tax and we can just open a terminal and [Music] we just have to do bc package pc package vc package rf dot text and i will try some i will experiment really quickly on if that works and it does and we can see that it installs the library for us now since we've already installed it it's not gonna build it again i didn't mention it but if this is your first time installing it it will take about two minutes to build so do keep that in mind before so that you might have to pause the video actually and we're given this output to put into our cmake list so we do that or so i thought that can i copy that or not ctrl shift c maybe oh here we go we can't use our keyboard but we can just do copy and there we go now you can't use main you actually have to use the project name and that should be it now if we go back to our documentation for cpr we can see that we have to do include let's include and we don't want to use using namespace std we don't want to do that because the std the standard library is huge and we don't want to make a mistake we can do cpr response like that and then we'll do r.text now let's run this to see if we made a mistake you'll notice that the build was insanely quick and that's because we don't need to re-download and rebuild the library for any new projects that use that library it works so let's move on to our next tutorial which is vs code now this was an old project of me doing it so let's actually create a new folder before we do this and we'll do it in the same folder here let me close this we'll do cmake project five open this in ps code and it's blank so what do we have to do in vs code to set up vs code for cmake and vc package well first thing you want to do install c or c plus plus and install c make tools after you've installed cma tools you'll probably have to edit some settings because you can't just use vc package directly and you'll notice that there's nothing called tool chain why is this i have no idea but you have to open up the settings.json and you'll see over here it's called cmake configure settings and set cmake tool chain file to this path which was from the integrate install it's the same path after you've done that things should work a bit better all we have to do is create cma quick start and we'll do this if these visual studio 2022 has been installed and you can't see it you just click scan for kids you might need to restart your computer i don't know why 2019 is still here but we'll go with amd64 because that's what i'm using or that's what i want we'll do cmake project we'll do example http or something like that we'll say we're running an executable and now we're here like before we want to create a file called vc package rf dot text and we're going to install cpr and our terminal we'll do vc package vc package rf and then we'll do act and do that of course it works i want to go back to output and actually we want to copy this over again we do this and vs code is a bit better at handling handling tabs that tab space after we've done this some things should happen and you'll say oh we're good to go no we're not good to go yet let's go to main.cpp really quickly and we'll edit the code over here so that we can run the example because you'll see some issues with the vs code right now if i can get them to occur you'll see that the include path the inclusion is not possible so let's actually build this really quickly and see what happens but another thing to actually do just for helping yourself is to create a run target so if you create a new run target it'll make your life easier when you want to build and run we can do cmake sat build target to run or let me see cmake cache or whatever and it should pop up anytime now any moment there we go we do this cmake build and we should be good this will not go away easily so let's actually try to remove that if we go here this might not work but the include path needs to be where the you know the same thing where cpr is installed which is this path over here so let's plug that in you didn't see what i did i went to installed x64 windows then i said include and this is the include path now will this work maybe maybe not it seems to have worked anyways that works if you didn't if you don't believe me let me let me show you again that it works build you'll see that okay i didn't oh yeah it works but you want to see the same taxes before so let's do that and again with as before since the library's already built once we don't need to build it over and over again and that's going to save us a lot of time when we have multiple projects using the same library that works but we'll do one more project now and that project is can we open the visual studio project and use it in visual stud and visual studio code let's find out the first thing that'll happen is a kit will be you'll have to select a kit just for jokes we will do x86 amd64 because i have no clue what that is and you see this this cmake tools would like to configure intellisense for this folder this is what i was looking for before but you want this to be always true so let's go i just want to see something really quickly but you want to click allow and what that will do is that when you look at the cmakeproject.cpp you'll notice that there's no issues here and you'll probably say oh but we already we already changed that issue and uh let me let me let me see if we did but as you can see the default ignore the include path probably changed there's this thing called default configuration provider so this is probably something you want to change in our default settings but anyways let's build the project and like before it'll just build there's no build and run build and run there's no build and run so the only thing we'd have to change actually is add that run script we do this we save it multiple times and we just do c make build target click run and bam we did it but anyways that is a tutorial on how to use cmake vc package with visual studio or visual studio code and yeah
Info
Channel: elibro
Views: 30,107
Rating: undefined out of 5
Keywords: C++, cpp, Visual Studio, C/C++, C programming, programming, tutorial, code, coding, Visual Studio Code, VSCode, VS Code, CMake, VCpkg, Getting started, Make, automation, Linux, Windows, Solution, Sln, cpr, Example, Project, C++ Project, C++ Tutorial, Beginner C++, Beginner, Visual Studio 2022, Cross-platform, cross platform, cross-platform, develop, development, cross-platform development, gcc, clang, compiler, Compile, github, telemetry, vcpkg, git
Id: FeBzSYiWkEU
Channel Id: undefined
Length: 16min 47sec (1007 seconds)
Published: Tue Dec 14 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.