Makefile Support in Visual Studio Code - Makefile VSCode Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey in this video I'm going to share with you how to use makefiles inside vs code make files have been around forever vs code is fairly new but they work together very well I love both these tools and I love how they come together uh I'll show you how to do a number of things using make files and how that integrates with vs code and if you stay to the end I'll share with you why I think make files are not going anywhere all right here is my little C project and I'm going to use it to demonstrate how make files work to you so I'll just show you the code I'll show you how it works we'll run it a little bit and then from there I'll show how to translate that to a make file and then we'll we'll go into seeing how it works in vs code so this is my program uh flip coins all it does is it seeds a random number and you give it some number of iterations and then it flips a coin printing whether it's heads or tails so I'm just going to build that I I build it using GCC then I run it I'm going to run it a hundred times look at that 50 heads and 50 tails that doesn't happen every time because it's random there we go that seems a bit uh more likely and we can run it what happens look at that now we're talking as the number of flips gets bigger we tend more and more towards 50 50. right like at this many flips we're probably always in the four nine zones right let's see yeah now we're like four nine nine six and the more numbers we add on The Closer that's gonna get uh to five the the closer we get to half I suppose when I give it five thousand it's getting close to five so that's the program and how you run it to to use a make file we just basically encode these steps into a make file so the the structure for a make file is always that you have a Target name and then you have prerequisites and then you have your recipe that you run so the inputs that I have is just my single file my coin flipper.cpp and when that file changes and I run my build I want to produce a new Target so that is what this step does right once it reduced the target the next thing I want to do is run it so I have my run Target here and my run target has as a prerequisite this coin flipper step and then it just runs it with an input of 10. I don't really have a test step there's no unit test in this but I did put together a test Target where just to make sure my random numbers are working I'm going to run it with a large amount and we can just visually see like okay does it seem like it's 50 50. and then the last thing I have is a clean step where I'm just removing that stuff so this is a simple make file I've also set up a default goal so that when I just run make in general it's going to do a build right if I want to do any other step like a clean then I have to specify that or a run right that it all makes sense now to to use vs code to do make file I mean I'm I'm already in vs code and I'm already using the terminal so you can just do this but vs code obviously has a lot of great extensions and there is extensions to deal with make files for instance if you go to your extensions and you search for make file you will find this one produced by Microsoft make file tools and you want to install that it says it's a preview but it's actually been out for a while and it's got a ton of downloads so just install that then if you use this little gear you can go into extension settings and in here you can see that it is quite customizable you could change the version of make that's being used you could add some special paths I actually do have um the default version of make on my Mac is a little bit old so I do actually have the newer version installed in Brew here so I could tell it please use gmake rather than make I'm not going to do that but once you have this installed and you open up your make file or a project with a make file you get this nice side menu I believe these are called perspectives or slide out menus I'm not really sure but from here you can hook up your make file for instance set my configuration to default set my build Target to what was my build step it was coin flipper so that's my build step where I'm building my coin flipper and then you can see yeah my launch Target when I run it is to run this coin flipper dot out so we have here our coin flipper dot out if we do a make clean then oops it's gone we do a build then we can see it's back and then if we do a run then we can see look at that it ran 47 heads 53 Tails so that is a kind of nice make file integration in vs code I'll probably just keep using the terminal because it's kind of what I like but this is super neat and I think you can add more things uh yeah you can configure clean there's lots you can do there so why would you be using this combination of vs code and make files well I like make files because they work with any language they work with any tool and as you can see there's Integrations everywhere to make them work they're they're just very flexible you learn how a makefile works and you know you can use it in lots of places and it's great just also for this kind of like test Runner steps where you're just you know specifying some some actions that you do in your development environment if you are looking to learn more about building software check out some of my other videos here on the Earthly Channel uh I work for Earthly Earthly as an open source build tool if you like software development if you like make files uh Earthly is kind of like Docker for builds it lets you build software locally in your CI using a you know a simple kind of make file ask Docker file-esque syntax hard to describe in a quick video but uh go to earthly.dev check it out it's in the description I I think you're really going to like it and if there's other videos you'd like to see please let me know
Info
Channel: Earthly
Views: 23,419
Rating: undefined out of 5
Keywords: makefile, vscode, cpsc221, launch.json, tasks.json, cppdbg, linux, programming, c++, visual studio code, vs code extensions, vs code extension, visual studio code tutorial, vs code shortcuts, vscode tutorial, makefile tutorial, simple makefile, c++ makefile, make, what is a makefile, makefiles, c programming, use of makefile, how to use makefile, visual studio code makefile, makefile in vscode, introduction to makefile
Id: vAS4R5P0Orc
Channel Id: undefined
Length: 6min 51sec (411 seconds)
Published: Tue Jan 17 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.