How to Setup C++ on Linux
Key Takeaways
The video demonstrates how to set up C++ on Linux using CMake, Code::Light IDE, and g++ compiler, and how to create and execute a basic C++ project using Code::Blocks.
Full Transcript
hey what's up guys my name is Aero and welcome back to my C++ Series so you're using Linux to develop C++ code okay cool let's cover how we can set up the tools we need on Linux so that we can make C++ programs now of course there are so many different tools out there so many different ways to write and build your code I'm going to cover one of those ways one that I personally like I hope you're ready to do some serious setting up I mean you've chosen Linux so obviously you're going to be prepared to do some work basically we're going to use cmake to generate project files for an IDE called code light code light is a nice lightweight IDE that basically does pretty much everything you would expect but isn't too heavyweight and just lets us write our code in a nice way so let's go ahead and set everything up so we've got a virtual box VM here running mint 18.1 and I'm using KDE as my GUI so if I go ahead and open a terminal we can get started so the first thing I like to do is set up a directory here called Dev which is basically going to hold all of our development stuff um we'll make a and then basically inside here we'll have a like a folder for each project so I'll make a directory called Hello World um which is going to be uh what we're going to do here now we're going to set up a basic H World project now in terms of the applications that we actually have to install we basically need the ones that we really need are a compiler cake and code light so the first thing you're going to want to do to install all that is do pseudo app to get update that's just going to basically update and type in your root password that's going to basically update all of our package packages our package repositories and then once that's done we can actually install the packages we need so what we need are uh we'll do aptg install I like to use Vim as my terminal text editor um and then we'll get g++ as our compiler we'll get code light as our IDE and we will get uh cake and then just hit enter you can see It'll take 198 megabytes Y and this will take a while okay so once that is done let's go ahead and clear this so we've got nothing in our directory right now I like to make a directory called source and that's where I'll actually put all of my source files I'm going to just create a file in the source directory called main.cpp I'm just not I'm not going to write anything into it I'm just going to create the empty file um and we'll actually let code light handle that file for us we're going to need to set up a cmake file and then I also like to set up a build script so that we've got an easy way to generate a project so in terms of cmake we'll make that first I'm just going to use Vim you can use any text editor you like the file is going to be called cmak lists. text and this is going to basically just instruct cmake how we want to actually generate our code light project file so first of all we'll specify a minimum version of cake that we need um as a good rule of thumb I like to just roll with version 3.5 we'll then give our project a name so I'll call this hollow world and then we'll set up some variables essentially so uh in terms of like flags that we want to use for compilation um we want to use the existing ones so that's uh basically the existing cmake cxx Flags which are the compilation Flags um but in terms of what we actually want to do we want to add we want to display all warnings um errors of course and then in terms of like which standard Library we use um you can use C++ 11 C+ 14 doesn't really doesn't really matter for this project since we'll be just using we'll be printing hello world but um we can roll with 14 just to Future proof ourselves a little bit um we'll create a variable here called Source directory um and I'll actually set this to be uh the project Source directory um and then essentially just a folder called source so the project Source directory is the directory we're currently in and then inside there I'm just making I've just made a directory called source and that's where all my source files are so that works out pretty well um so we've set up these variables right those two lines were just variable we've set our flags and we've set our source directory now we actually need to somehow tell the compiler which files to compile so um again using cmake we can just use a globe for that so basically I'm going to specify that my source files are going to be in that Source directory and that Source directory is just this variable that I've made up here right and then basically anything inside that directory that ends in C++ and CPP I want to compile now if you had include directories and stuff you would also want to set that up but for now we're not going to do that that um we'll just add executable so this is going to be our Target um hello world is our project name and then which files we want to pass into there are going to be our source files if you had again an include directory or something you would also pass it in here but there we go that's all of our stuff uh that's that's our entire cake lists done so let's write and quit now we'll set up a script that will run seake for us so I'll call this build.sh now this isn't really going to build our code it's just going to generate the project and I'll show you kind of how this works in a minute but basically the first thing we want to do is make sure that bash is going to be able to execute it and all that so we'll add uh Bin sh as every bash script will have um then we'll do cmake uh- G so in terms of the target we're going to be using Code light Unix make files you can also use something like ninja if you like probably a bit better than this but this is just a bit easier to set up um and then as far as my build type goes I'm actually going to set that to debug my see make build type um because generating a debug configuration is probably what we want anyway since we'll be debugging a lot and you want to make sure the code light has a capital l here um and that's it we can write and quit that and that's how it's going to be our entire script very very simple so now we're ready to run our script now in order to run a script in Linux you have to mark it as as executable so we'll just do CH mod plus X and then build our s so we're just adding the executable flag to the build.sh file now we can run it and hopefully if you did everything correctly you can see that it's written some build files for us so if we look at the directory you'll see there's a number of new files here um the ones that we kind of care about are hell world. project and Hell world. workpace there are make files as well but um you can see that those kind of the important ones so now how do we open this in code light well I like to just open it through the terminal so you can just type in code light and then hello world. workpace now if you want to open it in the background so that you can still use your terminal just add an ampersand onto the end hit enter and code light should open now you're probably going to want to run through this setup I don't really care so I'm going to hit cancel um as you can see we've got our project here and our Target just make this a bit bigger um we've got our include directories so this is where all of our includes go sources just going to go in here um we'll double click the file to open it I'm going to just basically type out a simple Hollow World application so we'll say and we'll do our little cn. getet as well all right save that if you want to build it you can just hit build and build project output's down here and you can see that everything's fine zero errors zero warnings we're ready to go if we go back to terminal and I do an LS you can see we've got a hollow world uh file and it's actually executable right so that's our actual program so let's go ahead and run that there you go hello world we've written our first application if you want to run it inside here one thing I like to do is just go to preferences and make it use the built-in terminal emulator and then you can just do build run we can build it and execute it and you can see here it is running inside of code light all right that's it Linux is set up we're ready to write some code we're ready to learn some C Plus+ over the next few videos we're going to cover how C++ actually works because that's the key to learning how to write C++ properly until then you can follow me on Twitter and Instagram and if you really like this series you can support my videos by pledging on patreon.com for/ Theo until next time goodbye vom
Original Description
Twitter ► https://twitter.com/thecherno
Instagram ► https://instagram.com/thecherno
Patreon ► https://patreon.com/thecherno
Series Playlist ► https://www.youtube.com/playlist?list=PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb
How to Setup C++ on Windows ► https://www.youtube.com/watch?v=1OsGXuNA5cc
How to Setup C++ on Mac ► https://www.youtube.com/watch?v=1E_kBSka_ec
BEST laptop for programming! ► http://geni.us/pakTES
My FAVOURITE keyboard for programming! ► http://geni.us/zNhB
FAVOURITE monitors for programming! ► http://geni.us/Ig6KBq
MAIN Camera ► http://geni.us/CYUQ
MAIN Lens ► http://geni.us/ZM3CmG
Microphone ► http://geni.us/wqO6g7K
Slack ► https://slack.thecherno.com
Stream ► http://www.twitch.tv/thecherno
Website ► http://www.thecherno.com
Facebook ► http://www.facebook.com/thecherno
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from The Cherno · The Cherno · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
3D Game Programming - Episode 1 - Window
The Cherno
3D Game Programming - Episode 2 - Game Loop
The Cherno
3D Game Programming - Episode 3 - Arrays
The Cherno
3D Game Programming - Episode 4 - Drawing Pixels!
The Cherno
3D Game Programming - Episode 4.5 - How Rendering Works
The Cherno
3D Game Programming - Episode 5 - Playing with Pixels!
The Cherno
3D Game Programming - Episode 6 - Performance Boosting
The Cherno
3D Game Programming - Episode 7 - FPS Counter
The Cherno
3D Game Programming - Episode 8 - Alpha Support and More
The Cherno
3D Game Programming - Episode 9 - Beginning 3D
The Cherno
3D Game Programming - Episode 10 - Floors and Animation
The Cherno
3D Game Programming - Episode 11 - Rotation
The Cherno
3D Game Programming - Episode 12 - User Input
The Cherno
3D Game Programming - Episode 13 - Render Distance Limiter!
The Cherno
3D Game Programming - Episode 14 - Basic Mouse Movement
The Cherno
3D Game Programming - Episode 15 - Textures + More!
The Cherno
3D Game Programming - Episode 16 - Walking, Crouching, Sprinting + More
The Cherno
3D Game Programming - Episode 16.5 - Exporting Runnable Jars
The Cherno
3D Game Programming - Episode 17 - Small Adjustments + Birthday!
The Cherno
3D Game Programming - Episode 17.5 - Creating an Applet
The Cherno
3D Game Programming - Episode 18 - The Beginning of Walls
The Cherno
3D Game Programming - Episode 18.1 - A Few More Things
The Cherno
Episode 18.5 - Creating an EXE File in Java
The Cherno
3D Game Programming - Episode 19 - Rendering Walls
The Cherno
3D Game Programming - Episode 20 - Continuing Walls, Fixing Bugs, and Managing Crashes
The Cherno
3D Game Programming - Episode 21 - Texturing Walls, Fixing Clipping, and Fixing the Mouse
The Cherno
3D Game Programming - Episode 22 - Random Level Generator + Properly Fixing Clipping
The Cherno
3D Game Programming - Episode 23 - Graphical User Interface (GUI) Launcher
The Cherno
3D Game Programming - Episode 24 - Making Our Launcher Work
The Cherno
3D Game Programming - Episode 25 - Writing and Reading Files
The Cherno
3D Game Programming - Episode 26 - Custom Resolutions
The Cherno
3D Game Programming - Episode 27 - Decorating the Launcher
The Cherno
3D Game Programming - Episode 28 - Continuing our Custom Launcher!
The Cherno
3D Game Programming - Episode 29 - Launching The Game
The Cherno
3D Game Programming - Episode 30 - Colour Processing In-Depth
The Cherno
3D Game Programming - Episode 31 - Sprites!
The Cherno
3D Game Programming - Episode 32 - Sprite Mapping
The Cherno
3D Game Programming - Episode 33 - High Resolution Rendering
The Cherno
3D Game Programming - Episode 34 - Entities
The Cherno
Genesis - My Game for Ludum Dare 24
The Cherno
Vlog + Ludum Dare Results
The Cherno
Game Programming - Episode 1 - Resolution
The Cherno
Game Programming - Episode 2 - Threads
The Cherno
Game Programming - Episode 3 - Game Loop
The Cherno
Game Programming - Episode 4 - Window
The Cherno
Episode 5 - Buffer Strategy
The Cherno
Game Programming - Episode 6 - Graphics Initialized
The Cherno
Game Programming - Episode 7 - Buffered Image and Rasters
The Cherno
Game Programming - Episode 8 - The Screen Class
The Cherno
Game Programming - Episode 9 - Rendering Pixels
The Cherno
Game Programming - Episode 10 - Clearing the Screen
The Cherno
Game Programming - Episode 11 - "Out of Bounds, Baby!"
The Cherno
Game Programming - Episode 12 - Negative Bounds
The Cherno
Game Programming - Episode 13 - Timer
The Cherno
Game Programming - Episode 14 - FPS Counter
The Cherno
Episode 15 - Tiles
The Cherno
Game Programming - Episode 16 - The Map
The Cherno
The Walls 2 - Minecraft PvP Survival Map
The Cherno
Game Programming - Episode 17 - Key Input
The Cherno
Game Programming - Episode 18 - Controlling The Map
The Cherno
More on: Tool Use & Function Calling
View skill →Related Reads
📰
📰
📰
📰
Terraform Cloudflare DNS Checklist Before Every Apply
Dev.to · Oleksandr Kuryzhev
Building a Windows Laptop Monitoring Agent with Webex and Email Alerts
Dev.to · sam codex
What Is Infrastructure as Code? A Beginner's Guide
Dev.to · Muskan Bandta
I just released SKTR, a deterministic architecture review CLI
Dev.to · Pablo Rubianes 🇺🇾
🎓
Tutor Explanation
DeepCamp AI