<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>C++ programming Archives - NeuralLantern.com</title>
	<atom:link href="https://www.NeuralLantern.com/tag/c-programming/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.NeuralLantern.com/tag/c-programming/</link>
	<description></description>
	<lastBuildDate>Mon, 04 Aug 2025 01:16:48 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://www.NeuralLantern.com/wp-content/uploads/2025/04/cropped-2025-04-04-Lantern-03-32x32.png</url>
	<title>C++ programming Archives - NeuralLantern.com</title>
	<link>https://www.NeuralLantern.com/tag/c-programming/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Demystifying x86-64 Program Segments: Stack, Heap, and More</title>
		<link>https://www.NeuralLantern.com/demystifying-x86-64-program-segments-stack-heap-and-more/</link>
					<comments>https://www.NeuralLantern.com/demystifying-x86-64-program-segments-stack-heap-and-more/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Mon, 04 Aug 2025 01:16:47 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[BSS section]]></category>
		<category><![CDATA[C++ programming]]></category>
		<category><![CDATA[coding tutorial]]></category>
		<category><![CDATA[computer architecture]]></category>
		<category><![CDATA[data section]]></category>
		<category><![CDATA[heap memory]]></category>
		<category><![CDATA[low-level programming]]></category>
		<category><![CDATA[memory management]]></category>
		<category><![CDATA[program segments]]></category>
		<category><![CDATA[segmentation fault]]></category>
		<category><![CDATA[stack overflow]]></category>
		<category><![CDATA[virtual memory]]></category>
		<category><![CDATA[x86-64]]></category>
		<category><![CDATA[Yasm assembly]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=195</guid>

					<description><![CDATA[<p>Understand x86-64 program segments like stack, heap, data, and BSS. Learn to avoid segmentation faults and stack overflows in this beginner-friendly coding tutorial.</p>
<p>The post <a href="https://www.NeuralLantern.com/demystifying-x86-64-program-segments-stack-heap-and-more/">Demystifying x86-64 Program Segments: Stack, Heap, and More</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="Demystifying x86-64 Program Segments: Stack, Heap, and More" width="1380" height="776" src="https://www.youtube.com/embed/GUicAuRPgPA?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">Join us for a clear, engaging look at x86-64 program segments! We break down the text, data, and BSS sections, explore stack vs. heap memory, and show a real stack overflow in C++. Learn why segmentation faults happen, how virtual memory works, and tips to avoid crashes. Whether you&#8217;re new to assembly or leveling up your coding skills, this video is packed with insights to boost your understanding of low-level programming. Subscribe for more coding deep dives!</p>



<p class="wp-block-paragraph">Introduction to x86-64 program segments 00:00:01<br>Understanding segmentation faults 00:00:12<br>Importance of segments in assembly 00:00:32<br>Overview of assembly program structure 00:01:09<br>Defining segments in Yasm assembly 00:01:49<br>Data section: Initialized global variables 00:02:20<br>BSS section: Uninitialized variables 00:03:23<br>Text section: Code and functions 00:03:59<br>Global and extern function declarations 00:04:41<br>Stack: Local variables and return addresses 00:07:11<br>Stack overflow example in C++ 00:08:48<br>Heap: Dynamic memory allocation 00:11:31<br>Stack vs heap memory growth 00:11:56<br>Virtual memory and memory allocation 00:14:00<br>Demonstrating memory overflow with heap allocation 00:16:59<br>Summary of segments and their purposes 00:17:59<br>Closing remarks and call to subscribe 00:18:47</p>



<p class="wp-block-paragraph">Thanks for watching!</p>



<p class="wp-block-paragraph">Find us on other social media here:</p>



<ul class="wp-block-list">
<li>https://www.NeuralLantern.com/social</li>
</ul>



<p class="wp-block-paragraph">Please help support us!</p>



<ul class="wp-block-list">
<li>Subscribing + Sharing on Social Media</li>



<li>Leaving a comment or suggestion</li>



<li>Subscribing to our Blog</li>



<li>Watching the main &#8220;pinned&#8221; video of this channel for offers and extras</li>
</ul>



<p class="wp-block-paragraph">Hi there!</p>



<p class="wp-block-paragraph">Let&#8217;s talk about x86-64 programs and their segments and the purpose of the segments.</p>



<p class="wp-block-paragraph">Probably when you&#8217;ve been programming in the past you&#8217;ve seen segmentation fault errors.</p>



<p class="wp-block-paragraph">If you&#8217;ve accidentally crossed the bounds of some appropriate memory location, if you</p>



<p class="wp-block-paragraph">have an array and you try to index it way outside of bounds or something, you might</p>



<p class="wp-block-paragraph">have seen a segfault.</p>



<p class="wp-block-paragraph">SegFaults basically come from the idea that you have crossed a segment boundary.</p>



<p class="wp-block-paragraph">Segments used to be really, really important.</p>



<p class="wp-block-paragraph">They&#8217;re a little bit less important now that we have virtual memory.</p>



<p class="wp-block-paragraph">I&#8217;ll just talk a little bit about them.</p>



<p class="wp-block-paragraph">I&#8217;m going to be discussing this from the perspective of an assembly program,</p>



<p class="wp-block-paragraph">just because even in higher level languages,</p>



<p class="wp-block-paragraph">your languages will typically be compiled down to assembly</p>



<p class="wp-block-paragraph">first before they actually hit machine code and your actual executable binary.</p>



<p class="wp-block-paragraph">So if you&#8217;re not interested in Yasm Assembly,</p>



<p class="wp-block-paragraph">Yasm assembly I think this could still be worth it for you to watch because</p>



<p class="wp-block-paragraph">you&#8217;ll be able to see the different segments and just kind of get a better</p>



<p class="wp-block-paragraph">understanding of what they are okay so I&#8217;m gonna actually write a very very</p>



<p class="wp-block-paragraph">very quick program in assembly it&#8217;s not gonna really do anything I just want you</p>



<p class="wp-block-paragraph">to show I just want you to see the segments that are involved so for</p>



<p class="wp-block-paragraph">starters let&#8217;s just pretend that I&#8217;m writing a an assembly program here we&#8217;ll</p>



<p class="wp-block-paragraph">This is a comment just so you know what I&#8217;m about to type.</p>



<p class="wp-block-paragraph">Perhaps actually this is not the best editor.</p>



<p class="wp-block-paragraph">I don&#8217;t know why I pulled this up.</p>



<p class="wp-block-paragraph">Let me get Gene here.</p>



<p class="wp-block-paragraph">It&#8217;s a little bit better.</p>



<p class="wp-block-paragraph">Gene.</p>



<p class="wp-block-paragraph">There we go.</p>



<p class="wp-block-paragraph">Maybe I&#8217;ll save it somewhere.</p>



<p class="wp-block-paragraph">I&#8217;ll say segments assembly.</p>



<p class="wp-block-paragraph">And then now the comment gets highlighted.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">So in assembly in the ASM assembly,</p>



<p class="wp-block-paragraph">we denote various segments by using the section keywords.</p>



<p class="wp-block-paragraph">keywords so we&#8217;ll say section and then dot something indicating the type of segment that we&#8217;re</p>



<p class="wp-block-paragraph">defining so section text and then up here we&#8217;ll have another one section dot bss and you know if</p>



<p class="wp-block-paragraph">you already program assembly you know that somewhere in here is where the code goes right</p>



<p class="wp-block-paragraph">between these sections so just a quick recap of what the data section is it just is where you</p>



<p class="wp-block-paragraph">can name and initialize at the same time at the very top.</p>



<p class="wp-block-paragraph">Globals are not great, but sometimes you want to do that in assembly, depending.</p>



<p class="wp-block-paragraph">It&#8217;s better if you stick all your variables on the stack.</p>



<p class="wp-block-paragraph">Like if they&#8217;re a local variable, it&#8217;s a little bit better.</p>



<p class="wp-block-paragraph">Think of higher level languages.</p>



<p class="wp-block-paragraph">You typically want to avoid global variables if you can possibly avoid them and make</p>



<p class="wp-block-paragraph">everything else a local variable or a member variable.</p>



<p class="wp-block-paragraph">So that means somewhere else other than data, probably the stack, but or the heap.</p>



<p class="wp-block-paragraph">Anyway, you know, this is like the basic pattern.</p>



<p class="wp-block-paragraph">We&#8217;ll say, you know, my variable and then we&#8217;ll decide to say what data size it is.</p>



<p class="wp-block-paragraph">In this case, it&#8217;s DB for one byte of data.</p>



<p class="wp-block-paragraph">You could put a, I think DD in there or a DW for a word.</p>



<p class="wp-block-paragraph">Sorry, sorry, DW would be for a word.</p>



<p class="wp-block-paragraph">And then I think DD would be a double and then DQ would definitely be a quad word.</p>



<p class="wp-block-paragraph">So here quad word is eight bytes.</p>



<p class="wp-block-paragraph">And then I can sort of initialize it to some number.</p>



<p class="wp-block-paragraph">some number and now I have a global variable so not like a huge deal the BSS section is basically</p>



<p class="wp-block-paragraph">where you have uninitialized variables but there you can make huge amounts of variables you can</p>



<p class="wp-block-paragraph">make an array of variables so if I say my array something like that I could put resource queue</p>



<p class="wp-block-paragraph">to say I want the type of one item to be a quad word so you know eight bytes per item and then I</p>



<p class="wp-block-paragraph">could just say I want you know a hundred thousand items or something and I&#8217;ll</p>



<p class="wp-block-paragraph">double check that after I stop recording this video and correct it if I&#8217;m wrong</p>



<p class="wp-block-paragraph">it&#8217;s been a while since I actually typed BSS here and then in the text section</p>



<p class="wp-block-paragraph">this is where you put code and functions and things you typically want to have at</p>



<p class="wp-block-paragraph">least one entry point somewhere you know if you want to make like if you want to</p>



<p class="wp-block-paragraph">make this the entry point of your entire program you&#8217;ll probably do global main</p>



<p class="wp-block-paragraph">main and then this assumes that you use the GCC libraries and just sort of return from the label</p>



<p class="wp-block-paragraph">sort of makes it a function assuming you didn&#8217;t ruin any of the other data.</p>



<p class="wp-block-paragraph">So those are the three sections that we can start off looking at the data section,</p>



<p class="wp-block-paragraph">the BSS section, and the tech section. It&#8217;s important to note that besides marking functions</p>



<p class="wp-block-paragraph">as global so that they&#8217;re accessible to other segments or other modules, we also mark</p>



<p class="wp-block-paragraph">We also mark functions and labels that we would like to access that are in other modules.</p>



<p class="wp-block-paragraph">So if we&#8217;re using the GCC libraries, we could say something like global printf,</p>



<p class="wp-block-paragraph">and then right away we&#8217;re able to call the printf function.</p>



<p class="wp-block-paragraph">Or say if you have another function in another module,</p>



<p class="wp-block-paragraph">like a different source code file that&#8217;s compiled somewhere else,</p>



<p class="wp-block-paragraph">we could say, you know, my other function.</p>



<p class="wp-block-paragraph">Something like that.</p>



<p class="wp-block-paragraph">Just mark it as global.</p>



<p class="wp-block-paragraph">Or sorry, not global.</p>



<p class="wp-block-paragraph">Extern.</p>



<p class="wp-block-paragraph">Xtern. Global is when you have the function in the current module and you want it to be available to other modules.</p>



<p class="wp-block-paragraph">Xtern is when the function or label is in another module and it&#8217;s already been made available to you,</p>



<p class="wp-block-paragraph">but you want your current module to know that it can access it for the purposes of assembling the program.</p>



<p class="wp-block-paragraph">So that means inside of here we could do something like call.</p>



<p class="wp-block-paragraph">We could say, let&#8217;s call my other function.</p>



<p class="wp-block-paragraph">my other function that will work if the other function is actually a function</p>



<p class="wp-block-paragraph">with a return statement and it respects the ABI you know it pushes registers that</p>



<p class="wp-block-paragraph">it&#8217;s going to modify if they&#8217;re callie saved if it&#8217;s not another function maybe</p>



<p class="wp-block-paragraph">we&#8217;ll say extern my other jump point so like not a proper function but just</p>



<p class="wp-block-paragraph">something that you might want to jump to then instead of using call we would use</p>



<p class="wp-block-paragraph">jump, you know, and so forth. So those are the basic sections. Let&#8217;s see, for the BSS,</p>



<p class="wp-block-paragraph">I definitely talked about token size and count. And then there&#8217;s resource B, resource W, resource</p>



<p class="wp-block-paragraph">D, resource Q for the different sizes. So basically just take all the different sizes you could put</p>



<p class="wp-block-paragraph">in the regular data section and assume that that could be popped on to the end of RES inside of</p>



<p class="wp-block-paragraph">the BSS section. If you&#8217;re interested, this is a segments video, not an assembly video.</p>



<p class="wp-block-paragraph">assembly video um another segment uh another segment that we&#8217;re not showing here in this</p>



<p class="wp-block-paragraph">source code is the actual stack probably i guess the best way that i could show it is</p>



<p class="wp-block-paragraph">i don&#8217;t know by messing around with the stack pointer increase uh</p>



<p class="wp-block-paragraph">oh rsp why did i think it was the instruction pointer we could increase the stack pointer and</p>



<p class="wp-block-paragraph">stack pointer and then decrease the stack pointer.</p>



<p class="wp-block-paragraph">It doesn&#8217;t really help a whole lot.</p>



<p class="wp-block-paragraph">But in another video, I&#8217;m gonna talk more in depth</p>



<p class="wp-block-paragraph">about what the stack is and how to use it and such.</p>



<p class="wp-block-paragraph">But just keep in mind that the stack</p>



<p class="wp-block-paragraph">is where local variables are stored</p>



<p class="wp-block-paragraph">and you can use it in assembly and C++</p>



<p class="wp-block-paragraph">and other higher level languages.</p>



<p class="wp-block-paragraph">You can even make virtual stacks</p>



<p class="wp-block-paragraph">in any type of program almost</p>



<p class="wp-block-paragraph">to just sort of have a stack like structure.</p>



<p class="wp-block-paragraph">But in C++, if you make any local variable,</p>



<p class="wp-block-paragraph">any local variable, then it&#8217;s usually going on the stack.</p>



<p class="wp-block-paragraph">And the stack tends to have a fixed size.</p>



<p class="wp-block-paragraph">And so if you sort of put too much data on the stack,</p>



<p class="wp-block-paragraph">you risk a stack overflow, which will crash your program.</p>



<p class="wp-block-paragraph">Besides local variables, the stack will hold other information that the current scope needs,</p>



<p class="wp-block-paragraph">like its return address.</p>



<p class="wp-block-paragraph">So when we make a function and then let&#8217;s say we call another function inside of it,</p>



<p class="wp-block-paragraph">actually just up here even when we call another function on line 22 the stack will receive the</p>



<p class="wp-block-paragraph">return address of where we currently are so that later when we return from the other function you</p>



<p class="wp-block-paragraph">know the program knows where to jump back and forth it&#8217;s actually under the hood just jump</p>



<p class="wp-block-paragraph">instructions when you do call it&#8217;s it&#8217;s not it&#8217;s not like a special thing it&#8217;s just jumping to</p>



<p class="wp-block-paragraph">another location and then pushing the return address on the call stack so that&#8217;s other stuff</p>



<p class="wp-block-paragraph">other stuff that the stack holds, which means if you have like an endless or like a infinite</p>



<p class="wp-block-paragraph">recursion happening in your function where just a function calls itself over and over</p>



<p class="wp-block-paragraph">and over again, or you have some complicated call graph and you end up calling too many</p>



<p class="wp-block-paragraph">functions without ever returning, you could overflow the stack.</p>



<p class="wp-block-paragraph">So that&#8217;s not good.</p>



<p class="wp-block-paragraph">Let me show you a quick example that I&#8217;m going to make for you real fast.</p>



<p class="wp-block-paragraph">Oh shoot.</p>



<p class="wp-block-paragraph">Did I actually make this?</p>



<p class="wp-block-paragraph">Where is the, it&#8217;s on the desktop.</p>



<p class="wp-block-paragraph">Okay, I guess I&#8217;m going to make more on the desktop.</p>



<p class="wp-block-paragraph">Let&#8217;s do a stack overflow.</p>



<p class="wp-block-paragraph">Let me do desktop here.</p>



<p class="wp-block-paragraph">Let&#8217;s do stack overflow.</p>



<p class="wp-block-paragraph">That&#8217;s CBP.</p>



<p class="wp-block-paragraph">I&#8217;m just going to make a quick program.</p>



<p class="wp-block-paragraph">In C++, that doesn&#8217;t really do anything except overflow the stack.</p>



<p class="wp-block-paragraph">So I just want you to know the stack can overflow.</p>



<p class="wp-block-paragraph">I&#8217;ll make a function called F.</p>



<p class="wp-block-paragraph">And F just calls itself.</p>



<p class="wp-block-paragraph">calls itself. So that&#8217;s going to be an infinite recursion.</p>



<p class="wp-block-paragraph">And that means, you know, every single time F calls itself,</p>



<p class="wp-block-paragraph">the return address of like line five is going to get pushed onto the stack again.</p>



<p class="wp-block-paragraph">So it&#8217;s just going to get pushed and pushed and pushed and pushed.</p>



<p class="wp-block-paragraph">The stack will overflow faster if I had local variables because every scope that</p>



<p class="wp-block-paragraph">gets called, even if it&#8217;s the same function name, it&#8217;ll have its own allocation on</p>



<p class="wp-block-paragraph">the stack. So if I just sort of like call this from main and then I&#8217;ll just need</p>



<p class="wp-block-paragraph">and then I&#8217;ll just need to make a little uh a little make file that just kind of compiles</p>



<p class="wp-block-paragraph">I don&#8217;t really even need to make a make file I could do a build script but I&#8217;m going to do it</p>



<p class="wp-block-paragraph">anyway we&#8217;ll say g plus plus standard equals c plus plus 23 show all warnings show pedantic</p>



<p class="wp-block-paragraph">the input file will be stack overflow cpp and then the output file will be main</p>



<p class="wp-block-paragraph">main and then assuming that succeeds I&#8217;ll just run main so this is like not a make</p>



<p class="wp-block-paragraph">file video I have other videos for make files let&#8217;s see let me get to the</p>



<p class="wp-block-paragraph">desktop if I run the make file with just the word make you should see a stack</p>



<p class="wp-block-paragraph">overflow we should also see a warning about the fact that there&#8217;s infinite</p>



<p class="wp-block-paragraph">That&#8217;s funny, I must have done something wrong or different because on a different computer</p>



<p class="wp-block-paragraph">not too long ago I did the same thing and I saw a warning.</p>



<p class="wp-block-paragraph">Okay, well thanks for not warning me.</p>



<p class="wp-block-paragraph">But anyway, you can see that we have a segmentation fault here because the stack overflowed.</p>



<p class="wp-block-paragraph">We just made a stack that was too huge.</p>



<p class="wp-block-paragraph">This is a reminder that the stack is not necessarily as dynamic as the heap.</p>



<p class="wp-block-paragraph">You can definitely overflow it.</p>



<p class="wp-block-paragraph">It&#8217;s not really meant to store gigantic amounts of data.</p>



<p class="wp-block-paragraph">What am I talking about when I say the heap though?</p>



<p class="wp-block-paragraph">So just keep in mind that whenever you allocate dynamic data,</p>



<p class="wp-block-paragraph">well, maybe, well, what do you think?</p>



<p class="wp-block-paragraph">Maybe, maybe inside of, instead of calling F, let&#8217;s call G.</p>



<p class="wp-block-paragraph">The heap is where you allocate dynamic data.</p>



<p class="wp-block-paragraph">So anytime you use the malloc operator in C or the new allocator in C++,</p>



<p class="wp-block-paragraph">you&#8217;re creating like a dynamic allocation of data.</p>



<p class="wp-block-paragraph">I&#8217;ll do a new integer and then I&#8217;ll do like a thousand integers so this is</p>



<p class="wp-block-paragraph">basically going to allocate a thousand new integers in the heap which is a</p>



<p class="wp-block-paragraph">segment that is right up against the stack I should mention also that the</p>



<p class="wp-block-paragraph">stack it&#8217;s important the stack its memory locations go down as the stack</p>



<p class="wp-block-paragraph">grows keep that in mind because typically when you when you imagine a</p>



<p class="wp-block-paragraph">stack I&#8217;ll make more videos in the future so you can visualize the stack better but most of you who</p>



<p class="wp-block-paragraph">know what a stack is already you imagine that the stack grows upward visually right but in your</p>



<p class="wp-block-paragraph">computer the memory locations of the stack grow downward so if I add something to the stack then</p>



<p class="wp-block-paragraph">the new stack head pointer is actually going to be a lesser address and the reason for that is the</p>



<p class="wp-block-paragraph">stack and the heap they grow in the same direction towards the same unallocated space we&#8217;ll call that</p>



<p class="wp-block-paragraph">We&#8217;ll call that space the unallocated memory space or the unmapped memory space.</p>



<p class="wp-block-paragraph">And it&#8217;s just, you know, a segment stack in the heap.</p>



<p class="wp-block-paragraph">And then there&#8217;s the unallocated space that they grow towards each other.</p>



<p class="wp-block-paragraph">If they ever meet, then your program is out of memory and it&#8217;ll crash.</p>



<p class="wp-block-paragraph">But the heap actually can be dynamically allocated to store tons of RAM.</p>



<p class="wp-block-paragraph">I&#8217;m probably about to crash this computer.</p>



<p class="wp-block-paragraph">So maybe this video won&#8217;t finish recording.</p>



<p class="wp-block-paragraph">recording so maybe I&#8217;ll try to crash this at the very end I just wanted you to</p>



<p class="wp-block-paragraph">see let me let me do this I&#8217;ll say while true we&#8217;ll just allocate a new integer</p>



<p class="wp-block-paragraph">this is kind of bad form because when you allocate you know a new variable</p>



<p class="wp-block-paragraph">somewhere you want to have access to it after the allocation you would usually</p>



<p class="wp-block-paragraph">send that into a pointer you&#8217;d say like you know integer pointer P equals new</p>



<p class="wp-block-paragraph">in something like that right but in this case I don&#8217;t really care I&#8217;m not gonna</p>



<p class="wp-block-paragraph">that memory i just want you to see how fast the memory can grow when we did the stack overflow</p>



<p class="wp-block-paragraph">seemed like the program died pretty quickly but here we&#8217;re going to be able to see the memory</p>



<p class="wp-block-paragraph">boom pretty pretty big before the whole computer just starts to you know fall to its knees</p>



<p class="wp-block-paragraph">so i&#8217;m going to do a call to g here and then i won&#8217;t actually run this until</p>



<p class="wp-block-paragraph">i&#8217;m ready to crash this whole video let&#8217;s see what else can i say</p>



<p class="wp-block-paragraph">Oh, the reason that the heap can grow so much larger than the stack is our programs now in the modern era, they use virtual memory.</p>



<p class="wp-block-paragraph">So it&#8217;s not like when we allocate, let&#8217;s say we&#8217;re accessing a memory location via a pointer inside of our program.</p>



<p class="wp-block-paragraph">It&#8217;s not that the pointer has the absolute memory location through the whole system.</p>



<p class="wp-block-paragraph">Like it doesn&#8217;t, it&#8217;s not able to name locations outside of the current program.</p>



<p class="wp-block-paragraph">Every program sees its own start memory location as just zero.</p>



<p class="wp-block-paragraph">And then under the hood, there are some extra tricks so that when you try to access a memory location,</p>



<p class="wp-block-paragraph">let&#8217;s say memory location 100, because you&#8217;ve made, I don&#8217;t know, this many integers or whatever.</p>



<p class="wp-block-paragraph">Then under the hood, the computer will know what is the start offset of the program&#8217;s memory.</p>



<p class="wp-block-paragraph">So maybe the start offset is 1000.</p>



<p class="wp-block-paragraph">It&#8217;s like totally unrealistic, but just pretend.</p>



<p class="wp-block-paragraph">The start offset is 1000.</p>



<p class="wp-block-paragraph">1000 then that means if it&#8217;s trying to access a pointer with memory location 100 it just gets added to the offset the virtual offset</p>



<p class="wp-block-paragraph">So it&#8217;ll be a thousand and 100 is the real you know physical memory location or at least at that point</p>



<p class="wp-block-paragraph">It&#8217;ll probably go to the paging system, but that&#8217;s that&#8217;s another video</p>



<p class="wp-block-paragraph">So just know that it&#8217;s virtual which means the program thinks it has the full range of of the 64 bit memory address space</p>



<p class="wp-block-paragraph">Even if you don&#8217;t even have that much memory on your computer, which there&#8217;s no way there&#8217;s no way you have so much memory</p>



<p class="wp-block-paragraph">there&#8217;s no way you have so much memory that it&#8217;s going to overflow or even meet</p>



<p class="wp-block-paragraph">64 bits at all but the program thinks it can so it&#8217;s just going to grow and grow</p>



<p class="wp-block-paragraph">and grow until you actually run out of physical memory and then eventually</p>



<p class="wp-block-paragraph">probably your program is going to start going to the page file or to the swap</p>



<p class="wp-block-paragraph">file and then when you run out of that then your whole computer probably is</p>



<p class="wp-block-paragraph">going to start crashing to be honest it&#8217;ll probably start crashing as soon as</p>



<p class="wp-block-paragraph">it hits the swap file because at that point none of the other programs really</p>



<p class="wp-block-paragraph">None of the other programs really have enough leftover memory to to breathe to do extra</p>



<p class="wp-block-paragraph">allocations and things so everything&#8217;s going to start slowing down it&#8217;s going to be pretty bad</p>



<p class="wp-block-paragraph">and well i think that&#8217;s all i really need to say this is not supposed to be a really long video</p>



<p class="wp-block-paragraph">let me uh let me show you this crasher i&#8217;m going to say goodbye now thank you so much for watching</p>



<p class="wp-block-paragraph">the video i hope you learned a little bit and had some fun too and and that way i&#8217;ve already said</p>



<p class="wp-block-paragraph">if it actually crashes the computer. So I&#8217;m going to open up this and then I&#8217;m going to do maybe</p>



<p class="wp-block-paragraph">HTOP so that I can see memory. So if you kind of like look at HTOP real fast,</p>



<p class="wp-block-paragraph">this is just a Linux command line tool that you can install. It&#8217;s pretty cool.</p>



<p class="wp-block-paragraph">What the heck&#8217;s going on here? Oh, that&#8217;s my recorder. You can see here&#8217;s the memory allocation.</p>



<p class="wp-block-paragraph">So I&#8217;m using two gigs of eight gigs on this virtual machine and then I&#8217;m not using any swap</p>



<p class="wp-block-paragraph">space which means I have not exhausted all my memory and and I have not been forced to go to</p>



<p class="wp-block-paragraph">the disk for like additional memory but in a second we&#8217;ll see that will probably change</p>



<p class="wp-block-paragraph">so I&#8217;m going to do make just to run that it looks like it&#8217;s stuck but if you keep looking at the</p>



<p class="wp-block-paragraph">memory allocation oh it already hit eight gigs now it&#8217;s into the swap already probably</p>



<p class="wp-block-paragraph">The out of memory killer, the OOM, successfully killed the program.</p>



<p class="wp-block-paragraph">Thank goodness.</p>



<p class="wp-block-paragraph">Or the whole computer would have been down.</p>



<p class="wp-block-paragraph">I always forget that that&#8217;s going to happen lately.</p>



<p class="wp-block-paragraph">But you can see it spiked, right?</p>



<p class="wp-block-paragraph">It went right up to the full physical memory allocation of 7.75 gigs.</p>



<p class="wp-block-paragraph">And then the swap file went all the way up to 2 gigs.</p>



<p class="wp-block-paragraph">You can see that the swap file still has about 700 megs inside of it.</p>



<p class="wp-block-paragraph">That just means that there&#8217;s memory that isn&#8217;t really being accessed.</p>



<p class="wp-block-paragraph">the operating system doesn&#8217;t feel like it&#8217;s necessary to pull it back out of swap and put</p>



<p class="wp-block-paragraph">it into RAM but I wonder if the video skipped when I did that or stuttered or anything I&#8217;m</p>



<p class="wp-block-paragraph">interested to find out now okay so that&#8217;s the end of this video I hope you have a decent basic</p>



<p class="wp-block-paragraph">understanding of segments and then you know like the segments and their purpose you know the heap</p>



<p class="wp-block-paragraph">and the stack they grow together the heap can dynamically allocate to grow bigger notice how it</p>



<p class="wp-block-paragraph">Whereas the stack will crash a lot faster.</p>



<p class="wp-block-paragraph">If the stack and the heap meet, then you&#8217;ve ran out of memory.</p>



<p class="wp-block-paragraph">At that point, you know, you probably want to like resize the heap or the stack just crashes.</p>



<p class="wp-block-paragraph">And then we got the text section of the program and the data section and the BSS section of the program.</p>



<p class="wp-block-paragraph">And these sections are a little bit less relevant in the modern era because we have, you know, virtual memory and stuff.</p>



<p class="wp-block-paragraph">That definitely means you have tried to access outside of your segment and it&#8217;s a no go.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">Thank you for watching this video.</p>



<p class="wp-block-paragraph">I will see you at a later date and time.</p>



<p class="wp-block-paragraph">Hey everybody.</p>



<p class="wp-block-paragraph">Thanks for watching this video again from the bottom of my heart.</p>



<p class="wp-block-paragraph">I really appreciate it.</p>



<p class="wp-block-paragraph">I do hope you did learn something and have some fun.</p>



<p class="wp-block-paragraph">If you could do me a please, a small little favor, could you please subscribe and follow</p>



<p class="wp-block-paragraph">as you do on the current social media website</p>



<p class="wp-block-paragraph">that you&#8217;re looking at right now,</p>



<p class="wp-block-paragraph">it would really mean the world to me</p>



<p class="wp-block-paragraph">and it&#8217;ll help make more videos</p>



<p class="wp-block-paragraph">and grow this community.</p>



<p class="wp-block-paragraph">So we&#8217;ll be able to do more videos,</p>



<p class="wp-block-paragraph">longer videos, better videos,</p>



<p class="wp-block-paragraph">or just I&#8217;ll be able to keep making videos in general.</p>



<p class="wp-block-paragraph">So please do me a kindness and subscribe.</p>



<p class="wp-block-paragraph">You know, sometimes I&#8217;m sleeping</p>



<p class="wp-block-paragraph">in the middle of the night</p>



<p class="wp-block-paragraph">and I just wake up</p>



<p class="wp-block-paragraph">because I know somebody subscribed or followed.</p>



<p class="wp-block-paragraph">It just wakes me up and I get filled with joy.</p>



<p class="wp-block-paragraph">That&#8217;s exactly what happens every single time.</p>



<p class="wp-block-paragraph">So you could do it as a nice favor to me or you could you could troll me if you want to just wake me up in the middle</p>



<p class="wp-block-paragraph">And I just subscribe and then I&#8217;ll just wake up. I promise that&#8217;s what will happen</p>



<p class="wp-block-paragraph">Also, if you look at the middle of the screen right now, you should see a QR code which you can scan</p>



<p class="wp-block-paragraph">in order to go to the website which I think is also named somewhere at the bottom of this video</p>



<p class="wp-block-paragraph">and it&#8217;ll take you to my main website where you can just kind of like see</p>



<p class="wp-block-paragraph">all the videos I published and the services and tutorials and things that I offer</p>



<p class="wp-block-paragraph">and all that good stuff and</p>



<p class="wp-block-paragraph">and uh if you have a suggestion for uh uh clarifications or errata or just future videos</p>



<p class="wp-block-paragraph">that you want to see please leave a comment or if you just want to say hey what&#8217;s up what&#8217;s going on</p>



<p class="wp-block-paragraph">you know just send me a comment whatever i also wake up for those in the middle of the night i</p>



<p class="wp-block-paragraph">get i wake up in a cold sweat and i&#8217;m like it would really it really mean the world to me i</p>



<p class="wp-block-paragraph">would really appreciate it so again thank you so much for watching this video and um enjoy the cool</p>



<p class="wp-block-paragraph">Enjoy the cool music as I fade into the darkness which is coming for us all.</p>



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/demystifying-x86-64-program-segments-stack-heap-and-more/">Demystifying x86-64 Program Segments: Stack, Heap, and More</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/demystifying-x86-64-program-segments-stack-heap-and-more/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Master GNU Debugger: Debug C++ &#038; Assembly Programs with GDB Like a Pro</title>
		<link>https://www.NeuralLantern.com/master-gnu-debugger-debug-c-assembly-programs-with-gdb-like-a-pro/</link>
					<comments>https://www.NeuralLantern.com/master-gnu-debugger-debug-c-assembly-programs-with-gdb-like-a-pro/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sat, 14 Jun 2025 23:53:13 +0000</pubDate>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[assembly debugging]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[breakpoints]]></category>
		<category><![CDATA[c++ debugging]]></category>
		<category><![CDATA[C++ programming]]></category>
		<category><![CDATA[call stack]]></category>
		<category><![CDATA[coding for beginners]]></category>
		<category><![CDATA[coding tutorial]]></category>
		<category><![CDATA[debug symbols]]></category>
		<category><![CDATA[debugging tools]]></category>
		<category><![CDATA[GDB]]></category>
		<category><![CDATA[GNU Debugger]]></category>
		<category><![CDATA[null pointer]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software development]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=155</guid>

					<description><![CDATA[<p>Master GDB to debug C++ &#038; assembly! Learn breakpoints, call stacks, &#038; crash fixes in this fun guide for coders.</p>
<p>The post <a href="https://www.NeuralLantern.com/master-gnu-debugger-debug-c-assembly-programs-with-gdb-like-a-pro/">Master GNU Debugger: Debug C++ &amp; Assembly Programs with GDB Like a Pro</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="Master GNU Debugger: Debug C++ &amp; Assembly Programs with GDB Like a Pro" width="1380" height="776" src="https://www.youtube.com/embed/lPcwsvSWak0?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">Hey everybody! Ready to crush those pesky bugs in your C++ and assembly programs? In this video, we’re diving deep into the GNU Debugger (GDB) – the ultimate tool for tracking down crashes, inspecting variables, and mastering your code. From setting up debug symbols to navigating call stacks, setting breakpoints, and even debugging assembly registers, this fun and relatable guide has you covered. Whether you’re a beginner coder or a seasoned dev, you’ll learn practical tips to level up your debugging game. We’ll also tackle null pointers, create GDB scripts, and explore why your program might be misbehaving. Stick around for a few laughs and some serious skills! Don’t forget to subscribe, hit that like button, and check out my website for more coding tutorials. Let’s debug like pros together!</p>



<p class="wp-block-paragraph">Introduction to GNU Debugger 00:00:00<br>What is a Debugger 00:00:20<br>Debug Symbols Explanation 00:02:08<br>Compiling with Debug Symbols 00:03:13<br>File Size Comparison 00:05:30<br>Installing and Launching GDB 00:06:21<br>GDB Console Basics 00:06:55<br>Attaching GDB to Program 00:08:12<br>Running Program in GDB 00:09:09<br>Handling Program Crash 00:13:02<br>Understanding Call Stack 00:14:05<br>Navigating Call Stack 00:18:13<br>Inspecting Variables 00:19:08<br>Null Pointer Issues 00:21:25<br>Using GDB Script 00:25:10<br>Setting Breakpoints 00:27:04<br>Managing Breakpoints 00:28:37<br>Continuing Execution 00:30:41<br>Debugging Assembly 00:33:24<br>Global Variables in Assembly 00:35:43<br>Advanced GDB Commands 00:38:31<br>Conclusion and Call to Action 00:40:22</p>



<p class="wp-block-paragraph">Thanks for watching!</p>



<p class="wp-block-paragraph">Find us on other social media here:</p>



<ul class="wp-block-list">
<li>https://www.NeuralLantern.com/social</li>
</ul>



<p class="wp-block-paragraph">Please help support us!</p>



<ul class="wp-block-list">
<li>Subscribing + Sharing on Social Media</li>



<li>Leaving a comment or suggestion</li>



<li>Subscribing to our Blog</li>



<li>Watching the main &#8220;pinned&#8221; video of this channel for offers and extras</li>
</ul>



<p class="wp-block-paragraph">Hey everybody! In this video I&#8217;m going to show you how to use the GNU Debugger to</p>



<p class="wp-block-paragraph">debug your C++ and assembly programs.</p>



<p class="wp-block-paragraph">You can also use it for C and some other stuff but we&#8217;re just going to focus on</p>



<p class="wp-block-paragraph">C++ and assembly. What is the GNU Debugger and what is a debugger in the</p>



<p class="wp-block-paragraph">first place? So for starters the GNU Debugger it&#8217;s like it&#8217;s called GDB and</p>



<p class="wp-block-paragraph">the db you can imagine that stands for debugger something like that and the g stands for gnu i</p>



<p class="wp-block-paragraph">personally don&#8217;t know how to uh pronounce gnu so i just say gnu because it it feels more fun to do</p>



<p class="wp-block-paragraph">it that way it&#8217;s more interesting i think probably some people just say new but i don&#8217;t like that</p>



<p class="wp-block-paragraph">because the gdb debugger is really old and robust and powerful it&#8217;s not a new tool it&#8217;s it&#8217;s an old</p>



<p class="wp-block-paragraph">new debugger someone&#8217;s always going to ask what was the old debugger and then I say this is the</p>



<p class="wp-block-paragraph">old debugger the new debugger is the old debugger anyway so we&#8217;re going to use the GNU debugger</p>



<p class="wp-block-paragraph">if you haven&#8217;t yet watched my video on caveman debugging you probably want to watch that first</p>



<p class="wp-block-paragraph">just for like some basics of you know why you might want to look at information in your program</p>



<p class="wp-block-paragraph">but for now we&#8217;ll just assume that you already know what&#8217;s going on with just like why you would</p>



<p class="wp-block-paragraph">know how to make make files see my other videos but here i just have a basic make file all it&#8217;s</p>



<p class="wp-block-paragraph">really going to do is just sort of compile a very simple program and add debug symbols into it so</p>



<p class="wp-block-paragraph">let&#8217;s double check that i&#8217;m actually doing that here yeah there we go okay so the first thing</p>



<p class="wp-block-paragraph">that i should probably show you is uh we are compiling a c plus plus source module so i&#8217;ve</p>



<p class="wp-block-paragraph">actually using c but i i have that left over in there anyway and then we&#8217;re assembling something</p>



<p class="wp-block-paragraph">in yasm we&#8217;re linking with g plus plus because we want to have a hybrid program and we&#8217;ve got</p>



<p class="wp-block-paragraph">all these flags here those are just variables and so uh so now before i can debug with gdb</p>



<p class="wp-block-paragraph">i&#8217;ve got to talk about something called debug symbols what are debug symbols imagine just a</p>



<p class="wp-block-paragraph">bunch of extra information explaining all of the design and variables and everything inside of your</p>



<p class="wp-block-paragraph">about your code stuffed directly into the executable.</p>



<p class="wp-block-paragraph">So imagine, you know, when we compile a C++ source module</p>



<p class="wp-block-paragraph">into an object file, usually that&#8217;s just, you know,</p>



<p class="wp-block-paragraph">assembly at that point.</p>



<p class="wp-block-paragraph">But when we add debug symbols, we&#8217;ll have a bunch of information</p>



<p class="wp-block-paragraph">that can help the debugger figure out where we are in the program,</p>



<p class="wp-block-paragraph">what the variables look like, you know,</p>



<p class="wp-block-paragraph">a bunch of extra information to help the debugger pretty much.</p>



<p class="wp-block-paragraph">The assembler will put debug symbols into the object code</p>



<p class="wp-block-paragraph">symbols into the object code that you generate the compilers will do that the linker will do that</p>



<p class="wp-block-paragraph">and so it&#8217;s important to understand if you don&#8217;t generate debug symbols when you&#8217;re compiling and</p>



<p class="wp-block-paragraph">linking your code then your debugger won&#8217;t actually be able to do anything it won&#8217;t understand what&#8217;s</p>



<p class="wp-block-paragraph">going on you can debug it but like you&#8217;re not going to see anything that&#8217;s very uh that&#8217;s useful</p>



<p class="wp-block-paragraph">so let me show you real fast i&#8217;m going to do make clean and then i&#8217;m going to say make build</p>



<p class="wp-block-paragraph">that I do not have debug symbols.</p>



<p class="wp-block-paragraph">All right, okay, if you don&#8217;t know how to compile and link from the command line, see</p>



<p class="wp-block-paragraph">my other videos, but for now it looks like we&#8217;re not generating debug symbols.</p>



<p class="wp-block-paragraph">So if I list the contents of my directory here, just note the size is real fast.</p>



<p class="wp-block-paragraph">I have an assembly module here that I&#8217;m calling ASI.asm, ASI for assembly, and then we&#8217;re</p>



<p class="wp-block-paragraph">assembling it down to an object file.</p>



<p class="wp-block-paragraph">Notice how it&#8217;s just 656 bytes, very small.</p>



<p class="wp-block-paragraph">plus plus module that I&#8217;m creating here is compiling to an object file that is</p>



<p class="wp-block-paragraph">about four and a half kilobytes so you know not too big the final executable is</p>



<p class="wp-block-paragraph">called main and it&#8217;s about 17 kilobytes so this is without debug symbols when</p>



<p class="wp-block-paragraph">you&#8217;re compiling something on your own you need to add extra switches to enable</p>



<p class="wp-block-paragraph">debug symbols so you can see here in this make file that I&#8217;ve made and again if</p>



<p class="wp-block-paragraph">you don&#8217;t know how to make a make file or compile or link or anything see my</p>



<p class="wp-block-paragraph">But for now, I&#8217;m just going to assume you kind of know your way around to makefile,</p>



<p class="wp-block-paragraph">or at least you can kind of infer what&#8217;s going on.</p>



<p class="wp-block-paragraph">So I&#8217;ve commented out a different version of this variable for the flags of my C++ compiler.</p>



<p class="wp-block-paragraph">If I uncomment this and then comment out the other one,</p>



<p class="wp-block-paragraph">you&#8217;ll notice the only real difference is this part right here, dash G dwarf 2.</p>



<p class="wp-block-paragraph">Usually in C++ compilation, it&#8217;ll just be dash G to generate debug symbols,</p>



<p class="wp-block-paragraph">and then the symbol format will default to a format called dwarf2 so I don&#8217;t know for these</p>



<p class="wp-block-paragraph">tutorials I like to just specify the full format but you can just say dash g in your c++ compiler</p>



<p class="wp-block-paragraph">and linker we do the same thing for the linker down here so I&#8217;m going to uncomment this</p>



<p class="wp-block-paragraph">and comment that and the only difference is just g dwarf2 so I&#8217;m just telling my linker that I also</p>



<p class="wp-block-paragraph">want debug symbols in there too then we do the same thing for the assembler so I&#8217;m going to</p>



<p class="wp-block-paragraph">So I&#8217;m going to uncomment that and comment this other one.</p>



<p class="wp-block-paragraph">And the only difference is that in the assembler,</p>



<p class="wp-block-paragraph">we kind of have to specify it a little bit differently.</p>



<p class="wp-block-paragraph">Instead of G dwarf dash two,</p>



<p class="wp-block-paragraph">it&#8217;s just G dwarf two as just one string.</p>



<p class="wp-block-paragraph">And I think with Yasm, you have to specify the debug symbol format.</p>



<p class="wp-block-paragraph">So just keep that in mind.</p>



<p class="wp-block-paragraph">So now I&#8217;ve turned on all the debug symbols.</p>



<p class="wp-block-paragraph">I&#8217;m going to do real fast, make clean and make build one more time.</p>



<p class="wp-block-paragraph">And then if I list everything,</p>



<p class="wp-block-paragraph">list everything let me just double check that it&#8217;s building the symbols now right okay good</p>



<p class="wp-block-paragraph">notice that the files are bigger so this asio um file is now 1.8 kilobytes instead of you know</p>



<p class="wp-block-paragraph">half a kilobyte the main.o object file is now 36 kilobytes instead of only 4.5 and the executable</p>



<p class="wp-block-paragraph">main is 36 kilobytes instead of just 17. so you can feel it already right like there&#8217;s a bunch</p>



<p class="wp-block-paragraph">extra information sitting inside the object files and the binary which allows us to debug our program</p>



<p class="wp-block-paragraph">okay so now that we&#8217;ve generated debug symbols in our program we can actually think about starting</p>



<p class="wp-block-paragraph">to use gdb so gdb is a program just gdb by the command line if you don&#8217;t have it in your system</p>



<p class="wp-block-paragraph">already you can go sudo apt install gdb or depending on what system you&#8217;re on maybe a or</p>



<p class="wp-block-paragraph">or whatever your package management program is,</p>



<p class="wp-block-paragraph">but we just need to install GDB.</p>



<p class="wp-block-paragraph">On Ubuntu and Debian, I think,</p>



<p class="wp-block-paragraph">there is a meta package called build essential,</p>



<p class="wp-block-paragraph">which will give you a bunch of compilation tools</p>



<p class="wp-block-paragraph">and make file stuff and whatever.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to assume at this point</p>



<p class="wp-block-paragraph">you already have GDB on your system.</p>



<p class="wp-block-paragraph">To launch GDB and go into its console,</p>



<p class="wp-block-paragraph">just type GDB by itself.</p>



<p class="wp-block-paragraph">So now we&#8217;re inside of the GDB console or terminal.</p>



<p class="wp-block-paragraph">console or terminal. We&#8217;re no longer inside of a bash terminal. We can&#8217;t type normal commands.</p>



<p class="wp-block-paragraph">Let me show you real fast. Here&#8217;s the first command you want to learn on GDB. It&#8217;s called</p>



<p class="wp-block-paragraph">quit. Never quit. Never surrender. So, you know, normally if you&#8217;re at the command line,</p>



<p class="wp-block-paragraph">you can do something like cat, etc. OS release just to see what operating system you&#8217;re using.</p>



<p class="wp-block-paragraph">So you can see for this virtual machine that I&#8217;m using right now, I&#8217;ve got like Ubuntu 22 on there.</p>



<p class="wp-block-paragraph">If we go inside of GDB, we can&#8217;t use regular bash commands anymore or regular operating</p>



<p class="wp-block-paragraph">system commands.</p>



<p class="wp-block-paragraph">We can&#8217;t say cat, et cetera, OS release because we can now only use GDB commands.</p>



<p class="wp-block-paragraph">We&#8217;re inside of GDB already.</p>



<p class="wp-block-paragraph">Notice how it says undefined catch command.</p>



<p class="wp-block-paragraph">I don&#8217;t know what you&#8217;re talking about, dude.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">So remember we do a Q or quit to get out.</p>



<p class="wp-block-paragraph">You can actually just type Q.</p>



<p class="wp-block-paragraph">A lot of commands that I&#8217;m going to be talking about.</p>



<p class="wp-block-paragraph">going to be talking about you can abbreviate them with one or two or three letters and it totally</p>



<p class="wp-block-paragraph">works just for speed so now that we know how to enter gdb and now that we also know that we have</p>



<p class="wp-block-paragraph">already compiled our program with debug symbols we can attach gdb to our program i mean what&#8217;s the</p>



<p class="wp-block-paragraph">whole point of a debugger we most of the time we will just have our debugger attached to our program</p>



<p class="wp-block-paragraph">and launch it or i guess launch it while it&#8217;s attached you can also attach to a running program</p>



<p class="wp-block-paragraph">but we&#8217;re going to launch a program and stay attached to it.</p>



<p class="wp-block-paragraph">And then we can sort of catch crashes and see what&#8217;s going on.</p>



<p class="wp-block-paragraph">Or we could also tell the debugger to stop the program at certain points in time,</p>



<p class="wp-block-paragraph">like when we hit a certain line number or when a variable changes or something like that.</p>



<p class="wp-block-paragraph">And then we can look around.</p>



<p class="wp-block-paragraph">We can look at all the variables, look at the state of the program,</p>



<p class="wp-block-paragraph">even change things if we wanted to.</p>



<p class="wp-block-paragraph">We can look at all the registers if you&#8217;re coding in assembly.</p>



<p class="wp-block-paragraph">So it&#8217;s pretty useful.</p>



<p class="wp-block-paragraph">Anyway, I&#8217;m going to go gdb and the next command we&#8217;re going to learn is file, which just tells</p>



<p class="wp-block-paragraph">gdb to attach to a program so that we can run it.</p>



<p class="wp-block-paragraph">So, you know, the name of our program here that we compiled is just called main.</p>



<p class="wp-block-paragraph">And so if I type file main, then gdb should load up that file and try to parse its debug</p>



<p class="wp-block-paragraph">symbols so it can begin debugging for you.</p>



<p class="wp-block-paragraph">Notice how it says reading symbols from main.</p>



<p class="wp-block-paragraph">you know if we did a typo or we had something with no debug symbols it will give us some sort</p>



<p class="wp-block-paragraph">of an error message so for now i&#8217;m just going to quit and then go back in just to make sure that</p>



<p class="wp-block-paragraph">it&#8217;s all clean and we&#8217;re going to do file main now it attaches once it&#8217;s attached that&#8217;s not i guess</p>



<p class="wp-block-paragraph">it&#8217;s not technically attached because the program&#8217;s not running but once it has loaded the debug</p>



<p class="wp-block-paragraph">symbols for that program we can run the program with the run command in gdb also kind of interesting</p>



<p class="wp-block-paragraph">If you have debug symbols that are generated separately from your executable,</p>



<p class="wp-block-paragraph">you could tell GDB to load the symbols file and then run your program.</p>



<p class="wp-block-paragraph">That happens a lot in Linux where people release the non-debug friendly version of a program</p>



<p class="wp-block-paragraph">and then they&#8217;ll release the debug symbols separately if you&#8217;re interested.</p>



<p class="wp-block-paragraph">Anyway, so I&#8217;m going to type run and it&#8217;ll run the program.</p>



<p class="wp-block-paragraph">Notice how GDB kind of tells us that it&#8217;s starting up now.</p>



<p class="wp-block-paragraph">here&#8217;s like a thread debugger that&#8217;s being enabled and it says we&#8217;re using this library to do it and</p>



<p class="wp-block-paragraph">then it says hello you know here&#8217;s the hello message so the program is actually running that&#8217;s</p>



<p class="wp-block-paragraph">not my name i wish it was and then it prints the final result and then gdb says your program exited</p>



<p class="wp-block-paragraph">normally on newer versions of gdb there&#8217;s a setting i think by default where it&#8217;ll ask you</p>



<p class="wp-block-paragraph">if you want to start a debug daemon a debug info daemon or something yes or no you can usually just</p>



<p class="wp-block-paragraph">without actually having to type n.</p>



<p class="wp-block-paragraph">It&#8217;s a little bit faster.</p>



<p class="wp-block-paragraph">So the whole program ran and finished.</p>



<p class="wp-block-paragraph">If I type run again, it does the same thing.</p>



<p class="wp-block-paragraph">In GDB, if you hit enter without typing anything,</p>



<p class="wp-block-paragraph">it ends up repeating the previous command.</p>



<p class="wp-block-paragraph">So I&#8217;m not going to type run.</p>



<p class="wp-block-paragraph">If I just hit enter, are you serious?</p>



<p class="wp-block-paragraph">GDB made me into a liar.</p>



<p class="wp-block-paragraph">Well, most of the commands will repeat if you hit enter.</p>



<p class="wp-block-paragraph">I guess not the run command.</p>



<p class="wp-block-paragraph">So I&#8217;ll type run again.</p>



<p class="wp-block-paragraph">And okay, I mean, the program is pretty good, right?</p>



<p class="wp-block-paragraph">So if you watched my…</p>



<p class="wp-block-paragraph">It&#8217;s not pretty good.</p>



<p class="wp-block-paragraph">watched my it&#8217;s not pretty good it&#8217;s a nonsense program I mean it it doesn&#8217;t crash is what I&#8217;m</p>



<p class="wp-block-paragraph">saying if you watched my previous video which you should on caveman debugging I had this uh you know</p>



<p class="wp-block-paragraph">nonsense portion of code that just sort of updated a variable and we pretended that we were confused</p>



<p class="wp-block-paragraph">and we didn&#8217;t understand what was happening and uh we used gdb to debug it so what I&#8217;m going to do</p>



<p class="wp-block-paragraph">either let&#8217;s say we&#8217;ll start off with throwing an exception and then we&#8217;ll try to use a no pointer</p>



<p class="wp-block-paragraph">and then we&#8217;ll see a crash and then after that I&#8217;m going to start using breakpoints where we can stop</p>



<p class="wp-block-paragraph">automatically inside of our program to print the state of the program print the variables</p>



<p class="wp-block-paragraph">and then I&#8217;m going to do that first in C++ and then hopefully I&#8217;ll remember to do that in</p>



<p class="wp-block-paragraph">assembly right after it&#8217;s basically the same thing only with assembly you don&#8217;t really have</p>



<p class="wp-block-paragraph">you know a bunch of variables everywhere you just kind of have registers and maybe some globals</p>



<p class="wp-block-paragraph">globals but it&#8217;s going to be the same deal okay so let&#8217;s pretend that uh we are gonna have a crash</p>



<p class="wp-block-paragraph">okay so this program just kind of runs later on we&#8217;ll figure out why the result is wrong we&#8217;ll</p>



<p class="wp-block-paragraph">just pretend that it&#8217;s wrong but for now we&#8217;ll just say how about we uncomment this line right</p>



<p class="wp-block-paragraph">here and what will happen is when we&#8217;re running the main loop at some point in the loop we get</p>



<p class="wp-block-paragraph">When F gets called, the input will be looked at here.</p>



<p class="wp-block-paragraph">And if the input is more than one,</p>



<p class="wp-block-paragraph">which is definitely gonna happen like right away,</p>



<p class="wp-block-paragraph">then we&#8217;ll call on the G function.</p>



<p class="wp-block-paragraph">Then the G function will just throw an exception.</p>



<p class="wp-block-paragraph">We&#8217;ll just pretend that something really bad happened.</p>



<p class="wp-block-paragraph">You crashed or you actually did throw</p>



<p class="wp-block-paragraph">and you didn&#8217;t catch your throw,</p>



<p class="wp-block-paragraph">or maybe the system threw something at you</p>



<p class="wp-block-paragraph">or another library threw something at you</p>



<p class="wp-block-paragraph">and you didn&#8217;t catch it.</p>



<p class="wp-block-paragraph">So just basically a program crash.</p>



<p class="wp-block-paragraph">Let me run this real fast.</p>



<p class="wp-block-paragraph">So make run just to show you that the program crashes.</p>



<p class="wp-block-paragraph">Make run at this point is the same thing as just kind of executing the program.</p>



<p class="wp-block-paragraph">But you can see that it says terminate called after throwing an instance of runtime error.</p>



<p class="wp-block-paragraph">And then there&#8217;s the message, oh my gosh, and then aborted core dumped.</p>



<p class="wp-block-paragraph">That&#8217;s not good.</p>



<p class="wp-block-paragraph">So now let&#8217;s try to understand why.</p>



<p class="wp-block-paragraph">Why did that crash?</p>



<p class="wp-block-paragraph">Pretend you don&#8217;t know that it happened in G. You know, you&#8217;re trying to investigate.</p>



<p class="wp-block-paragraph">So we could type GDB and then we could type a file to load the debug symbols, but it&#8217;s a little bit faster just to type GDB main and just sort of name the file that you want to load right away.</p>



<p class="wp-block-paragraph">So if I do that, notice how it automatically tries to load the debug symbols from main.</p>



<p class="wp-block-paragraph">Then I can just type run and then the program tries to run and notice how it actually catches the crash.</p>



<p class="wp-block-paragraph">If you look down here, terminate called after throwing an instance of runtime error.</p>



<p class="wp-block-paragraph">throwing an instance of runtime error so that&#8217;s what the program thinks is going on but then the</p>



<p class="wp-block-paragraph">program is trying to terminate but then down here gdb is like wait wait wait i just caught you know</p>



<p class="wp-block-paragraph">a termination uh getting invoked here and you can see this is sort of system code like we did not</p>



<p class="wp-block-paragraph">create this source file p thread kill we didn&#8217;t write that that&#8217;s the standard library and there&#8217;s</p>



<p class="wp-block-paragraph">a function here called p thread kill implementation with those you know fun c underscore prefixes</p>



<p class="wp-block-paragraph">prefixes everywhere and so this is like some sort of a c source file and we don&#8217;t have that file on</p>



<p class="wp-block-paragraph">the system so we can&#8217;t really debug that file lucky for you most of these standard libraries</p>



<p class="wp-block-paragraph">work all the time so you don&#8217;t really need to debug them you need to debug your code instead</p>



<p class="wp-block-paragraph">of the standard library code so the question really is how did i get here how did i get to</p>



<p class="wp-block-paragraph">this crash so the next command we&#8217;ll learn in gdb is just the where command the where command will</p>



<p class="wp-block-paragraph">I&#8217;m going to release a video in the future that kind of explains call stacks, but basically</p>



<p class="wp-block-paragraph">imagine a abstract data type, a data structure called a stack. And every time you want to add</p>



<p class="wp-block-paragraph">data to the stack, it just sort of stacks up on top of the last piece of data. So like if I add</p>



<p class="wp-block-paragraph">something, let&#8217;s say I want to add the number five, then I would just add the number five on top of</p>



<p class="wp-block-paragraph">the stack, right? If I wanted to add the number 11, then I would just add the number 11 onto the</p>



<p class="wp-block-paragraph">off of the stack and the stack is a really good data structure to uh sort of give you a trail of</p>



<p class="wp-block-paragraph">breadcrumbs to know where you got where did you come from so we call this the call stack because</p>



<p class="wp-block-paragraph">what&#8217;s happening is every single time you call a function then the new scope and then you know the</p>



<p class="wp-block-paragraph">new function that you&#8217;re invoking um it has something called a call frame full of information</p>



<p class="wp-block-paragraph">current address is and all that stuff.</p>



<p class="wp-block-paragraph">And we&#8217;ll just call that chunk of data that belongs to one instance of a function call.</p>



<p class="wp-block-paragraph">We&#8217;ll just call that a call frame.</p>



<p class="wp-block-paragraph">And so if you&#8217;re stacking call frames one on top of the other,</p>



<p class="wp-block-paragraph">then we call that whole entire thing the call stack.</p>



<p class="wp-block-paragraph">And this is what allows us to use recursion and all these complicated call graphs and everything.</p>



<p class="wp-block-paragraph">It&#8217;s really simple, but it&#8217;s really powerful.</p>



<p class="wp-block-paragraph">So you&#8217;re looking at the call stack.</p>



<p class="wp-block-paragraph">Each one of these lines is the call frame or is a call frame.</p>



<p class="wp-block-paragraph">And so for example, if you just look at number zero here, you&#8217;re looking at call frame zero,</p>



<p class="wp-block-paragraph">which is the closest frame to wherever the crash occurred, which is if you look at it,</p>



<p class="wp-block-paragraph">that&#8217;s exactly what we were looking at when we saw that original message, right? Call frame zero.</p>



<p class="wp-block-paragraph">So that&#8217;s not really useful. You want to go down to higher numbered call frames or I guess</p>



<p class="wp-block-paragraph">physically lowered number call frames and just kind of scan it until you find some code that</p>



<p class="wp-block-paragraph">raise no abort no none of this stuff is ours live standard c plus plus no the first frame that</p>



<p class="wp-block-paragraph">contains code that is ours is call frame number nine or i guess like nine away from our current</p>



<p class="wp-block-paragraph">position so i guess find the physically highest call frame that is your code or the lowest numbered</p>



<p class="wp-block-paragraph">call frame that is your code and it&#8217;s telling us right here all right we uh we actually seem to</p>



<p class="wp-block-paragraph">So if I go to 65, right there, it tells you exactly where the crash happened.</p>



<p class="wp-block-paragraph">If you&#8217;re still trying to figure out, well, how did I get to that crash?</p>



<p class="wp-block-paragraph">I don&#8217;t know how that actually happened.</p>



<p class="wp-block-paragraph">Just keep looking down further in the call frames.</p>



<p class="wp-block-paragraph">The next one, call frame 10, says, well, we were inside of function f with input equals</p>



<p class="wp-block-paragraph">three at main.cpb line 46.</p>



<p class="wp-block-paragraph">So if I just go to 46, I can get another clue.</p>



<p class="wp-block-paragraph">I can go, all right, so for some reason we called g.</p>



<p class="wp-block-paragraph">Imagine again, this program is much more complicated.</p>



<p class="wp-block-paragraph">And then if we&#8217;re still confused, we just look down at another one and it&#8217;s like, well, this all this whole mess started at CPP main dot CPP line 28.</p>



<p class="wp-block-paragraph">So if we look at line 28, it&#8217;s like, well, we were inside of this loop and we we called the F function and then the F function called the G function.</p>



<p class="wp-block-paragraph">And then G just kind of did a throw. So that gives us a lot of information.</p>



<p class="wp-block-paragraph">All right. Next thing we can do is we can sort of move up and down the call stack, because right now we&#8217;re sitting at call frame zero, which is just the system code.</p>



<p class="wp-block-paragraph">which is just the system code, but maybe we don&#8217;t understand why the throw actually happened at,</p>



<p class="wp-block-paragraph">let&#8217;s say, line 65, right? So we can use up to go up in the call stack to a different call frame.</p>



<p class="wp-block-paragraph">So if I hit up, notice how it mentions that we&#8217;re now in frame number one instead of zero.</p>



<p class="wp-block-paragraph">And if I do up again, we&#8217;re now in frame two, which is a little bit closer. We can use the</p>



<p class="wp-block-paragraph">trick finally where we hit the enter key instead of repeating the command. So I&#8217;m just going to</p>



<p class="wp-block-paragraph">and hit enter a couple times until we eventually get to our code,</p>



<p class="wp-block-paragraph">which I think was supposed to be at frame nine.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to hit it a bunch of times until we get to frame nine.</p>



<p class="wp-block-paragraph">Now we&#8217;re looking sort of back in time at that point</p>



<p class="wp-block-paragraph">because all these other frames actually did get invoked,</p>



<p class="wp-block-paragraph">but we don&#8217;t really care about what was going on inside of them</p>



<p class="wp-block-paragraph">because they probably did their job correctly.</p>



<p class="wp-block-paragraph">We&#8217;re looking at our code, so we&#8217;re going back in time</p>



<p class="wp-block-paragraph">right when we were doing this throw.</p>



<p class="wp-block-paragraph">Oh no, we threw. Why did we throw?</p>



<p class="wp-block-paragraph">well there&#8217;s another command in gdb called info locals</p>



<p class="wp-block-paragraph">okay the info locals uh there&#8217;s there&#8217;s really not much to this maybe maybe let me do this again</p>



<p class="wp-block-paragraph">a equals five and uh then i&#8217;ll just say a plus plus just so that we have a local variable</p>



<p class="wp-block-paragraph">i forgot that gdb doesn&#8217;t consider the incoming arguments as locals so there was nothing there</p>



<p class="wp-block-paragraph">real fast uh gdp oh let&#8217;s do make build and then gdp main and then run and then we have a throw</p>



<p class="wp-block-paragraph">and then i say where and then i go up up up up to a frame you can also use the keyword down if you</p>



<p class="wp-block-paragraph">go too far if you want to go you know back down in the call stack but i&#8217;m just going to use up</p>



<p class="wp-block-paragraph">okay so now we have it here now finally i think i can do info locals just to see the local variables</p>



<p class="wp-block-paragraph">notice how the a variable is there now because I just added a local variable a a moment ago</p>



<p class="wp-block-paragraph">you can also print things directly you can say print the input incoming variable if you&#8217;re in</p>



<p class="wp-block-paragraph">assembly you can also print registers you can say info registers like that and you&#8217;ll get a nice</p>



<p class="wp-block-paragraph">print out of all the registers you could print individual registers you can say let&#8217;s print</p>



<p class="wp-block-paragraph">register r12 you can print register r12 as binary by saying I think it&#8217;s p slash t</p>



<p class="wp-block-paragraph">or print slash t yeah we can probably just do print slash t also</p>



<p class="wp-block-paragraph">t stands for two because they&#8217;re it&#8217;s a base two number system</p>



<p class="wp-block-paragraph">does that mean there&#8217;s a p slash h or a p slash f for 15 or 16 s for 16 i don&#8217;t know i haven&#8217;t</p>



<p class="wp-block-paragraph">tried that is it going to work hang on p slash s bar 12 it&#8217;s not going to work nope didn&#8217;t work</p>



<p class="wp-block-paragraph">i think it thinks it&#8217;s a character point or something but anyway so we can print a lot of</p>



<p class="wp-block-paragraph">So we can print a lot of stuff.</p>



<p class="wp-block-paragraph">And like I said before, we can go up and down the call stack.</p>



<p class="wp-block-paragraph">So I can go down a couple times and then go back up again.</p>



<p class="wp-block-paragraph">And now we can assume that we&#8217;ve kind of debugged, you know, where the source of the error was.</p>



<p class="wp-block-paragraph">So I&#8217;m going to comment that call out to G and run the program again one more time with a different error.</p>



<p class="wp-block-paragraph">So I&#8217;ve commented this code out from before, but just imagine now that we&#8217;re going to use some pointers.</p>



<p class="wp-block-paragraph">We&#8217;re going to start off with a pointer called P.</p>



<p class="wp-block-paragraph">a pointer called p we&#8217;re going to set it to null at the beginning and then we&#8217;re going to just</p>



<p class="wp-block-paragraph">kind of allocate it and then we&#8217;re going to set you know a value and then we&#8217;re going to dereference</p>



<p class="wp-block-paragraph">it and dereferencing a pointer just kind of sets the first value in an array you can do that and</p>



<p class="wp-block-paragraph">then we&#8217;re going to deallocate the pointer and then how about right after that we do something</p>



<p class="wp-block-paragraph">really really naughty we say p at some index is equal to a five this should be this should be a</p>



<p class="wp-block-paragraph">a program crash because we deallocated p already at that point we would be dealing with junk data</p>



<p class="wp-block-paragraph">if we tried to dereference p but to make it even more clear that it&#8217;s naughty we&#8217;ll set it to a no</p>



<p class="wp-block-paragraph">pointer and then we&#8217;ll try to actually use it so let me let me just restart the program real fast</p>



<p class="wp-block-paragraph">i&#8217;m gonna do quit yes and then we&#8217;ll do make a debug just so you know my make debug is just a</p>



<p class="wp-block-paragraph">Let&#8217;s see, where&#8217;s that? Where&#8217;s that? Where&#8217;s that? Do I not have a debug shortcut yet?</p>



<p class="wp-block-paragraph">Oh dear. I need to add that before this video is over. You know what? I&#8217;ll add it right now.</p>



<p class="wp-block-paragraph">We&#8217;ll do this run and we&#8217;ll say debug, make debug, and it needs to build first. And then I&#8217;ll say</p>



<p class="wp-block-paragraph">debugging the program. And then we will do the GDB binary and give it an argument of</p>



<p class="wp-block-paragraph">the executable and then later we can we can upgrade this to take a little script of commands</p>



<p class="wp-block-paragraph">because the commands are going to start getting out of control so now if i do make debug if i</p>



<p class="wp-block-paragraph">didn&#8217;t screw it up now it at least goes in there and i&#8217;ll do run and then we have a seg fault and</p>



<p class="wp-block-paragraph">notice how it tells us right away hey you have a seg fault right here you&#8217;re accessing invalid</p>



<p class="wp-block-paragraph">memory let&#8217;s do info locals just to see what&#8217;s up oh the p is actually a zero that&#8217;s a null pointer</p>



<p class="wp-block-paragraph">explicitly oh whoops you know oh what have I done but it&#8217;s a really good idea to set your</p>



<p class="wp-block-paragraph">pointers to null after you deallocate because if you don&#8217;t you might end up with undefined</p>



<p class="wp-block-paragraph">behavior where sometimes the program doesn&#8217;t crash while you&#8217;re overriding junk data or reading junk</p>



<p class="wp-block-paragraph">data but sometimes it does and you&#8217;re not really sure like why does it work sometimes and why does</p>



<p class="wp-block-paragraph">it not work sometimes so let me comment this out and see if it&#8217;ll crash uh let&#8217;s just let&#8217;s just</p>



<p class="wp-block-paragraph">make debug and then i&#8217;ll do run and then if we do info locals oh yeah okay so this is uh</p>



<p class="wp-block-paragraph">it did seg fault so that&#8217;s good uh if we were unlucky then the program wouldn&#8217;t have crashed</p>



<p class="wp-block-paragraph">it would have just started behaving strangely and um when we print out the value of p notice how it</p>



<p class="wp-block-paragraph">looks like a pointer still like if we were to debug the program and print the pointer value</p>



<p class="wp-block-paragraph">then it doesn&#8217;t really it looks the same it looks the same after we deallocated it right so that</p>



<p class="wp-block-paragraph">this is called a dangling pointer meaning you deallocated the pointer but you forgot to set</p>



<p class="wp-block-paragraph">it to null afterwards so then later when you&#8217;re trying to debug the program it&#8217;s a little confusing</p>



<p class="wp-block-paragraph">because you&#8217;re like that looks like a regular pointer what did i do wrong so um it&#8217;s really</p>



<p class="wp-block-paragraph">good practice to set your pointers to null right after you deallocate them that way when you&#8217;re</p>



<p class="wp-block-paragraph">debugging later because something crashed instead of seeing a memory location on p you&#8217;ll see</p>



<p class="wp-block-paragraph">On P, you&#8217;ll see something that looks definitely like a null pointer and print P.</p>



<p class="wp-block-paragraph">Then it&#8217;s way easier to realize, oh, whoops, I was trying to use a dead pointer, a pointer that I deallocated.</p>



<p class="wp-block-paragraph">Hopefully that makes sense so far.</p>



<p class="wp-block-paragraph">Next thing I want to do is a small upgrade.</p>



<p class="wp-block-paragraph">I can&#8217;t remember if it&#8217;s dash X or dash EX.</p>



<p class="wp-block-paragraph">I think it&#8217;s dash X.</p>



<p class="wp-block-paragraph">But you can write a little script.</p>



<p class="wp-block-paragraph">I have a little script here called Good Doggo.</p>



<p class="wp-block-paragraph">called good doggo you can just make any file name it anything you want i&#8217;m so i&#8217;m just naming it</p>



<p class="wp-block-paragraph">good doggo.txt because my dog&#8217;s taking a little nap behind me as usual um but you could name this</p>



<p class="wp-block-paragraph">gdb.txt or whatever it is you want so you can put inside of this script file any command that you</p>



<p class="wp-block-paragraph">want gdb to execute when it launches so let&#8217;s just comment this stuff out real fast and i&#8217;ll do</p>



<p class="wp-block-paragraph">I&#8217;ll just do run maybe for starters.</p>



<p class="wp-block-paragraph">Because whenever I&#8217;ve been launching for debug,</p>



<p class="wp-block-paragraph">I launch with GDB and then I type run manually, right?</p>



<p class="wp-block-paragraph">So I want to save a little time.</p>



<p class="wp-block-paragraph">So good doggo is the name of the script.</p>



<p class="wp-block-paragraph">So when I invoke GDB, I am going to,</p>



<p class="wp-block-paragraph">where is it right there?</p>



<p class="wp-block-paragraph">Okay, it&#8217;s GDB.</p>



<p class="wp-block-paragraph">And then I&#8217;m going to go dot, I think it&#8217;s X.</p>



<p class="wp-block-paragraph">And then I&#8217;m going to say good doggo.txt.</p>



<p class="wp-block-paragraph">If it&#8217;s not dash x, then it&#8217;s dash ex.</p>



<p class="wp-block-paragraph">One of those executes the command that comes after,</p>



<p class="wp-block-paragraph">and one of those executes the command script that comes after.</p>



<p class="wp-block-paragraph">Let me just double check that this actually is going to work.</p>



<p class="wp-block-paragraph">So make debug.</p>



<p class="wp-block-paragraph">All right, okay, so it was dash x.</p>



<p class="wp-block-paragraph">Dash x specifies a script that will be run.</p>



<p class="wp-block-paragraph">Dash ex just specifies a command that you can put right in there.</p>



<p class="wp-block-paragraph">Like I could have said dash ex run, and it would have ran right away.</p>



<p class="wp-block-paragraph">But the script is more convenient, right?</p>



<p class="wp-block-paragraph">Because we can save typing.</p>



<p class="wp-block-paragraph">So notice how it ran right away and then there&#8217;s a seg fault.</p>



<p class="wp-block-paragraph">Okay, so now let&#8217;s go a little bit deeper.</p>



<p class="wp-block-paragraph">Let&#8217;s change this to false again now that we understand like null pointers and all that</p>



<p class="wp-block-paragraph">stuff.</p>



<p class="wp-block-paragraph">So we can just basically deal a little bit more with only what the main loop is doing.</p>



<p class="wp-block-paragraph">Suppose we just still don&#8217;t really understand what the loop is doing, why our answer is</p>



<p class="wp-block-paragraph">you know, good or bad.</p>



<p class="wp-block-paragraph">So maybe I want to do a breakpoint at the top of that for loop.</p>



<p class="wp-block-paragraph">loop gets to the top of its iteration, I want the program to pause so I can look around.</p>



<p class="wp-block-paragraph">So I&#8217;m going to set up a breakpoint on line 22. And here&#8217;s how you set up breakpoints</p>



<p class="wp-block-paragraph">in GDB. I&#8217;m going to go ahead and maybe do the terminal for now. And then I&#8217;ll stick that into</p>



<p class="wp-block-paragraph">the script next. I will not remember that it&#8217;s line 22. That&#8217;s okay. I&#8217;m going to do quit.</p>



<p class="wp-block-paragraph">And I&#8217;m going to do make build. Then I&#8217;m going to go GDB main just to jump in there.</p>



<p class="wp-block-paragraph">and then i&#8217;m going to say break or just the letter b just to make a break point you type the name of</p>



<p class="wp-block-paragraph">the source code file that you want to break in and then a colon and then the line number where</p>



<p class="wp-block-paragraph">you want it to break so i think i think it actually was line 22 oh i can see it and then</p>



<p class="wp-block-paragraph">maybe i want to have it break at line i don&#8217;t know maybe right here line 25 right before it increases</p>



<p class="wp-block-paragraph">And then so I&#8217;m going to do an up arrow to just repeat the command so I can edit it real fast.</p>



<p class="wp-block-paragraph">And then I&#8217;ll break again at line 28 and then maybe 30 and then 32.</p>



<p class="wp-block-paragraph">So I&#8217;m going to go 28, 30 and 32.</p>



<p class="wp-block-paragraph">30 and I&#8217;m just making up break points.</p>



<p class="wp-block-paragraph">I just want to inspect the program and then maybe I&#8217;ll break at line 36 so I can see what the final answer is.</p>



<p class="wp-block-paragraph">So I just have a bunch of break points set up.</p>



<p class="wp-block-paragraph">Remember when the program is running now under GDB, every time it hits one of those lines,</p>



<p class="wp-block-paragraph">every time it hits one of those lines the program will pause and i&#8217;ll have a chance to look around</p>



<p class="wp-block-paragraph">at the variables and things so i&#8217;m not sure if i&#8217;ve set up the breakpoints correctly i can say</p>



<p class="wp-block-paragraph">info breakpoints and it&#8217;ll show me all of my breakpoints notice how you can enable them and</p>



<p class="wp-block-paragraph">disable them so let&#8217;s say for the sake of argument i want to disable the breakpoint at line 30 because</p>



<p class="wp-block-paragraph">maybe i don&#8217;t really need that right now but i kind of want to keep it in the system for later</p>



<p class="wp-block-paragraph">disable four because it&#8217;s number four.</p>



<p class="wp-block-paragraph">It&#8217;s breakpoint number four.</p>



<p class="wp-block-paragraph">So I can say disable four.</p>



<p class="wp-block-paragraph">Then if I do info breakpoints again,</p>



<p class="wp-block-paragraph">notice how there&#8217;s a little N on there,</p>



<p class="wp-block-paragraph">meaning breakpoint four is disabled.</p>



<p class="wp-block-paragraph">So I could re-enable it with a four</p>



<p class="wp-block-paragraph">and then go info breakpoints again.</p>



<p class="wp-block-paragraph">So now they&#8217;re all enabled.</p>



<p class="wp-block-paragraph">I am going to maybe copy this into the script file real fast</p>



<p class="wp-block-paragraph">so I don&#8217;t have to keep typing this over and over and over again.</p>



<p class="wp-block-paragraph">Imagine if every single time you changed your program and recompiled it you had to type all of the breakpoints from scratch</p>



<p class="wp-block-paragraph">That&#8217;s why I want you to use this little breakpoint script</p>



<p class="wp-block-paragraph">So we&#8217;re going to do B to break at main.cpp line 22 and 25 and</p>



<p class="wp-block-paragraph">28 and</p>



<p class="wp-block-paragraph">30 and 32. I should have copy pasted the three dang it 36</p>



<p class="wp-block-paragraph">And after we&#8217;re done setting up all the breakpoints</p>



<p class="wp-block-paragraph">show me the breakpoints just so I can have a visual reminder. Keep in mind if you change too</p>



<p class="wp-block-paragraph">much of your source code then you&#8217;re probably going to have to update these lines and that&#8217;s</p>



<p class="wp-block-paragraph">okay but it&#8217;s a good idea to just at least you know kind of look at them a little bit so that&#8217;s</p>



<p class="wp-block-paragraph">why I&#8217;m saying info breakpoints. And so then remember again the makefile all it&#8217;s doing when</p>



<p class="wp-block-paragraph">I type make debug is it&#8217;s just launching this command right here it&#8217;s just saying gdb with the</p>



<p class="wp-block-paragraph">with my gdb script so let me quit to get out of this and then i&#8217;m going to say clear and make</p>



<p class="wp-block-paragraph">debug and notice how it did all that stuff for me it added the breakpoints it showed me the break</p>



<p class="wp-block-paragraph">points and then it ran the program like i told it to and then it already broke on a breakpoint it</p>



<p class="wp-block-paragraph">already break it break breakened it&#8217;s broken i don&#8217;t know i don&#8217;t think it&#8217;s broken uh so we&#8217;re</p>



<p class="wp-block-paragraph">So we&#8217;re on breakpoint number one on line 22.</p>



<p class="wp-block-paragraph">And here&#8217;s the for loop.</p>



<p class="wp-block-paragraph">I can type all of my inspection stuff.</p>



<p class="wp-block-paragraph">I can say info locals.</p>



<p class="wp-block-paragraph">I can say print I, I can say print A, I can print whatever I want.</p>



<p class="wp-block-paragraph">And then when I&#8217;m done kind of looking around and inspecting things,</p>



<p class="wp-block-paragraph">I want to continue the program.</p>



<p class="wp-block-paragraph">I don&#8217;t want to just stop it here.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to use the command continue.</p>



<p class="wp-block-paragraph">And it goes right to the next breakpoint.</p>



<p class="wp-block-paragraph">If I want to, you know, continue again, I can hit C.</p>



<p class="wp-block-paragraph">continue again i can hit c or i can just hit enter you know to just sort of keep continuing as i</p>



<p class="wp-block-paragraph">inspect and print things let&#8217;s see when can i get to break point number one is that what&#8217;s going on</p>



<p class="wp-block-paragraph">here hang on a second what is break point number one oh i know what to do info break points</p>



<p class="wp-block-paragraph">break point number one is that main.cpp line 22 is that actually going to get hit oh it&#8217;s</p>



<p class="wp-block-paragraph">having issues here with my GUI. Okay. Line 22. Okay. So it&#8217;s not really hitting that anymore.</p>



<p class="wp-block-paragraph">I guess it&#8217;s not going to think that it hits the top of the forelip. Okay. So I guess breakpoint</p>



<p class="wp-block-paragraph">two is where we&#8217;re always going to be hitting. So let&#8217;s just suppose that I&#8217;m continuing until</p>



<p class="wp-block-paragraph">I hit breakpoint number two. Suppose that the next 10 times I see breakpoint two, I don&#8217;t</p>



<p class="wp-block-paragraph">actually want to stop and break on it. I just want to skip the next 10 iterations for some reason.</p>



<p class="wp-block-paragraph">some reason you can say continue 10 and it&#8217;ll skip the next 10 times that it hits the number two</p>



<p class="wp-block-paragraph">notice how if i hit continue a bunch of times we&#8217;re not really seeing the break point number</p>



<p class="wp-block-paragraph">two anymore we&#8217;re seeing other break points and then eventually if i hit it enough times</p>



<p class="wp-block-paragraph">we&#8217;ll probably see two again oh my god oh my god are we seeing it yet no</p>



<p class="wp-block-paragraph">Okay, wait, are we seeing I&#8217;m freaking myself out.</p>



<p class="wp-block-paragraph">Okay, so let&#8217;s continue 10 times on breakpoint three, then we&#8217;ll only see</p>



<p class="wp-block-paragraph">breakpoint four, I guess.</p>



<p class="wp-block-paragraph">So we can do continue 10 times on breakpoint four.</p>



<p class="wp-block-paragraph">What is going on here?</p>



<p class="wp-block-paragraph">Did I write this program in a weird way?</p>



<p class="wp-block-paragraph">Hmm.</p>



<p class="wp-block-paragraph">Well, trust me on this.</p>



<p class="wp-block-paragraph">Let&#8217;s continue 100 on breakpoint three and then continue 100 on breakpoint four.</p>



<p class="wp-block-paragraph">breakpoint 4. Okay, so now we&#8217;re just done with the whole entire program. I guess there must have</p>



<p class="wp-block-paragraph">been a 2 there that I missed. So now we&#8217;re finally on breakpoint 6, which is when everything is</p>



<p class="wp-block-paragraph">finished. Let me show you real fast that we can add more breakpoints in assembly just to prove</p>



<p class="wp-block-paragraph">that we can debug assembly real fast. So if I want to debug assembly, I just have to type the name of</p>



<p class="wp-block-paragraph">that source code file. If it was nested in a folder, like if you had like a complicated hierarchy of</p>



<p class="wp-block-paragraph">of source code files you would just need to type the relative path but for now I&#8217;m just going to</p>



<p class="wp-block-paragraph">be able to type the name of the file so assy.asm and let&#8217;s suppose that I want to break at line</p>



<p class="wp-block-paragraph">16 just so I can see the registers that I set up so I&#8217;m going to do 16 and then I&#8217;m going to break</p>



<p class="wp-block-paragraph">at assy.asm line 16 and then I&#8217;m going to run and that actually never gets called does it no no it</p>



<p class="wp-block-paragraph">called does it no no it gets called I think I have a call up here somewhere</p>



<p class="wp-block-paragraph">nope I don&#8217;t have a call okay let&#8217;s make a call this is gonna throw off all of my</p>



<p class="wp-block-paragraph">C++ breakpoints so I&#8217;ll just comment them all out right now comment them all</p>



<p class="wp-block-paragraph">out so I don&#8217;t have to redo them and this is a hybrid program so I&#8217;m gonna go</p>



<p class="wp-block-paragraph">extern what is it extern C make a block where I name the function the reason we</p>



<p class="wp-block-paragraph">name mangling so the AC symbol is going to show up as just its regular function</p>



<p class="wp-block-paragraph">name rather than a bunch of extra stuff indicating the prototype so that we can</p>



<p class="wp-block-paragraph">do overloading so we&#8217;re just going to disable that and then at the very top of</p>



<p class="wp-block-paragraph">the program I&#8217;m just going to call it this should hopefully work let me just</p>



<p class="wp-block-paragraph">do a regular make run just to make sure the whole program compiles okay now</p>



<p class="wp-block-paragraph">debug script we&#8217;re gonna break on line 16 which is going to be letting us see</p>



<p class="wp-block-paragraph">the registers okay so I&#8217;m gonna go make debug notice how it hit the breakpoint</p>



<p class="wp-block-paragraph">in the assembly just the same as the C++ and we can print whatever we want now so</p>



<p class="wp-block-paragraph">I&#8217;m just gonna say info registers and if we look carefully we can kind of see</p>



<p class="wp-block-paragraph">that we modified racks REX is 15 so that&#8217;s expected RDI is 20 which is</p>



<p class="wp-block-paragraph">R12 should be a giant number. Where&#8217;s R12? Right there. So you can see the state of your program at any point in time just by breaking on it.</p>



<p class="wp-block-paragraph">I&#8217;m breaking on a certain line. So this is tremendously useful for debugging not just for higher level languages but also assembly.</p>



<p class="wp-block-paragraph">What else can I do? Oh let&#8217;s put a global in the data section. So I&#8217;m gonna do, I don&#8217;t know, my thing or something like that and we&#8217;ll call it a byte array and I&#8217;ll just go hello.</p>



<p class="wp-block-paragraph">I&#8217;ll say we have a thing one and a thing two.</p>



<p class="wp-block-paragraph">Something like that.</p>



<p class="wp-block-paragraph">And maybe thing two is a null terminated string,</p>



<p class="wp-block-paragraph">whereas thing one is a regular thing.</p>



<p class="wp-block-paragraph">We should be able to print those symbols.</p>



<p class="wp-block-paragraph">If that&#8217;s not true, I&#8217;ll come back at a later time</p>



<p class="wp-block-paragraph">and show you how to do it.</p>



<p class="wp-block-paragraph">Anyway, so we&#8217;ll do make debug</p>



<p class="wp-block-paragraph">to just kind of assemble everything again.</p>



<p class="wp-block-paragraph">And we know how to do info registers.</p>



<p class="wp-block-paragraph">We can print, you know, one register in particular,</p>



<p class="wp-block-paragraph">print R12 if we wanted to.</p>



<p class="wp-block-paragraph">History has not reached.</p>



<p class="wp-block-paragraph">History has not reached 12.</p>



<p class="wp-block-paragraph">Oh, I got to put R12.</p>



<p class="wp-block-paragraph">Yeah, then we can get the, wait a minute, wait a minute.</p>



<p class="wp-block-paragraph">Oh, I threw off the line numbers because I added the variables up here.</p>



<p class="wp-block-paragraph">So now we&#8217;re going to break at 21.</p>



<p class="wp-block-paragraph">Let me just fix that.</p>



<p class="wp-block-paragraph">21.</p>



<p class="wp-block-paragraph">We&#8217;ll do a quit.</p>



<p class="wp-block-paragraph">Make debug again.</p>



<p class="wp-block-paragraph">And now we&#8217;re at 21.</p>



<p class="wp-block-paragraph">If I say info registers, we can see R12 is that big value.</p>



<p class="wp-block-paragraph">you, but we can also print R12 directly. And we should be able to print my thing one, hopefully,</p>



<p class="wp-block-paragraph">has an unknown type, oh, we have to cast it. So we can do like basic casting in GDB. So I&#8217;m going</p>



<p class="wp-block-paragraph">to say this is a character pointer. Remember, all of the assembly symbols are basically pointers,</p>



<p class="wp-block-paragraph">unless it&#8217;s an EQU, EQU variable. In that case, it&#8217;s more of a define. So I&#8217;m going to print</p>



<p class="wp-block-paragraph">and then it says error cannot access the memory add address</p>



<p class="wp-block-paragraph">what the heck did i do wrong how about that cannot access that all right i&#8217;ll come back in</p>



<p class="wp-block-paragraph">another video because this wasn&#8217;t something that i prepared for just to print strings in globals</p>



<p class="wp-block-paragraph">i&#8217;ll come back at some later date in the future like five years from now and i&#8217;ll just show you</p>



<p class="wp-block-paragraph">how to print globals but i hope if you&#8217;re in assembly you probably don&#8217;t need to worry about</p>



<p class="wp-block-paragraph">You just have globals, but the real problem for you is going to be what&#8217;s inside of your registers and so forth.</p>



<p class="wp-block-paragraph">You can also deref, I think.</p>



<p class="wp-block-paragraph">Let me see.</p>



<p class="wp-block-paragraph">Okay, I&#8217;m going to move on from that.</p>



<p class="wp-block-paragraph">So anyway, we got a script and we got a lot of basic GDB commands.</p>



<p class="wp-block-paragraph">Is there anything else that I wanted to show you?</p>



<p class="wp-block-paragraph">Let me just look at my notes real fast here to make sure I&#8217;m not forgetting to say anything.</p>



<p class="wp-block-paragraph">make sure I&#8217;m not forgetting to say anything.</p>



<p class="wp-block-paragraph">So we&#8217;re going to do debug symbols, console, quit, attach to binary,</p>



<p class="wp-block-paragraph">launching the program, uncaught exception, breakpoints, info, delete,</p>



<p class="wp-block-paragraph">enable, disable, run, continue, end times, info registers, printing.</p>



<p class="wp-block-paragraph">Oh, we can print a register in binary.</p>



<p class="wp-block-paragraph">Forgot to show that.</p>



<p class="wp-block-paragraph">So we are at a breakpoint, I think.</p>



<p class="wp-block-paragraph">And if we printed R12 with the regular print, we can also do P slash T to just</p>



<p class="wp-block-paragraph">p slash t to just sort of print it in binary if you want to i think i might have said that already</p>



<p class="wp-block-paragraph">either that or i said that like a couple days ago to some and then we can do info locals and</p>



<p class="wp-block-paragraph">then print a variable and then we get the script file and then we can quit okay so i think this is</p>



<p class="wp-block-paragraph">pretty much everything that i wanted to show you you now have a basic idea of what we can do inside</p>



<p class="wp-block-paragraph">of gdb but keep in mind there is so much more you can do in gdb than i can fit in one video</p>



<p class="wp-block-paragraph">can type help and you can see a list of other major you know areas that gdb can handle um you</p>



<p class="wp-block-paragraph">can do uh let&#8217;s see i think it&#8217;s help and then like we&#8217;ve got information on aliases breakpoints</p>



<p class="wp-block-paragraph">data you know whatever we can do i think help breakpoints to see more information on breakpoint</p>



<p class="wp-block-paragraph">commands yeah so all of the things you can do with breakpoints is like all of these commands here</p>



<p class="wp-block-paragraph">one page we have to enter to see one more page or see to see all of the results without using</p>



<p class="wp-block-paragraph">paging anymore so i&#8217;m just hit c and so there&#8217;s like you know we can save trace points we can</p>



<p class="wp-block-paragraph">try to catch exceptions we can enable disable break points there&#8217;s like unwinders which i&#8217;ve</p>



<p class="wp-block-paragraph">never even used we can bookmark things we can you know start tracing memory we can rethrow</p>



<p class="wp-block-paragraph">variables so just keep in mind gdp is incredibly powerful this video barely scratches the surface</p>



<p class="wp-block-paragraph">but for a programmer who is new to debugging i think this will be very useful to you i hope it is</p>



<p class="wp-block-paragraph">anyway thanks for watching this video i hope you learned a little bit of stuff and had a</p>



<p class="wp-block-paragraph">little bit of fun um i will see you in the next video rest yourself and take a nap and have fun</p>



<p class="wp-block-paragraph">and hug your your loved ones okay I&#8217;m out see you later hey everybody thanks</p>



<p class="wp-block-paragraph">for watching this video again from the bottom of my heart I really appreciate</p>



<p class="wp-block-paragraph">it I do hope you did learn something and have some fun if you could do me a</p>



<p class="wp-block-paragraph">please a small little favor could you please subscribe and follow this channel</p>



<p class="wp-block-paragraph">channel or these videos or whatever it is you do on the current social media</p>



<p class="wp-block-paragraph">website that you&#8217;re looking at right now it would really mean the world to me</p>



<p class="wp-block-paragraph">and it&#8217;ll help make more videos and grow this community so we&#8217;ll be able to do</p>



<p class="wp-block-paragraph">more videos longer videos better videos or just I&#8217;ll be able to keep making</p>



<p class="wp-block-paragraph">videos in general so please do do me a kindness and and subscribe you know</p>



<p class="wp-block-paragraph">sometimes I&#8217;m sleeping in the middle of the night and I just wake up because I</p>



<p class="wp-block-paragraph">know somebody subscribed or followed it just wakes me up and I get filled with</p>



<p class="wp-block-paragraph">That&#8217;s exactly what happens every single time.</p>



<p class="wp-block-paragraph">So you could do it as a nice favor to me,</p>



<p class="wp-block-paragraph">or you could troll me if you want to just wake me up in the middle of the night.</p>



<p class="wp-block-paragraph">Just subscribe, and then I&#8217;ll just wake up.</p>



<p class="wp-block-paragraph">I promise that&#8217;s what will happen.</p>



<p class="wp-block-paragraph">Also, if you look at the middle of the screen right now,</p>



<p class="wp-block-paragraph">you should see a QR code, which you can scan in order to go to the website,</p>



<p class="wp-block-paragraph">which I think is also named somewhere at the bottom of this video.</p>



<p class="wp-block-paragraph">And it&#8217;ll take you to my main website,</p>



<p class="wp-block-paragraph">where you can just kind of like see all the videos I published,</p>



<p class="wp-block-paragraph">and the services and tutorials and things that I offer,</p>



<p class="wp-block-paragraph">and all that good stuff.</p>



<p class="wp-block-paragraph">things that I offer and all that good stuff. And, uh, if you have a suggestion for, uh, uh,</p>



<p class="wp-block-paragraph">clarifications or errata, or just future videos that you want to see, please leave a comment.</p>



<p class="wp-block-paragraph">Or if you just want to say, Hey, what&#8217;s up, what&#8217;s going on? You know, just send me a comment,</p>



<p class="wp-block-paragraph">whatever. I also wake up for those in the middle of the night. I get, I wake up in a cold sweat</p>



<p class="wp-block-paragraph">and I&#8217;m like, it would really, it really mean the world to me. I would really appreciate it. So</p>



<p class="wp-block-paragraph">watching this video and enjoy the cool music as I fade into the darkness which is coming for us all.</p>



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/master-gnu-debugger-debug-c-assembly-programs-with-gdb-like-a-pro/">Master GNU Debugger: Debug C++ &amp; Assembly Programs with GDB Like a Pro</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/master-gnu-debugger-debug-c-assembly-programs-with-gdb-like-a-pro/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How Linkers Work: Linking Code, Virtual Memory, and Module Jumps Explained</title>
		<link>https://www.NeuralLantern.com/how-linkers-work-linking-code-virtual-memory-and-module-jumps-explained/</link>
					<comments>https://www.NeuralLantern.com/how-linkers-work-linking-code-virtual-memory-and-module-jumps-explained/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Mon, 02 Jun 2025 13:04:50 +0000</pubDate>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[C++ programming]]></category>
		<category><![CDATA[code linking]]></category>
		<category><![CDATA[coding tutorials]]></category>
		<category><![CDATA[compilation]]></category>
		<category><![CDATA[computer science]]></category>
		<category><![CDATA[executable files]]></category>
		<category><![CDATA[jump instructions]]></category>
		<category><![CDATA[linker]]></category>
		<category><![CDATA[module linking]]></category>
		<category><![CDATA[object files]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming basics]]></category>
		<category><![CDATA[software development]]></category>
		<category><![CDATA[virtual memory]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=139</guid>

					<description><![CDATA[<p>Learn how linkers connect code modules, manage virtual memory, and handle jumps in this beginner-friendly guide to programming! #Linker #Coding</p>
<p>The post <a href="https://www.NeuralLantern.com/how-linkers-work-linking-code-virtual-memory-and-module-jumps-explained/">How Linkers Work: Linking Code, Virtual Memory, and Module Jumps Explained</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="How Linkers Work: Linking Code, Virtual Memory, and Module Jumps Explained" width="1380" height="776" src="https://www.youtube.com/embed/Q6B9FWCeaFs?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">Hey everyone, let’s talk linkers! In this video, we unpack the general idea of linking in programming—taking your source code, turning it into object files, and stitching them into an executable. We dive into virtual memory, how programs use offsets, and why jump instructions matter across modules. Using simple assembly and C++ examples, we’ll show how linkers lay out modules, handle labels, and make function calls work. Whether you’re a beginner or a coder curious about what happens under the hood, this is for you! Hit subscribe, scan the QR code for more tutorials, and drop a comment with your thoughts or video ideas. Let’s keep learning and have some fun with code! #Programming #Linker #VirtualMemory #CodingExplained</p>



<p class="wp-block-paragraph">Introduction to Linking 00:00:00<br>Compilation and Object Files 00:00:05<br>Linker Overview 00:00:32<br>Virtual Memory Explanation 00:00:42<br>Program Memory Offsets 00:01:18<br>Jump Instructions in Modules 00:02:54<br>Module Address Space 00:03:38<br>Assembler and Label Jumps 00:04:02<br>Linker’s Role in Module Layout 00:07:15<br>Function Calls Across Modules 00:08:04<br>Marking Labels as Global 00:09:31<br>External Function Calls 00:10:23<br>Data in Executables 00:11:12<br>Conclusion and Call to Subscribe 00:12:08</p>



<p class="wp-block-paragraph">Thanks for watching!</p>



<p class="wp-block-paragraph">Find us on other social media here:</p>



<ul class="wp-block-list">
<li>https://www.NeuralLantern.com/social</li>
</ul>



<p class="wp-block-paragraph">Please help support us!</p>



<ul class="wp-block-list">
<li>Subscribing + Sharing on Social Media</li>



<li>Leaving a comment or suggestion</li>



<li>Subscribing to our Blog</li>



<li>Watching the main &#8220;pinned&#8221; video of this channel for offers and extras</li>
</ul>



<p class="wp-block-paragraph">Hey there, I want to talk to you very quickly about the general idea of linking your programs.</p>



<p class="wp-block-paragraph">In previous videos I&#8217;ve described exactly how to perform the linking stage when you&#8217;re compiling</p>



<p class="wp-block-paragraph">a program. So you write some source code, you compile the source code into object files,</p>



<p class="wp-block-paragraph">you know each file becomes one individual object file, and then when we&#8217;re done we take all the</p>



<p class="wp-block-paragraph">object files and we link them up into an executable program. So I&#8217;ve talked about that</p>



<p class="wp-block-paragraph">I just wanted to talk to you about the general idea of the linking stage in general.</p>



<p class="wp-block-paragraph">Like what is the linker? What is its job? What is it actually doing?</p>



<p class="wp-block-paragraph">So try to keep in mind for starters, each program uses virtual memory.</p>



<p class="wp-block-paragraph">It uses a virtual memory space.</p>



<p class="wp-block-paragraph">So obviously on your computer you have real memory,</p>



<p class="wp-block-paragraph">but there&#8217;s lots of layers of abstraction between the physical hardware</p>



<p class="wp-block-paragraph">the physical hardware and the program that&#8217;s running for starters the operating system uses</p>



<p class="wp-block-paragraph">a paging system the memory stick the memory circuitry might be doing something else for</p>



<p class="wp-block-paragraph">error checking or just you know transport or whatever so so try and bear in mind that each</p>



<p class="wp-block-paragraph">program thinks that it&#8217;s it thinks that itself is kind of the beginning of memory you could imagine</p>



<p class="wp-block-paragraph">it as each program thinks that its first memory location that it has assigned to it is memory</p>



<p class="wp-block-paragraph">location zero but that wouldn&#8217;t necessarily be the case on the computer</p>



<p class="wp-block-paragraph">your operating system probably would have come up with an offset let&#8217;s say</p>



<p class="wp-block-paragraph">for example you know your computer decides to launch your program it</p>



<p class="wp-block-paragraph">creates a process it finds a chunk of memory that&#8217;s available across you know</p>



<p class="wp-block-paragraph">one or more pages of free memory and let&#8217;s say for the sake of argument that</p>



<p class="wp-block-paragraph">the starting offset for the for the quote-unquote real forgetting the other</p>



<p class="wp-block-paragraph">layers layers of abstraction the real memory location of your program is going</p>



<p class="wp-block-paragraph">of your program is going to be let&#8217;s just say like a thousand I know that&#8217;s</p>



<p class="wp-block-paragraph">real unrealistically too low but let&#8217;s just say a thousand and then let&#8217;s say</p>



<p class="wp-block-paragraph">that your program then thinks that it starts at memory location zero that</p>



<p class="wp-block-paragraph">means if your program wants to access memory location 100 then under the hood</p>



<p class="wp-block-paragraph">at the last moment right before you actually hit the RAM stick or hit the</p>



<p class="wp-block-paragraph">page file system a translation has to be performed so if your program is trying</p>



<p class="wp-block-paragraph">what actually happens is you know the general offset for the entire program</p>



<p class="wp-block-paragraph">gets added to memory location 100 and then that tells the computer or the</p>



<p class="wp-block-paragraph">operating system that what you&#8217;re actually trying to do in your program is</p>



<p class="wp-block-paragraph">access memory location 1100 so keep in mind all of this memory is virtual</p>



<p class="wp-block-paragraph">and the modules themselves also need to know where to jump when I say where to</p>



<p class="wp-block-paragraph">Well, suppose for the sake of argument, you have a program that has some jump instructions</p>



<p class="wp-block-paragraph">or go to instructions or like some conditional branching instructions, anything where execution</p>



<p class="wp-block-paragraph">is not just going to go to the very next statement.</p>



<p class="wp-block-paragraph">Execution is going to go somewhere else.</p>



<p class="wp-block-paragraph">Like maybe you have an if else block.</p>



<p class="wp-block-paragraph">It&#8217;s got to maybe jump sometimes down to the else part instead of the top if part.</p>



<p class="wp-block-paragraph">And then when it&#8217;s done executing, it&#8217;s going to jump until after the whole block, you know,</p>



<p class="wp-block-paragraph">There will be lots of times in all of your programs where execution kind of has to jump</p>



<p class="wp-block-paragraph">around somewhere if the program is even a little bit complicated.</p>



<p class="wp-block-paragraph">So that could be a jump instruction, go to in a higher level language, not assembly necessarily,</p>



<p class="wp-block-paragraph">jump if not equal and so forth.</p>



<p class="wp-block-paragraph">So if you imagine writing one module, you could also imagine that the module has its</p>



<p class="wp-block-paragraph">own virtual memory address space.</p>



<p class="wp-block-paragraph">Just imagine it for now.</p>



<p class="wp-block-paragraph">And maybe it starts at zero.</p>



<p class="wp-block-paragraph">at zero that&#8217;s that&#8217;s not what we&#8217;re going to say but just like imagine the module only really knows</p>



<p class="wp-block-paragraph">about itself and so sometimes when you&#8217;re jumping for example if we&#8217;re going to jump uh when</p>



<p class="wp-block-paragraph">something is not equal to something else we&#8217;ll jump to some label and in order to jump to that</p>



<p class="wp-block-paragraph">label the assembler needs to know you know where is that label inside of your source code so pretend</p>



<p class="wp-block-paragraph">just for a moment this is not like a real assembly program but just pretend for a moment that we have</p>



<p class="wp-block-paragraph">and maybe this is like I don&#8217;t know the main label that gets jumped into from GCC and</p>



<p class="wp-block-paragraph">so then we have like a label down here outside and we&#8217;ll do stuff and then jump back to the</p>



<p class="wp-block-paragraph">original point so we probably have to do a label here main finish this is this is bad form but I&#8217;m</p>



<p class="wp-block-paragraph">So if we jump, let&#8217;s compare, I don&#8217;t know, one with two or something.</p>



<p class="wp-block-paragraph">Let&#8217;s compare RAX to RDX and we&#8217;ll just move RAX the value one and move RDX the value two</p>



<p class="wp-block-paragraph">so they&#8217;re not actually equal.</p>



<p class="wp-block-paragraph">And then we compare them and then we say, all right, jump if they&#8217;re not equal to this label.</p>



<p class="wp-block-paragraph">So definitely now we know, oh, we are going to jump down to that label.</p>



<p class="wp-block-paragraph">So execution is going to go directly down to here.</p>



<p class="wp-block-paragraph">we&#8217;ll do something and then eventually maybe we want to jump back so we&#8217;ll say uh</p>



<p class="wp-block-paragraph">maybe let&#8217;s do it again let&#8217;s do let&#8217;s do like a whole set of statements again we&#8217;ll say jump</p>



<p class="wp-block-paragraph">if it is equal and we&#8217;ll just like load those two registers so one and one and then compare</p>



<p class="wp-block-paragraph">them and then say jump if it is equal to main finish this is not a video about conditional</p>



<p class="wp-block-paragraph">branching or jumping i&#8217;m trying to make this as simple as i can but i hope you understand the</p>



<p class="wp-block-paragraph">but i hope you understand the point is just basically we&#8217;re jumping around within the same</p>



<p class="wp-block-paragraph">module right so it&#8217;s easy for the program to understand where to jump if it&#8217;s in the same</p>



<p class="wp-block-paragraph">module or i guess the the object file when we&#8217;re assembling it it&#8217;s easy to understand where to jump</p>



<p class="wp-block-paragraph">because if we&#8217;re at line 8 here when we start to jump and then the actual label here has its first</p>



<p class="wp-block-paragraph">instruction at line 17 well then it you know the amount of instructions to move is just the</p>



<p class="wp-block-paragraph">the difference you know so it&#8217;s easy to say all right if our virtual address is you know this</p>



<p class="wp-block-paragraph">when we jump and we&#8217;re going to jump this much of a difference based on where the label is then now</p>



<p class="wp-block-paragraph">we can just compute the new virtual address to jump or the absolute address or whatever you want</p>



<p class="wp-block-paragraph">to whatever you want to do on that particular run but how does it know where to jump in another</p>



<p class="wp-block-paragraph">module because when we assemble this module as an object file the assembler is only running one pass</p>



<p class="wp-block-paragraph">one pass on just this object file it doesn&#8217;t really know the addresses in the other modules</p>



<p class="wp-block-paragraph">it doesn&#8217;t know their offsets of its labels even if it&#8217;s a c plus plus or a c module it doesn&#8217;t</p>



<p class="wp-block-paragraph">really know the offsets it doesn&#8217;t know where the functions start and end doesn&#8217;t know anything</p>



<p class="wp-block-paragraph">because right now if we assemble this one source code it&#8217;s only going to know about this one source</p>



<p class="wp-block-paragraph">code right and the same goes for the other modules if we compile a c plus plus program to an object</p>



<p class="wp-block-paragraph">a function or you know do a go to statement or something into one of these labels from this</p>



<p class="wp-block-paragraph">module the c plus plus program won&#8217;t really know where it is it won&#8217;t know what address it&#8217;s at it</p>



<p class="wp-block-paragraph">won&#8217;t know the offset right so that&#8217;s the job of the linker the linker looks at all of these labels</p>



<p class="wp-block-paragraph">and all of these uh conditional branching statements and jump statements and everything</p>



<p class="wp-block-paragraph">and it just decides for starters it decides where each module is going to start in memory so maybe</p>



<p class="wp-block-paragraph">I don&#8217;t know if your C++ module starts up here somewhere and then it&#8217;ll say this assembly module</p>



<p class="wp-block-paragraph">starts right after it and then another module right after that and it&#8217;ll just kind of decide</p>



<p class="wp-block-paragraph">where every module will start in the final executable that we&#8217;re actually linking together.</p>



<p class="wp-block-paragraph">Once it decides the layout then it knows the offset of all the different modules and therefore</p>



<p class="wp-block-paragraph">it can compute the additional offset that it would take to get to all the labels. So then at that</p>



<p class="wp-block-paragraph">Your C++ module will make a function call inside of, you know, some assembly module like the one we&#8217;re looking at, assuming it was written a little bit differently.</p>



<p class="wp-block-paragraph">Main finish return.</p>



<p class="wp-block-paragraph">I guess the way it&#8217;s written down here, it&#8217;s returning to main if we just kind of execute it as we&#8217;re looking at it.</p>



<p class="wp-block-paragraph">But another module could could call main finish as a function and still get a return statement.</p>



<p class="wp-block-paragraph">That would actually work, even though it&#8217;s probably bad design.</p>



<p class="wp-block-paragraph">that your assembly sorry your C++ program wants to call a function called</p>



<p class="wp-block-paragraph">main finish inside of this module the linker having already laid out the</p>



<p class="wp-block-paragraph">modules and and being aware of all their offsets it knows okay so you know this</p>



<p class="wp-block-paragraph">assembly module it was underneath the C++ module so it&#8217;ll just take that offset</p>



<p class="wp-block-paragraph">and add it to the offset of the label itself within the module and then also</p>



<p class="wp-block-paragraph">add that to the the virtual address or I guess the operating system will do the</p>



<p class="wp-block-paragraph">address. But you know, the point is the linker coordinates all the jumps and the conditional</p>



<p class="wp-block-paragraph">branches where the functions start, lays out all the modules, gets all the offsets,</p>



<p class="wp-block-paragraph">and then starts replacing all of the conditional branches and jumps and things with the real</p>



<p class="wp-block-paragraph">offsets that make it actually doable. Like let&#8217;s jump to exactly this memory location</p>



<p class="wp-block-paragraph">in code exactly in quotes, because we&#8217;re still using virtual addressing.</p>



<p class="wp-block-paragraph">idea of the linker it knows how to jump between modules um wants to link or discuss okay that&#8217;s</p>



<p class="wp-block-paragraph">all i really wanted to say don&#8217;t forget if you want a label to be available to jump into or to</p>



<p class="wp-block-paragraph">call as a function from outside the module you got to mark it as global so if i actually wanted</p>



<p class="wp-block-paragraph">somebody to be able to call main finish as a function i just have to mark it as global same</p>



<p class="wp-block-paragraph">thing for some label if i say global some label then now at this point another module could call</p>



<p class="wp-block-paragraph">call this as a function or jump into it probably bad form to not put a return a return statement</p>



<p class="wp-block-paragraph">at this point which means when i&#8217;m calling it up here instead of jump not equal to i probably have</p>



<p class="wp-block-paragraph">to add more complicated logic so i can use a function call that gets jumped around if it is</p>



<p class="wp-block-paragraph">equal but so i&#8217;m not going to go that far right now kind of complicated just for this video</p>



<p class="wp-block-paragraph">and then also of course if you intend to jump somewhere else remember that you have to mark</p>



<p class="wp-block-paragraph">So let&#8217;s say there&#8217;s a function in your other module, your C++ module or your C module or your assembly module.</p>



<p class="wp-block-paragraph">You just have to mark it as extern in the text section, in the text segment, like some other function somewhere else, something like that.</p>



<p class="wp-block-paragraph">And then once I do that, now I could actually call it, I could say, call, you know, this.</p>



<p class="wp-block-paragraph">Actually, that&#8217;ll never get reached because the jump equal thing is at the bottom.</p>



<p class="wp-block-paragraph">equal thing is at the bottom but I could do this I could say call it if it was actually a function</p>



<p class="wp-block-paragraph">or I could say jump if it was just a jump point or I could say you know jump not equal to</p>



<p class="wp-block-paragraph">the other function instead of some label something like that so lots of stuff you can do and now you</p>



<p class="wp-block-paragraph">kind of understand the idea of linking is taking all the modules stuffing them inside of the final</p>



<p class="wp-block-paragraph">executable and also putting data inside of the final executable you know like if you&#8217;re creating</p>



<p class="wp-block-paragraph">So, you know, like if you&#8217;re creating a string variable in your globals area of your assembly</p>



<p class="wp-block-paragraph">program or hard coding, any kind of string anywhere in your C++, then it&#8217;s got to be</p>



<p class="wp-block-paragraph">inside of the executable.</p>



<p class="wp-block-paragraph">Otherwise, it wouldn&#8217;t be anywhere when we ran the program.</p>



<p class="wp-block-paragraph">So, yeah, it sticks the data in there.</p>



<p class="wp-block-paragraph">It sticks the segments in there.</p>



<p class="wp-block-paragraph">It, you know, calculates the jumps and all that stuff.</p>



<p class="wp-block-paragraph">I just want to point out you could put strings in a configuration file.</p>



<p class="wp-block-paragraph">of a vanilla C++ or assembly program you probably are making strings directly in the program.</p>



<p class="wp-block-paragraph">Anyway, so I think that&#8217;s the gist of everything that I really wanted to say about what is the</p>



<p class="wp-block-paragraph">general idea of the linker. Thanks for watching this video I hope you learned a little bit and</p>



<p class="wp-block-paragraph">had some fun. I will see you in the next video. Hey everybody thanks for watching this video again</p>



<p class="wp-block-paragraph">it i do hope you did learn something and have some fun if you could do me a please a small little</p>



<p class="wp-block-paragraph">favor could you please subscribe and follow this channel or these videos or whatever it is you do</p>



<p class="wp-block-paragraph">on the current social media website that you&#8217;re looking at right now it would really mean the</p>



<p class="wp-block-paragraph">world to me and it&#8217;ll help make more videos and grow this community so we&#8217;ll be able to do more</p>



<p class="wp-block-paragraph">videos longer videos better videos or just i&#8217;ll be able to keep making videos in general so please</p>



<p class="wp-block-paragraph">and subscribe. You know, sometimes I&#8217;m sleeping in the middle of the night and I just wake up</p>



<p class="wp-block-paragraph">because I know somebody subscribed or followed. It just wakes me up and I get filled with joy.</p>



<p class="wp-block-paragraph">That&#8217;s exactly what happens every single time. So you could do it as a nice favor to me or you</p>



<p class="wp-block-paragraph">could troll me if you want to just wake me up in the middle of the night, just subscribe</p>



<p class="wp-block-paragraph">and then I&#8217;ll just wake up. I promise that&#8217;s what will happen. Also, if you look at the middle of</p>



<p class="wp-block-paragraph">the screen right now, you should see a QR code, which you can scan in order to go to the website,</p>



<p class="wp-block-paragraph">is also named somewhere at the bottom of this video and it&#8217;ll take you to my main website where</p>



<p class="wp-block-paragraph">you can just kind of like see all the videos I published and the services and tutorials and</p>



<p class="wp-block-paragraph">things that I offer and all that good stuff and uh if you have a suggestion for uh uh clarifications</p>



<p class="wp-block-paragraph">or errata or just future videos that you want to see please leave a comment or if you just want to</p>



<p class="wp-block-paragraph">say hey what&#8217;s up what&#8217;s going on you know just send me a comment whatever I also wake up for</p>



<p class="wp-block-paragraph">I wake up in a cold sweat and I&#8217;m like, it would really mean the world to me.</p>



<p class="wp-block-paragraph">I would really appreciate it.</p>



<p class="wp-block-paragraph">So again, thank you so much for watching this video and enjoy the cool music as I fade into</p>



<p class="wp-block-paragraph">the darkness, which is coming for us all.</p>



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/how-linkers-work-linking-code-virtual-memory-and-module-jumps-explained/">How Linkers Work: Linking Code, Virtual Memory, and Module Jumps Explained</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/how-linkers-work-linking-code-virtual-memory-and-module-jumps-explained/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Master GNU Makefiles: Streamline Coding Builds with C++, C &#038; Assembly</title>
		<link>https://www.NeuralLantern.com/master-gnu-makefiles-streamline-coding-builds-with-c-c-assembly/</link>
					<comments>https://www.NeuralLantern.com/master-gnu-makefiles-streamline-coding-builds-with-c-c-assembly/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sun, 25 May 2025 07:53:49 +0000</pubDate>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[beginner coding]]></category>
		<category><![CDATA[build automation]]></category>
		<category><![CDATA[build system]]></category>
		<category><![CDATA[C programming]]></category>
		<category><![CDATA[C++ programming]]></category>
		<category><![CDATA[coding tutorial]]></category>
		<category><![CDATA[coding workflow]]></category>
		<category><![CDATA[compile code]]></category>
		<category><![CDATA[GNU Make]]></category>
		<category><![CDATA[Makefile tutorial]]></category>
		<category><![CDATA[programming tips]]></category>
		<category><![CDATA[software development]]></category>
		<category><![CDATA[software engineering]]></category>
		<category><![CDATA[streamline coding]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=113</guid>

					<description><![CDATA[<p>Master GNU Make! Simplify coding with Makefiles, manage C++, C, assembly builds, and cut compile times. Beginner-friendly guide!</p>
<p>The post <a href="https://www.NeuralLantern.com/master-gnu-makefiles-streamline-coding-builds-with-c-c-assembly/">Master GNU Makefiles: Streamline Coding Builds with C++, C &amp; Assembly</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe loading="lazy" title="Master GNU Makefiles: Streamline Coding Builds with C++, C &amp; Assembly" width="1380" height="776" src="https://www.youtube.com/embed/fvaoc5Ogp7Y?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">Tired of typing endless compile commands? Join me in this fun, hands-on guide to mastering GNU Make! We’ll walk through creating a Makefile to simplify your coding builds, covering C++, C, and assembly projects. Learn how to set up variables, define functions, manage dependencies, and organize build directories to cut compile times drastically. From practical tips like using clean targets to advanced tricks like dynamic variable assignments, this video has it all. Whether you’re a beginner or a seasoned coder, you’ll see how Makefiles can transform your workflow. Plus, I share a real story of turning a 1-hour build into 1 minute! Subscribe for more coding tutorials, and let me know how Makefiles change your game. Scan the QR code for more resources!</p>



<p class="wp-block-paragraph">Introduction to Make Files 00:00:00<br>What is a Build System 00:00:11<br>Problems with Manual Compilation 00:00:16<br>Using Scripts vs Build Systems 00:00:36<br>Benefits of Make Build System 00:00:56<br>Personal Experience with Build Times 00:01:15<br>Creating Sample Source Files 00:02:20<br>Installing Make Build System 00:04:56<br>Creating a Makefile 00:06:02<br>Defining Functions in Makefile 00:06:46<br>Calling Functions and Variables 00:07:13<br>Setting Up Compiler Variables 00:10:51<br>Dynamic vs Static Variable Assignment 00:11:56<br>Compiler and Linker Flags 00:12:44<br>Setting Up Build Paths 00:19:16<br>Printing Variables for Debugging 00:21:24<br>Understanding Targets in Make 00:25:10<br>Dependency Graph and Compilation 01:02:04<br>Managing Build Directory 01:03:11<br>Creating Binary Target 01:05:44<br>Handling Object Files 01:11:29<br>Running the Program 01:13:16<br>Clean Target for Cleanup 01:17:00<br>Advanced Build System Features 01:22:46<br>Git Ignore for Build Files 01:24:34<br>Conclusion and Call to Action 01:25:08</p>



<p class="wp-block-paragraph">Thanks for watching!</p>



<p class="wp-block-paragraph">Find us on other social media here:</p>



<ul class="wp-block-list">
<li>https://www.NeuralLantern.com/social</li>
</ul>



<p class="wp-block-paragraph">Please help support us!</p>



<ul class="wp-block-list">
<li>Subscribing + Sharing on Social Media</li>



<li>Leaving a comment or suggestion</li>



<li>Subscribing to our Blog</li>



<li>Watching the main &#8220;pinned&#8221; video of this channel for offers and extras</li>
</ul>



<p class="wp-block-paragraph">Hey there, let&#8217;s talk about using make files and the make build system.</p>



<p class="wp-block-paragraph">So what&#8217;s a build system? It&#8217;s basically just a program that helps you compile your program.</p>



<p class="wp-block-paragraph">In a previous video, I talked about the idea that it&#8217;s really cumbersome</p>



<p class="wp-block-paragraph">to type out build commands, you know, compiling commands, linking commands and so forth for your</p>



<p class="wp-block-paragraph">cumbersome and you&#8217;ll forget everything that you&#8217;re supposed to be doing. So the next upgrade</p>



<p class="wp-block-paragraph">from that was in a previous video I talked about let&#8217;s take all the commands and put them into a</p>



<p class="wp-block-paragraph">script so that we don&#8217;t really have to remember all the commands. We can just, you know, create</p>



<p class="wp-block-paragraph">a build script and then just kind of run it when we want a program to compile and link and execute.</p>



<p class="wp-block-paragraph">But then the thing is about a script is if you have a very, very large program,</p>



<p class="wp-block-paragraph">it might take a very long time to compile. So a build system will take care of that for you.</p>



<p class="wp-block-paragraph">care of that for you the build system that i&#8217;m about to show you the make build system</p>



<p class="wp-block-paragraph">it can carefully calculate which source code files you&#8217;ve actually changed since the last</p>



<p class="wp-block-paragraph">time that you built your program and it will only rebuild the source code files</p>



<p class="wp-block-paragraph">that actually need to be rebuilt you know into their corresponding object files and such</p>



<p class="wp-block-paragraph">so for as a personal example long time ago before i learned how to use build systems i had a giant</p>



<p class="wp-block-paragraph">And every single little change that I made, I would just have to wait for like an hour.</p>



<p class="wp-block-paragraph">Like I&#8217;d have to go get a sandwich or go do something else or work on a different project for an hour.</p>



<p class="wp-block-paragraph">Then come back and see if my changes actually affected anything.</p>



<p class="wp-block-paragraph">Somewhat quickly, I got irritated enough that I looked into build systems.</p>



<p class="wp-block-paragraph">And I realized that make, the one that I&#8217;m showing you today, is pretty easy.</p>



<p class="wp-block-paragraph">It goes really, really far, but it&#8217;s pretty easy to get started.</p>



<p class="wp-block-paragraph">And it drastically reduced my compile times.</p>



<p class="wp-block-paragraph">set up, you know, the make file and everything so that I let the build system do the building.</p>



<p class="wp-block-paragraph">My build only took like a minute. So I could do like a quick change and then just wait one minute</p>



<p class="wp-block-paragraph">to see the results and then another quick change and so forth. Okay. So if you look at the screen</p>



<p class="wp-block-paragraph">here, I&#8217;m sitting here on a blank desktop. Hopefully I&#8217;m recording everything. Am I?</p>



<p class="wp-block-paragraph">I&#8217;m sitting on a blank page here. So let me just make a couple of source code files. This is not</p>



<p class="wp-block-paragraph">This is not a tutorial for C++ or assembly or anything.</p>



<p class="wp-block-paragraph">I&#8217;m just going to copy paste a couple of sample programs in here real fast.</p>



<p class="wp-block-paragraph">So I&#8217;m creating a C++ source code file.</p>



<p class="wp-block-paragraph">I&#8217;m calling it first.cpp and it&#8217;s going to call functions from other source code files.</p>



<p class="wp-block-paragraph">This is going to be a hybrid program.</p>



<p class="wp-block-paragraph">Again, don&#8217;t really worry about this.</p>



<p class="wp-block-paragraph">My other videos already explained hybrid programs and so forth.</p>



<p class="wp-block-paragraph">I&#8217;m just going to show you how to use the make build system.</p>



<p class="wp-block-paragraph">the make build system.</p>



<p class="wp-block-paragraph">So let&#8217;s make another source code file called second dot C.</p>



<p class="wp-block-paragraph">And then another one called third dot ASM.</p>



<p class="wp-block-paragraph">So I&#8217;m linking a I&#8217;m linking three source.</p>



<p class="wp-block-paragraph">Whoops, that&#8217;s wrong.</p>



<p class="wp-block-paragraph">I&#8217;m linking three source code files.</p>



<p class="wp-block-paragraph">And they&#8217;re all in different languages just to prove to you that this will work</p>



<p class="wp-block-paragraph">with a hybrid program.</p>



<p class="wp-block-paragraph">And so you can kind of see I&#8217;ve got first, second and third.</p>



<p class="wp-block-paragraph">The first one is C++.</p>



<p class="wp-block-paragraph">The second one is just C.</p>



<p class="wp-block-paragraph">Third one is assembly.</p>



<p class="wp-block-paragraph">If I look at it real fast, get ready to pause the video.</p>



<p class="wp-block-paragraph">real fast get ready to pause the video then you can see that it&#8217;s C++ and if we look at the second</p>



<p class="wp-block-paragraph">one it&#8217;s just C and if we look at the third one it&#8217;s just a very simple assembly program and they</p>



<p class="wp-block-paragraph">just sort of say hello and that&#8217;s it okay so you know at this point in my other video I would have</p>



<p class="wp-block-paragraph">made a compile script I&#8217;d say nano compile and then I&#8217;d stick a bunch of compile commands inside</p>



<p class="wp-block-paragraph">of it let&#8217;s see do I even have that from last time let me see if I got it if I have it I&#8217;ll</p>



<p class="wp-block-paragraph">I got it if I have it I&#8217;ll just paste it real fast just to show you compile I don&#8217;t think I&#8217;ve</p>



<p class="wp-block-paragraph">got it although I do okay I&#8217;m just gonna paste it in here and it&#8217;s not the point of this video check</p>



<p class="wp-block-paragraph">my other video if you want to kind of understand everything that&#8217;s going on in here but it&#8217;s just</p>



<p class="wp-block-paragraph">a script so I&#8217;m gonna go compile clear and then list and then in the last video I just said let&#8217;s</p>



<p class="wp-block-paragraph">and it compiles everything and it links the binary and then I can run main which is my binary and then</p>



<p class="wp-block-paragraph">it just runs this program so it&#8217;s no problem it seems okay but again imagine that your program is</p>



<p class="wp-block-paragraph">huge many many lines of source code in every single file and many many many source code files</p>



<p class="wp-block-paragraph">and perhaps you&#8217;re pulling in libraries and shared objects and just like you know a bunch of other</p>



<p class="wp-block-paragraph">stuff your your your building could slow down drastically so I&#8217;m going to remove the compiler</p>



<p class="wp-block-paragraph">the compiler script and then I&#8217;m going to manually remove all the compiled</p>



<p class="wp-block-paragraph">object files. Got to be careful with this. Remove the binary. Okay. So now I&#8217;ve got</p>



<p class="wp-block-paragraph">that one, two, three. Okay. Now I&#8217;m ready to set up a make file. So I guess first</p>



<p class="wp-block-paragraph">you probably should have the make build system installed. If you&#8217;re if you&#8217;re</p>



<p class="wp-block-paragraph">learning about C++ and assembly you probably already do but just just so you</p>



<p class="wp-block-paragraph">know it&#8217;s a it&#8217;s gonna show up in Ubuntu as the build essentials package so</p>



<p class="wp-block-paragraph">So sudo apt install build essentials.</p>



<p class="wp-block-paragraph">I can&#8217;t remember if this is plural or not.</p>



<p class="wp-block-paragraph">It&#8217;s either build essentials or build essential.</p>



<p class="wp-block-paragraph">You can do an apt search or a DNF search depending on your system.</p>



<p class="wp-block-paragraph">We can do build essential and see what shows up.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to go to the top build essential.</p>



<p class="wp-block-paragraph">Okay, so it was singular, not plural.</p>



<p class="wp-block-paragraph">I have it installed already.</p>



<p class="wp-block-paragraph">Let&#8217;s see.</p>



<p class="wp-block-paragraph">If you just want to install make by itself, you can probably do apt search.</p>



<p class="wp-block-paragraph">search, just make and go up to the Ms.</p>



<p class="wp-block-paragraph">You can see right here.</p>



<p class="wp-block-paragraph">It&#8217;s just pseudo apt install.</p>



<p class="wp-block-paragraph">Make is all you really have to do to get the whole make build system.</p>



<p class="wp-block-paragraph">They&#8217;ve got a website, you know, search for Gnu make.</p>



<p class="wp-block-paragraph">I&#8217;m going to type it on the screen here.</p>



<p class="wp-block-paragraph">Gnu make search for that.</p>



<p class="wp-block-paragraph">You&#8217;ll get a nice website with a bunch</p>



<p class="wp-block-paragraph">of documentation and examples that go way beyond this video.</p>



<p class="wp-block-paragraph">But I&#8217;m just going to show you the basics so you can get started.</p>



<p class="wp-block-paragraph">So the first thing you should do is create a file called make file.</p>



<p class="wp-block-paragraph">create a file called make file. I think under lowercase m is supported but I usually do uppercase</p>



<p class="wp-block-paragraph">m which is obviously supported because I always do it and what you&#8217;re really going to do is you&#8217;re</p>



<p class="wp-block-paragraph">just going to create an empty file call it make file and then inside of the make file you&#8217;re just</p>



<p class="wp-block-paragraph">going to give make a bunch of commands and things that you want it to do and then later when you&#8217;re</p>



<p class="wp-block-paragraph">actually ready to compile you&#8217;ll just type make as a command and then give make an instruction and</p>



<p class="wp-block-paragraph">have lots of instructions and targets available inside of the make file for</p>



<p class="wp-block-paragraph">make to grab onto. Okay, so moving on. The first thing I want to show you is how to</p>



<p class="wp-block-paragraph">define a function in make. You probably won&#8217;t do this a lot, but for me I kind of</p>



<p class="wp-block-paragraph">like to print, you know, pretty messages and sort of like do repetitive tasks in a</p>



<p class="wp-block-paragraph">function. So when you want to define a function you just use the keyword define</p>



<p class="wp-block-paragraph">and then you name the function. So I&#8217;m gonna make a function called say which I</p>



<p class="wp-block-paragraph">see what it&#8217;s for I know it&#8217;s silly define say and then I&#8217;m going to tab here and then I&#8217;m going to</p>



<p class="wp-block-paragraph">tell it to print some information I&#8217;ll just put test info for now the thing about calling functions</p>



<p class="wp-block-paragraph">is you usually put a dollar sign and then an open parenthesis and then the name of the function and</p>



<p class="wp-block-paragraph">then after that arguments to the function so here you can see actually let me get line numbers up</p>



<p class="wp-block-paragraph">here on nano you can see online too I am calling a function called info it&#8217;s a built-in system</p>



<p class="wp-block-paragraph">it&#8217;s a built-in system function you don&#8217;t have to define it yourself and I&#8217;m</p>



<p class="wp-block-paragraph">telling it I want you to print some info to the screen and I want you to print</p>



<p class="wp-block-paragraph">test info to the screen and that&#8217;s it so in my make file I can just call that</p>



<p class="wp-block-paragraph">right away with call you know dollar sign parentheses and then the keyword</p>



<p class="wp-block-paragraph">call and then name the function that I want to call closing parentheses and</p>



<p class="wp-block-paragraph">then if the function takes arguments I put a comma and then just start</p>



<p class="wp-block-paragraph">providing the argument so I&#8217;ll just say hello what&#8217;s up actually this shouldn&#8217;t</p>



<p class="wp-block-paragraph">up. Actually, this shouldn&#8217;t take my arguments right now. We&#8217;ll upgrade it in a second. But</p>



<p class="wp-block-paragraph">so this is a very simple makefile. It doesn&#8217;t actually have any targets. It will just simply</p>



<p class="wp-block-paragraph">do things. This kind of stuff is useful. At the very top of your makefile later, we&#8217;re going to</p>



<p class="wp-block-paragraph">define like a bunch of variables. And sometimes it&#8217;s nice to print them out. So I just want to</p>



<p class="wp-block-paragraph">show you how to start printing so that maybe if your makefile isn&#8217;t working, you&#8217;ll realize that,</p>



<p class="wp-block-paragraph">oh, that variable is wrong because you printed everything when it started up. You don&#8217;t have to</p>



<p class="wp-block-paragraph">You don&#8217;t have to do it that way.</p>



<p class="wp-block-paragraph">I just like to.</p>



<p class="wp-block-paragraph">So how do you invoke the make file?</p>



<p class="wp-block-paragraph">We just literally type make.</p>



<p class="wp-block-paragraph">And because we named the make file, make file,</p>



<p class="wp-block-paragraph">the make program will automatically figure out</p>



<p class="wp-block-paragraph">where it is and go find it and load it.</p>



<p class="wp-block-paragraph">But you can specify the name of a make file</p>



<p class="wp-block-paragraph">if you really want to.</p>



<p class="wp-block-paragraph">I think it&#8217;s the dash F switch.</p>



<p class="wp-block-paragraph">Actually, let me look it up just to be sure.</p>



<p class="wp-block-paragraph">I&#8217;m gonna go man make and just go down a second here.</p>



<p class="wp-block-paragraph">Yeah.</p>



<p class="wp-block-paragraph">So this switch right here,</p>



<p class="wp-block-paragraph">here dash f and then specify the file name or file path or dash dash file and then specify the name</p>



<p class="wp-block-paragraph">or path that&#8217;s how you could use a non-standard make file but almost no one does that everyone</p>



<p class="wp-block-paragraph">just likes to to name it this way and then just type make so if i type make notice how the first</p>



<p class="wp-block-paragraph">thing it does is it says test info which is what i told it to do in that function which i called</p>



<p class="wp-block-paragraph">and then it says no targets gotta stop because we didn&#8217;t add any targets yet okay by the way if</p>



<p class="wp-block-paragraph">about what I&#8217;m even doing this for like compiling and whatever go see my other</p>



<p class="wp-block-paragraph">videos where we talk about compiling and linking and all that stuff this is just</p>



<p class="wp-block-paragraph">to make things a lot more easy and powerful so let&#8217;s upgrade this save</p>



<p class="wp-block-paragraph">function and I&#8217;m just gonna put some brackets and I&#8217;m gonna say my super cool</p>



<p class="wp-block-paragraph">make how about like builder I guess and then instead of test info I&#8217;m gonna put</p>



<p class="wp-block-paragraph">dollar sign one which basically is gonna tell this function you know when I call</p>



<p class="wp-block-paragraph">say, then the dollar sign one variable is going to show up as the first argument that I provided.</p>



<p class="wp-block-paragraph">So now when I call say, it should have hello, what&#8217;s up as the first argument that goes into</p>



<p class="wp-block-paragraph">the function. So that means it should print my super cool builder and then the message that I</p>



<p class="wp-block-paragraph">had it print. One more time, notice how it says my super cool builder. Hello, what&#8217;s up, I just like</p>



<p class="wp-block-paragraph">to do it this way, because then it&#8217;s easier for me to differentiate messages that the build system</p>



<p class="wp-block-paragraph">itself from the actual make file and messages that maybe the tools I&#8217;m calling on are giving like GCC or whatever</p>



<p class="wp-block-paragraph">So let&#8217;s edit this a little bit more</p>



<p class="wp-block-paragraph">The second thing I would like to do is well, maybe I&#8217;ll change this to just you know now running or something</p>



<p class="wp-block-paragraph">Now let&#8217;s set up some variables. I&#8217;m gonna do like a little thing here. I&#8217;m gonna say variables</p>



<p class="wp-block-paragraph">Put a bunch of comments in make files comments are just hashes</p>



<p class="wp-block-paragraph">So, you know, this, these lines right here don&#8217;t really do anything, 9, 10, 11.</p>



<p class="wp-block-paragraph">And I&#8217;m going to start setting up some variables for my compilers.</p>



<p class="wp-block-paragraph">So again, actually compiling is in a different video.</p>



<p class="wp-block-paragraph">We assume right now that you already know how to do it.</p>



<p class="wp-block-paragraph">So I&#8217;m going to say, let&#8217;s do some variables for compilers.</p>



<p class="wp-block-paragraph">You don&#8217;t have to do it this way, but the standard convention for naming a regular C</p>



<p class="wp-block-paragraph">compilers or GCC seems to be just CC as the variable name.</p>



<p class="wp-block-paragraph">So I&#8217;m saying a variable named CC is going to be equal to GCC.</p>



<p class="wp-block-paragraph">to be equal to GCC and then from this point forward every time I use the variable CC in my</p>



<p class="wp-block-paragraph">script in my makefile it&#8217;s actually going to be like typing GCC and you know if you don&#8217;t understand</p>



<p class="wp-block-paragraph">why you would use variables you probably need to learn how to code a little bit more but basically</p>



<p class="wp-block-paragraph">it makes everything more powerful instead of typing GCC everywhere and then maybe later if I</p>



<p class="wp-block-paragraph">want to change it I have to go change it in a million places now I can just change it in one</p>



<p class="wp-block-paragraph">place and so it&#8217;s more powerful let&#8217;s do the same thing for the C++ compiler I&#8217;m going to say G++</p>



<p class="wp-block-paragraph">compiler I&#8217;m gonna say G++ same thing for my Yasm assembler I&#8217;m gonna say</p>



<p class="wp-block-paragraph">we&#8217;re using Yasm also notice how when I assign variables I&#8217;m not just using an</p>



<p class="wp-block-paragraph">equality or an assignment operator I&#8217;m not just doing equals that is a little</p>



<p class="wp-block-paragraph">bit different of a way to assign you can do that but if you just put an</p>



<p class="wp-block-paragraph">assignment operator by itself just like the equal then if you later change</p>



<p class="wp-block-paragraph">depends on on the right side, like another variable, then it will update on the left</p>



<p class="wp-block-paragraph">side. So it&#8217;s like, it&#8217;s not really a permanent assignment. It&#8217;s more like a dynamic assignment.</p>



<p class="wp-block-paragraph">So, you know, if you want to make sure that the variable has a fixed value that doesn&#8217;t change,</p>



<p class="wp-block-paragraph">even if you start changing variables that it depends on, then use colon equal. I&#8217;ll just leave it at that for now.</p>



<p class="wp-block-paragraph">Not super important. You can also tab and, you know, kind of line things up and it&#8217;s no problem.</p>



<p class="wp-block-paragraph">just to make things look nicer.</p>



<p class="wp-block-paragraph">So now let&#8217;s set up some flags for C and C++ and YASM.</p>



<p class="wp-block-paragraph">So I&#8217;m going to create a variable called ccflags,</p>



<p class="wp-block-paragraph">do the same thing again where I do the colon assignment operator.</p>



<p class="wp-block-paragraph">I&#8217;m just going to give it some flags.</p>



<p class="wp-block-paragraph">I want it to show me all warnings,</p>



<p class="wp-block-paragraph">and I want it to be pedantic about its warnings,</p>



<p class="wp-block-paragraph">and I want it to generate debug symbols.</p>



<p class="wp-block-paragraph">build system we want to try to compile source code files into object files first</p>



<p class="wp-block-paragraph">and then at a different stage link the object files together we we don&#8217;t want</p>



<p class="wp-block-paragraph">to just compile everything in one fell swoop directly to a binary in one line</p>



<p class="wp-block-paragraph">because we wouldn&#8217;t really be leveraging the power of the build system in a</p>



<p class="wp-block-paragraph">moment I&#8217;m going to draw a diagram that tries to make this a little more clear</p>



<p class="wp-block-paragraph">for now I&#8217;m just typing up variables so just bear with me when I&#8217;m you know</p>



<p class="wp-block-paragraph">Cpp flags.</p>



<p class="wp-block-paragraph">So for C++, I&#8217;m actually going to reuse a variable here.</p>



<p class="wp-block-paragraph">I&#8217;m going to reuse the CC flags because all the flags</p>



<p class="wp-block-paragraph">above are fine for C++ as well as C.</p>



<p class="wp-block-paragraph">So that means like in my C++ compilation,</p>



<p class="wp-block-paragraph">I want all warnings and I want it to be pedantic and I want to generate debug</p>



<p class="wp-block-paragraph">symbols, but in C++, we&#8217;ll specify the C++ standard.</p>



<p class="wp-block-paragraph">So C++ 23.</p>



<p class="wp-block-paragraph">kind of already leveraging variables against other variables to save typing and make things a little</p>



<p class="wp-block-paragraph">bit more module. If I decided that all my C was not going to show warnings or was going to convert</p>



<p class="wp-block-paragraph">all warnings into errors or, you know, use a different flag or something, all I&#8217;d have to do</p>



<p class="wp-block-paragraph">is change it in one spot, line 20 and line 21 would automatically get updated. Also keep in mind</p>



<p class="wp-block-paragraph">because like I said before, we have this colon assignment operator here going on the right side.</p>



<p class="wp-block-paragraph">value of cc flags then it would be reflected if i didn&#8217;t use um the assignment operator you know</p>



<p class="wp-block-paragraph">what let&#8217;s let&#8217;s just do it let&#8217;s just do it real fast i&#8217;m going to say call say i&#8217;m going to say</p>



<p class="wp-block-paragraph">let&#8217;s let&#8217;s see cpp flags is and then i&#8217;m just going to print cpp flags you print variables kind</p>



<p class="wp-block-paragraph">of the same way that you call functions you just put a dollar sign and then surround the variable</p>



<p class="wp-block-paragraph">name in a set of parentheses and that&#8217;s pretty much it so i&#8217;m going to copy this line a couple</p>



<p class="wp-block-paragraph">And in between CPP flags, actually let&#8217;s do CC flags.</p>



<p class="wp-block-paragraph">We&#8217;ll assign CC flags to something.</p>



<p class="wp-block-paragraph">I&#8217;ll say hello test.</p>



<p class="wp-block-paragraph">And right now the way CPP flags is written, the assignment kind of sticks.</p>



<p class="wp-block-paragraph">It&#8217;s like permanent fixed.</p>



<p class="wp-block-paragraph">It doesn&#8217;t dynamically depend on CC flags.</p>



<p class="wp-block-paragraph">So we should see two instances of the exact same message.</p>



<p class="wp-block-paragraph">Let me open up another window here because I want to keep that editor open.</p>



<p class="wp-block-paragraph">because I don&#8217;t I want to keep that editor open so we&#8217;ll do a make and notice how when it prints</p>



<p class="wp-block-paragraph">the CPP flags they&#8217;re the same it&#8217;s the same both times even though I changed CC flags in between</p>



<p class="wp-block-paragraph">those two messages on the other hand if I don&#8217;t put that to colon if I just put a sign then now</p>



<p class="wp-block-paragraph">it is dynamic notice how the second message uses the modified version of cc flags so keep that in</p>



<p class="wp-block-paragraph">So keep that in mind if you want a variable to be able to change anytime you depend on</p>



<p class="wp-block-paragraph">anytime a dependent variable that it depends on changes you&#8217;ll assign one way and if you</p>



<p class="wp-block-paragraph">don&#8217;t want it to change you&#8217;ll assign it another way okay so that&#8217;s enough of that I&#8217;m going to</p>



<p class="wp-block-paragraph">take away that message and I&#8217;m going to change this back to non-dynamic okay then we&#8217;ll do the</p>



<p class="wp-block-paragraph">same thing for assembly assembly flags this is going to be the Yasm compiler I&#8217;m going to tell</p>



<p class="wp-block-paragraph">I&#8217;m going to tell it that I want ELF 64.</p>



<p class="wp-block-paragraph">I want a 64 bit executable.</p>



<p class="wp-block-paragraph">I want to dwarf to debug symbols.</p>



<p class="wp-block-paragraph">I think in Yasm you have to specify the type of symbol.</p>



<p class="wp-block-paragraph">I think I can&#8217;t remember if you actually need to.</p>



<p class="wp-block-paragraph">So you could try just, you know, dash G if you want.</p>



<p class="wp-block-paragraph">It may or may not work.</p>



<p class="wp-block-paragraph">But I always just like to specify at least for assembly.</p>



<p class="wp-block-paragraph">So then let&#8217;s do some linker flags.</p>



<p class="wp-block-paragraph">Okay, so link flags, you know, what is the linking stage?</p>



<p class="wp-block-paragraph">What&#8217;s going to happen in a hybrid program?</p>



<p class="wp-block-paragraph">You know, for me, it&#8217;s just going to be the G plus plus GCC linker.</p>



<p class="wp-block-paragraph">So that means I&#8217;m going to do all the CPP flags because I want wall and pedantic and</p>



<p class="wp-block-paragraph">debug symbols and I want the C plus plus standard set and all that stuff.</p>



<p class="wp-block-paragraph">Whatever you want to do is fine.</p>



<p class="wp-block-paragraph">And then I want to just specify.</p>



<p class="wp-block-paragraph">I don&#8217;t think you have to do this on modern systems, but I&#8217;m going to specify I want to link a 64-bit executable</p>



<p class="wp-block-paragraph">And then I have to specify no pi</p>



<p class="wp-block-paragraph">Which I think is kind of an Ubuntu thing your program probably won&#8217;t run if you don&#8217;t do this</p>



<p class="wp-block-paragraph">So just trust me for now put no pi in the linking stage and then we&#8217;ll do another flag called no exec stack</p>



<p class="wp-block-paragraph">Which is also a somewhat new thing which prevents</p>



<p class="wp-block-paragraph">stack which means you might be less hackable not sure if it&#8217;s how safe it really is but you know</p>



<p class="wp-block-paragraph">probably improves the safety a little bit uh let&#8217;s see at the last minute okay so now uh</p>



<p class="wp-block-paragraph">now that i&#8217;ve set up the link flags uh i need to like add on the dash c flag for the actual</p>



<p class="wp-block-paragraph">compiler flags because uh you know if if you know this from my previous videos if you&#8217;re going to</p>



<p class="wp-block-paragraph">compile to an object file and not directly link everything right away you need to add the dash c</p>



<p class="wp-block-paragraph">away you need to add the dash c flag to let the compiler know oh i just want to compile to an</p>



<p class="wp-block-paragraph">object file and then later i&#8217;ll come along and link so i&#8217;m going to go cpp flags is equal to</p>



<p class="wp-block-paragraph">and i&#8217;m going to say equal to itself and then just add a dash c at the end of it and then we&#8217;ll do</p>



<p class="wp-block-paragraph">cc flags and then it&#8217;s going to equal to itself with just a dash c at the end of it so</p>



<p class="wp-block-paragraph">I had CPP flags on line 21 equal to just this basic thing.</p>



<p class="wp-block-paragraph">And then I reused CPP flags for the link flags,</p>



<p class="wp-block-paragraph">which means if the link flags didn&#8217;t use that colon,</p>



<p class="wp-block-paragraph">I would basically have ruined the link flags variable by the time I went down</p>



<p class="wp-block-paragraph">here and changed it. So you don&#8217;t have to organize your make file this way.</p>



<p class="wp-block-paragraph">You can actually hard code a lot more stuff into the variables.</p>



<p class="wp-block-paragraph">I just like to try to be more dynamic. It&#8217;s more fun.</p>



<p class="wp-block-paragraph">up all the basic variables for the compiler let&#8217;s set up some variables for paths so i&#8217;m</p>



<p class="wp-block-paragraph">going to set up paths here so what do i mean by paths you know this is a build system it&#8217;s got to</p>



<p class="wp-block-paragraph">know where things are right so for starters you probably want to name your binary you know the</p>



<p class="wp-block-paragraph">executable file so i&#8217;m just going to make mine main you can make anything you want like my program or</p>



<p class="wp-block-paragraph">whatever but you know for mine it&#8217;s going to be main and then i&#8217;m going to set up another variable</p>



<p class="wp-block-paragraph">going to set up another variable that depends on it so I&#8217;m going to say the actual binary path is</p>



<p class="wp-block-paragraph">just going to be you know this main meaning the current directory and main also you know most it</p>



<p class="wp-block-paragraph">seems like most make files have it set up so that all of the intermediate files like the the object</p>



<p class="wp-block-paragraph">files and the binary they get built in the current source directory you know like the root of the</p>



<p class="wp-block-paragraph">Sometimes also I like to just make a build directory.</p>



<p class="wp-block-paragraph">So it&#8217;s really, really easy to just kind of clean everything out.</p>



<p class="wp-block-paragraph">You just delete the build directory and you don&#8217;t have to worry about the repository getting</p>



<p class="wp-block-paragraph">super cluttered with object files in the meantime.</p>



<p class="wp-block-paragraph">So I&#8217;m going to name a build directory here.</p>



<p class="wp-block-paragraph">I&#8217;m going to say build directory name is build.</p>



<p class="wp-block-paragraph">And then so you can imagine there&#8217;s going to be a folder here now named build that shows</p>



<p class="wp-block-paragraph">up whenever, well, I&#8217;m going to add more targets later when I actually start building.</p>



<p class="wp-block-paragraph">when I actually start building, we&#8217;re still just naming things.</p>



<p class="wp-block-paragraph">So then I&#8217;m going to name the actual build directory as the current directory slash and then build dir name.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">So that means the bin shouldn&#8217;t just be in the current directory.</p>



<p class="wp-block-paragraph">It should be in the build dir and then a slash.</p>



<p class="wp-block-paragraph">And then instead of typing main, actually, I should probably reuse that variable.</p>



<p class="wp-block-paragraph">So let&#8217;s do bin name.</p>



<p class="wp-block-paragraph">And again, reusing variables is really, really good because it just saves you work.</p>



<p class="wp-block-paragraph">I can change things in less places when I leverage variables more.</p>



<p class="wp-block-paragraph">If I had the word main written down all over the program, I&#8217;d have to change that in every</p>



<p class="wp-block-paragraph">single spot of the make file if I wanted to change main to something else.</p>



<p class="wp-block-paragraph">But in this case, I only have to change it in one spot.</p>



<p class="wp-block-paragraph">Okay, so now maybe it&#8217;s probably a good idea at this point to start printing out what we&#8217;ve</p>



<p class="wp-block-paragraph">done.</p>



<p class="wp-block-paragraph">So I&#8217;m going to do a bunch of, you know, calls to print things.</p>



<p class="wp-block-paragraph">you know calls to print things print everything out just for double checking ourselves</p>



<p class="wp-block-paragraph">okay how can i do that i&#8217;m going to do that with a call uh the uh say you could also just do uh info</p>



<p class="wp-block-paragraph">and then you know something like that like we did up above in the save function if you want a less</p>



<p class="wp-block-paragraph">fancier build system but i like doing it this way so i&#8217;m going to say what um let&#8217;s do cc uh</p>



<p class="wp-block-paragraph">CC and I&#8217;ll just put maybe like a quality operator or something and then</p>



<p class="wp-block-paragraph">I&#8217;ll just print out what I put for CC and I&#8217;ll just start duplicating this</p>



<p class="wp-block-paragraph">line a few times and I&#8217;ll say I&#8217;ll just print out everything that I added as a</p>



<p class="wp-block-paragraph">variable CPP and then ASM type ASM and this just kind of you know it just kind</p>



<p class="wp-block-paragraph">typed something in incorrectly might take me a while to figure that out but if</p>



<p class="wp-block-paragraph">I print it all out at the beginning of the of the make file running that I can</p>



<p class="wp-block-paragraph">just visually inspect what the variables actually contain so let&#8217;s do CPP flags</p>



<p class="wp-block-paragraph">and then we&#8217;ll do CC flags</p>



<p class="wp-block-paragraph">SM flags.</p>



<p class="wp-block-paragraph">And then we&#8217;ll do one more.</p>



<p class="wp-block-paragraph">It&#8217;s going to be probably, oh, link flags.</p>



<p class="wp-block-paragraph">There we go.</p>



<p class="wp-block-paragraph">So link flags.</p>



<p class="wp-block-paragraph">Bringing out a lot of stuff here.</p>



<p class="wp-block-paragraph">Then I can print the directories, I guess.</p>



<p class="wp-block-paragraph">So maybe I&#8217;ll duplicate this a few more times.</p>



<p class="wp-block-paragraph">I want to do builder.</p>



<p class="wp-block-paragraph">The build directory, just so I know where it is.</p>



<p class="wp-block-paragraph">and I can verify that it&#8217;s like a real path.</p>



<p class="wp-block-paragraph">Builder, maybe I&#8217;ll duplicate this one more time</p>



<p class="wp-block-paragraph">so that I can see the absolute path</p>



<p class="wp-block-paragraph">to the build directory.</p>



<p class="wp-block-paragraph">Just for my own information,</p>



<p class="wp-block-paragraph">because sometimes if you get it wrong,</p>



<p class="wp-block-paragraph">this is another way to kind of see what&#8217;s going on.</p>



<p class="wp-block-paragraph">So there&#8217;s a function in make that&#8217;s built in.</p>



<p class="wp-block-paragraph">You pretty much just say dollar</p>



<p class="wp-block-paragraph">and the name of the function is abspath.</p>



<p class="wp-block-paragraph">path and whatever you put inside of it it&#8217;ll try to give you the absolute path of that thing</p>



<p class="wp-block-paragraph">so i&#8217;m just telling it now that i want to print the absolute path of the build directory</p>



<p class="wp-block-paragraph">by the way um you probably don&#8217;t want to convert all of your variables to absolute paths because</p>



<p class="wp-block-paragraph">make has a huge problem with spaces in paths and file names so keep it relative unless you&#8217;re just</p>



<p class="wp-block-paragraph">going to print something um you&#8217;ll find out the hard way i mean feel free to try it and prove to</p>



<p class="wp-block-paragraph">yourself it&#8217;s not a good idea um but i found it the hard way many times because i kept forgetting</p>



<p class="wp-block-paragraph">I kept forgetting. So then we&#8217;ll just do the binary, I guess. Okay. Yeah. We&#8217;ll do one more</p>



<p class="wp-block-paragraph">for the binary. It&#8217;s going to go there and maybe I&#8217;ll duplicate this so that I can say</p>



<p class="wp-block-paragraph">what the absolute path is. Okay. Abs path. And then if I screw this up, I&#8217;ll just look up the</p>



<p class="wp-block-paragraph">I&#8217;m going to do clear and make so I can just see what it&#8217;s going to print.</p>



<p class="wp-block-paragraph">And let me just double check here.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">So everything looks good there.</p>



<p class="wp-block-paragraph">Looks good there.</p>



<p class="wp-block-paragraph">Looks pretty good.</p>



<p class="wp-block-paragraph">Absolute path to the builder is my stuff.</p>



<p class="wp-block-paragraph">All right.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">So seems good so far.</p>



<p class="wp-block-paragraph">I&#8217;m just going to leave that in there because it&#8217;ll be easy to double check it.</p>



<p class="wp-block-paragraph">And now we&#8217;re going to do targets.</p>



<p class="wp-block-paragraph">So what is the target in the make build system?</p>



<p class="wp-block-paragraph">in the make build system a target is just something that you might want to create or or</p>



<p class="wp-block-paragraph">or build or compile or something targets are not only for uh building uh executables or object</p>



<p class="wp-block-paragraph">files or you know something that you make targets sometimes can just be called they&#8217;re called phony</p>



<p class="wp-block-paragraph">targets but you can just call a target and it will execute a bunch of commands within that target</p>



<p class="wp-block-paragraph">even though it&#8217;s not building something specific that is needed so you can use make files to do a</p>



<p class="wp-block-paragraph">really powerful stuff. Let me show you first off, we&#8217;ll do a we&#8217;ll do a target. I&#8217;ve already</p>



<p class="wp-block-paragraph">prepared something up here. I&#8217;m just gonna I&#8217;m just gonna copy paste it here because it&#8217;s going</p>



<p class="wp-block-paragraph">to take a long time to type if I don&#8217;t. So here&#8217;s a target. An example of a target is okay, I&#8217;m going</p>



<p class="wp-block-paragraph">to name the target the target menu and I&#8217;m gonna put a colon. So now later I can type make menu</p>



<p class="wp-block-paragraph">and what will happen is it&#8217;ll execute all those commands that are listed below. Each command</p>



<p class="wp-block-paragraph">is really just going to be a shell command.</p>



<p class="wp-block-paragraph">You have to use tab to indent for the command itself.</p>



<p class="wp-block-paragraph">Notice how I have a bunch of echo statements</p>



<p class="wp-block-paragraph">and then I&#8217;m just like printing stuff, right?</p>



<p class="wp-block-paragraph">So this whole target, it doesn&#8217;t actually build anything,</p>



<p class="wp-block-paragraph">but it will print a menu to the screen for me,</p>



<p class="wp-block-paragraph">which is pretty convenient.</p>



<p class="wp-block-paragraph">When you&#8217;re not actually building something,</p>



<p class="wp-block-paragraph">like you&#8217;re not building the executable</p>



<p class="wp-block-paragraph">that the target doesn&#8217;t name an executable,</p>



<p class="wp-block-paragraph">then it&#8217;s called a phony target.</p>



<p class="wp-block-paragraph">And you want to name it as a phony target</p>



<p class="wp-block-paragraph">phony target with this line 67 down here because if you don&#8217;t the build system might actually</p>



<p class="wp-block-paragraph">eventually end up getting confused between a fake target and something that might be sitting on your</p>



<p class="wp-block-paragraph">file system like if i accidentally put a file named menu on my file system at the root of my</p>



<p class="wp-block-paragraph">repository then make might get confused and think well i see the file so therefore i don&#8217;t need to</p>



<p class="wp-block-paragraph">build it and then the menu will never show up again so this way i&#8217;m saying this is a phony target</p>



<p class="wp-block-paragraph">at the file system it&#8217;ll just always execute that target for me so this is the basics of a target</p>



<p class="wp-block-paragraph">you just name a target put a colon and then every line under that is a shell command that you wanted</p>



<p class="wp-block-paragraph">to execute so let me just show you that real fast we save to be sure so we&#8217;re going to do clear and</p>



<p class="wp-block-paragraph">actually the absolute paths are starting to bother me let me get rid of them right now</p>



<p class="wp-block-paragraph">head before I made this video. Okay, and we can just sort of trim the fat a little bit. So I&#8217;m</p>



<p class="wp-block-paragraph">going to do clear and make. And notice how the menu target just ran by itself already.</p>



<p class="wp-block-paragraph">The convenient thing about make files is the first target that shows up is going to be known</p>



<p class="wp-block-paragraph">as the default target and it will just get executed automatically if you don&#8217;t specify</p>



<p class="wp-block-paragraph">what to execute. So notice how I just typed make by itself and I didn&#8217;t actually specify a target.</p>



<p class="wp-block-paragraph">I could specify make menu and the same exact thing happens.</p>



<p class="wp-block-paragraph">Notice how I said make menu, the menu shows up again.</p>



<p class="wp-block-paragraph">But if you don&#8217;t specify anything,</p>



<p class="wp-block-paragraph">then it&#8217;ll always execute the first found target.</p>



<p class="wp-block-paragraph">And just to prove that to you right here,</p>



<p class="wp-block-paragraph">I&#8217;ll do maybe I&#8217;ll do like a different target</p>



<p class="wp-block-paragraph">and I&#8217;ll just call it hello.</p>



<p class="wp-block-paragraph">And I&#8217;ll just have it echo hello.</p>



<p class="wp-block-paragraph">So now if we just execute make with no arguments,</p>



<p class="wp-block-paragraph">notice how it just prints hello.</p>



<p class="wp-block-paragraph">if I want the menu again, I got to go make menu.</p>



<p class="wp-block-paragraph">Right? Okay. So I&#8217;m going to, I&#8217;m going to set the menu back to the default target.</p>



<p class="wp-block-paragraph">Another thing that sometimes people do is they&#8217;ll just make a target called default.</p>



<p class="wp-block-paragraph">I guess I&#8217;ll do that here, make a target called default. And they&#8217;ll say that the</p>



<p class="wp-block-paragraph">default target depends on whatever they want to actually run. And you don&#8217;t even need to</p>



<p class="wp-block-paragraph">call it default. You can call it hello or anything that you want. So, you know,</p>



<p class="wp-block-paragraph">put to lead default just so you know that this is not a standard system name that&#8217;s expected so</p>



<p class="wp-block-paragraph">the default target it&#8217;s just the name of the target then a colon and instead of putting shell</p>



<p class="wp-block-paragraph">commands underneath i could put dependencies on the right so now i&#8217;m saying that the default target</p>



<p class="wp-block-paragraph">depends on the menu target which means in the make build system first what it&#8217;s going to do is it&#8217;s</p>



<p class="wp-block-paragraph">going to go check to make sure that main or sorry menu is satisfied because menu is actually a fake</p>



<p class="wp-block-paragraph">Because menu is actually a fake, you know, a phony target, it&#8217;s always going to get executed.</p>



<p class="wp-block-paragraph">And then when it&#8217;s finished and laDefault realizes, okay, all of my dependencies are satisfied now,</p>



<p class="wp-block-paragraph">then laDefault is going to execute and it&#8217;s actually going to end up doing nothing.</p>



<p class="wp-block-paragraph">I mean, we could put some commands under here if we want.</p>



<p class="wp-block-paragraph">I&#8217;ll put the word nothing.</p>



<p class="wp-block-paragraph">And just to prove to you that menu will get executed first because it&#8217;s a dependency of laDefault.</p>



<p class="wp-block-paragraph">And then finally laDefault will execute its commands and print the word nothing.</p>



<p class="wp-block-paragraph">execute its commands and print the word nothing.</p>



<p class="wp-block-paragraph">Let&#8217;s do that and then I&#8217;ll erase the echo command there.</p>



<p class="wp-block-paragraph">So we&#8217;ll do clear and make.</p>



<p class="wp-block-paragraph">Notice how the menu got printed first</p>



<p class="wp-block-paragraph">because it was a dependency of the default</p>



<p class="wp-block-paragraph">and the default is the default target.</p>



<p class="wp-block-paragraph">And then after the dependencies were satisfied,</p>



<p class="wp-block-paragraph">then the default did its thing and printed nothing.</p>



<p class="wp-block-paragraph">But so let&#8217;s get rid of that.</p>



<p class="wp-block-paragraph">And now it&#8217;s just like when you do make with no arguments,</p>



<p class="wp-block-paragraph">then the menu gets printed.</p>



<p class="wp-block-paragraph">printed. Okay, so what else can I talk about real fast here? Let&#8217;s talk about</p>



<p class="wp-block-paragraph">silent commands. I&#8217;ll put a little comment menu. Let&#8217;s talk about silent</p>



<p class="wp-block-paragraph">commands. You see all these at symbols here? There are a bunch of symbols that</p>



<p class="wp-block-paragraph">you can use throughout a make file. I&#8217;m going to show you just this and a couple</p>



<p class="wp-block-paragraph">other ones, but basically this means don&#8217;t print the command you&#8217;re about to</p>



<p class="wp-block-paragraph">execute, just execute it. So let me show you an example real fast of what I&#8217;m</p>



<p class="wp-block-paragraph">what I&#8217;m talking about.</p>



<p class="wp-block-paragraph">Targets to show silence and non-silent commands,</p>



<p class="wp-block-paragraph">or a suppressed command, whatever you wanna call it.</p>



<p class="wp-block-paragraph">Basically not printing the command,</p>



<p class="wp-block-paragraph">just executing the command.</p>



<p class="wp-block-paragraph">So I&#8217;m gonna name a target silent commands,</p>



<p class="wp-block-paragraph">and it&#8217;s not gonna depend on anything.</p>



<p class="wp-block-paragraph">So that&#8217;s why I&#8217;m gonna hit enter here,</p>



<p class="wp-block-paragraph">just like with menu and unlike the default.</p>



<p class="wp-block-paragraph">So then I wanna do tab to enter a command</p>



<p class="wp-block-paragraph">to enter a command and the echo command is going to say hello this is a silent command or a</p>



<p class="wp-block-paragraph">suppressed command then i&#8217;m going to do basically the same thing again but i&#8217;m not going to put the</p>



<p class="wp-block-paragraph">at symbol in front i&#8217;m going to say hello this is a non-silent command so what we should see is that</p>



<p class="wp-block-paragraph">if we exit the silent commands target we should see first this message gets printed on line 75</p>



<p class="wp-block-paragraph">and then second we see the full command including the echo statement that shows up on line 76 and</p>



<p class="wp-block-paragraph">on line 76 and then third we should just see the message hello this is a non-silent command</p>



<p class="wp-block-paragraph">let me oh and then if it&#8217;s a phony target meaning it&#8217;s not an actual file on the file system</p>



<p class="wp-block-paragraph">that you expect to be built we have to do phony and phony is actually a target notice how i&#8217;m</p>



<p class="wp-block-paragraph">saying dot phony colon indicating that that it&#8217;s a target and we&#8217;ll just say that it depends on</p>



<p class="wp-block-paragraph">and we&#8217;ll just name the command that is also a phony or the target that&#8217;s also a phony</p>



<p class="wp-block-paragraph">you can specify all of the phony targets in one line if you really want to but for me that kind</p>



<p class="wp-block-paragraph">of feels messy and you&#8217;re allowed to like add add add dependencies so notice on line 70 i&#8217;m adding</p>



<p class="wp-block-paragraph">menu as a phony target and then on line 77 i&#8217;m adding silent commands as a phony target</p>



<p class="wp-block-paragraph">the way you do it is up to you but i like to do it this way so i&#8217;m going to do silent commands</p>



<p class="wp-block-paragraph">and then I&#8217;m going to do make silent commands.</p>



<p class="wp-block-paragraph">So now we&#8217;re actually going to execute the silent commands target</p>



<p class="wp-block-paragraph">so we wouldn&#8217;t see a menu.</p>



<p class="wp-block-paragraph">And then we&#8217;ll see an example of the silent commands.</p>



<p class="wp-block-paragraph">Notice how the first one that says,</p>



<p class="wp-block-paragraph">hello, this is a silent command.</p>



<p class="wp-block-paragraph">The actual echo command is nowhere to be found</p>



<p class="wp-block-paragraph">because that whole line was muted</p>



<p class="wp-block-paragraph">and only the output of executing the command gets shown to you.</p>



<p class="wp-block-paragraph">But for the second one,</p>



<p class="wp-block-paragraph">remember we did not put the at symbol on the second command.</p>



<p class="wp-block-paragraph">So the whole entire command gets printed.</p>



<p class="wp-block-paragraph">the whole entire command gets printed echo and then quote this is a non-silent command and then</p>



<p class="wp-block-paragraph">that command gets executed and here&#8217;s the result it&#8217;s the same string except just without the echo</p>



<p class="wp-block-paragraph">so you know this line right here is this is the command that we&#8217;re about to execute whoops</p>



<p class="wp-block-paragraph">this is the command we&#8217;re about to execute and then the last line is this is the result of</p>



<p class="wp-block-paragraph">executing that command why would you want to print your commands kind of useful sometimes to see the</p>



<p class="wp-block-paragraph">compiler statements that show up there have been a few times or more than a few times in my life</p>



<p class="wp-block-paragraph">times in my life where I was running a make file and just kind of watching it and it was printing</p>



<p class="wp-block-paragraph">out all the commands that it was executing and then I realized oh my god that&#8217;s wrong because</p>



<p class="wp-block-paragraph">it was printing and I was able to fix that so you know you don&#8217;t have to print your commands but</p>



<p class="wp-block-paragraph">you probably want to so let&#8217;s see what else can we do okay so here&#8217;s another thing that I want to</p>



<p class="wp-block-paragraph">show you how to ignore failures so sometimes if you&#8217;re compiling your source code won&#8217;t compile</p>



<p class="wp-block-paragraph">So then that means the compilation command failed.</p>



<p class="wp-block-paragraph">Or if you want to do any command in general,</p>



<p class="wp-block-paragraph">and for some reason it returns false or it fails,</p>



<p class="wp-block-paragraph">then that&#8217;s considered a failed command.</p>



<p class="wp-block-paragraph">The make build system will stop execution of any target</p>



<p class="wp-block-paragraph">as soon as it encounters a failure.</p>



<p class="wp-block-paragraph">It&#8217;s kind of a good thing.</p>



<p class="wp-block-paragraph">What if you had a huge complicated target,</p>



<p class="wp-block-paragraph">which you can do it this way.</p>



<p class="wp-block-paragraph">I&#8217;ve done it this way before.</p>



<p class="wp-block-paragraph">What if you had a huge complicated target,</p>



<p class="wp-block-paragraph">which not only builds everything,</p>



<p class="wp-block-paragraph">but then also tries to deploy it to your remote server?</p>



<p class="wp-block-paragraph">deploy it to your remote server.</p>



<p class="wp-block-paragraph">Well, if your program fails to build, you probably don&#8217;t want the deployment part to</p>



<p class="wp-block-paragraph">execute.</p>



<p class="wp-block-paragraph">So you would hope that it would stop as soon as something failed to compile.</p>



<p class="wp-block-paragraph">Right.</p>



<p class="wp-block-paragraph">So we should try to know the difference between failed commands stopping the make build system</p>



<p class="wp-block-paragraph">and failed commands being ignored by the build system and just continuing.</p>



<p class="wp-block-paragraph">So we can do it both ways.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to do a little comment here.</p>



<p class="wp-block-paragraph">or ignoring failures and then i&#8217;m going to do ignore failures so that&#8217;s a target no dependencies</p>



<p class="wp-block-paragraph">and i&#8217;m just going to do false false twice in bash if you just you know do a false</p>



<p class="wp-block-paragraph">then it will be interpreted as a failure um so you know if i put true here it will be interpreted</p>



<p class="wp-block-paragraph">as true and this is not necessarily a make file thing this is a bash thing just like the command</p>



<p class="wp-block-paragraph">just like the command line. Let me show you real fast just just to prove it. I&#8217;m gonna prove it to</p>



<p class="wp-block-paragraph">you. Okay, so hopefully you remember if you can do echo dollar sign question, it&#8217;ll tell you the</p>



<p class="wp-block-paragraph">return code of the last command that you executed. So if I type echo hello, and then as another</p>



<p class="wp-block-paragraph">command, I echo the return code of the previous command. Now it&#8217;s going to basically tell me</p>



<p class="wp-block-paragraph">echo and then it&#8217;s going to tell me whether or not echo succeeded. You see a zero indicating</p>



<p class="wp-block-paragraph">succeeded it would be really weird if it didn&#8217;t succeed but you know whatever now i can modify</p>



<p class="wp-block-paragraph">this command just to type in some random stuff like what if i type in this notice how the second</p>



<p class="wp-block-paragraph">part the echo return code part echoes a 127 anything but a zero is considered a failure</p>



<p class="wp-block-paragraph">usually so it&#8217;s telling me 127 and that&#8217;s sometimes a standard code meaning something</p>



<p class="wp-block-paragraph">wasn&#8217;t found i could also just do true and that should give me a zero because you know in bash it</p>



<p class="wp-block-paragraph">bash it understands boolean so it&#8217;s like true success that&#8217;s a return code of zero it&#8217;s weird</p>



<p class="wp-block-paragraph">but that&#8217;s what it is if i return if i execute false then the return code should at least not</p>



<p class="wp-block-paragraph">be zero it&#8217;s probably going to be a one yeah there we go so just letting you know if we just</p>



<p class="wp-block-paragraph">execute the statement false by itself or true by itself then that&#8217;s telling us</p>



<p class="wp-block-paragraph">um that&#8217;s sort of like simulating a failed compile command or something i guess we could put</p>



<p class="wp-block-paragraph">commands in there if we wanted to but i don&#8217;t really want to run the compiler just for this</p>



<p class="wp-block-paragraph">in the compiler just for this so then I&#8217;m gonna do echo this echo statement</p>



<p class="wp-block-paragraph">should be reached as previous errors which I&#8217;m using false to represent should</p>



<p class="wp-block-paragraph">be ignored so now why how do I know that we&#8217;re gonna ignore the errors because I</p>



<p class="wp-block-paragraph">put the little minus in front of the false notice how before it was either an</p>



<p class="wp-block-paragraph">at symbol or nothing at the beginning of a command remember the at symbol does</p>



<p class="wp-block-paragraph">Remember the at symbol does suppression.</p>



<p class="wp-block-paragraph">The minus symbol says try to run this command,</p>



<p class="wp-block-paragraph">but if it fails, ignore it,</p>



<p class="wp-block-paragraph">continue with the recipe for that build target.</p>



<p class="wp-block-paragraph">You know, recipe meaning all of the commands</p>



<p class="wp-block-paragraph">that you want it to execute.</p>



<p class="wp-block-paragraph">So that means the ignore failures target</p>



<p class="wp-block-paragraph">should actually fail twice and then make it to line 84</p>



<p class="wp-block-paragraph">where it just prints that message.</p>



<p class="wp-block-paragraph">Then we&#8217;ll do, well, we&#8217;ll mark this as a phony target.</p>



<p class="wp-block-paragraph">practice to try to mark your phony targets i&#8217;ve i&#8217;ve not done that in the past and eventually</p>



<p class="wp-block-paragraph">regretted it a few times so then i&#8217;m going to do stop on failures is another target and we&#8217;re going</p>



<p class="wp-block-paragraph">to do false whoops no minus because we actually want to stop on failure false and then we&#8217;ll do</p>



<p class="wp-block-paragraph">another echo and we&#8217;ll say this echo statement should never be reached as previous errors</p>



<p class="wp-block-paragraph">false should cause build build termination okay I&#8217;m kind of verbose but I hope this explains it</p>



<p class="wp-block-paragraph">we&#8217;ll name this as a phony target too phony you&#8217;re a phony failures okay so we can run both these</p>



<p class="wp-block-paragraph">maybe I&#8217;ll put a comment here just to show you it&#8217;s two separate things I kind of like doing that</p>



<p class="wp-block-paragraph">we can run ignore failures and then we can run stop on failures separately to see what happens</p>



<p class="wp-block-paragraph">Let me get rid of this terminal window.</p>



<p class="wp-block-paragraph">Okay, so I&#8217;m going to do clear and, what was it?</p>



<p class="wp-block-paragraph">Ignore failures and then stop on failures.</p>



<p class="wp-block-paragraph">So ignore failures, notice how it prints false</p>



<p class="wp-block-paragraph">because I forgot to put an at symbol in front of it.</p>



<p class="wp-block-paragraph">And then the make system itself says,</p>



<p class="wp-block-paragraph">hey, error, that command failed, error one.</p>



<p class="wp-block-paragraph">Remember before we had the return code one</p>



<p class="wp-block-paragraph">when we just typed in false.</p>



<p class="wp-block-paragraph">me that it received return code one from trying to execute false inside of bash so it detected</p>



<p class="wp-block-paragraph">that a failure occurred so these two lines go together then the same thing again because i have</p>



<p class="wp-block-paragraph">two false statements in there and then the last statement says this echo statement should be</p>



<p class="wp-block-paragraph">reached as previous errors should be ignored because we use the minus symbol i&#8217;m having a</p>



<p class="wp-block-paragraph">hard time selecting text here i gotta i gotta go home and practice my text selection actually wait</p>



<p class="wp-block-paragraph">So notice how, you know, the minus symbol right there says, let&#8217;s ignore.</p>



<p class="wp-block-paragraph">So now let&#8217;s do stop on failures.</p>



<p class="wp-block-paragraph">Stop on failures.</p>



<p class="wp-block-paragraph">Notice how the first false showed up as an error to the make build system.</p>



<p class="wp-block-paragraph">And then make just said, we&#8217;re done.</p>



<p class="wp-block-paragraph">We&#8217;re not ignoring this error.</p>



<p class="wp-block-paragraph">We&#8217;re just done.</p>



<p class="wp-block-paragraph">So keep that in mind.</p>



<p class="wp-block-paragraph">Anytime you have commands that need to stop the build, if they fail,</p>



<p class="wp-block-paragraph">build if they fail you should not put a minus in front but anytime you have commands where</p>



<p class="wp-block-paragraph">everything just needs to be executed even if some stuff fails you want to put a minus in front of</p>



<p class="wp-block-paragraph">there we&#8217;ll talk about a clean target a little bit later which usually you know just continues</p>



<p class="wp-block-paragraph">even if there&#8217;s a failure so we got silent commands ignored commands or ignored failures</p>



<p class="wp-block-paragraph">and failures that we&#8217;re actually going to stop so now we&#8217;re going to get into the the meat and</p>



<p class="wp-block-paragraph">make file it doesn&#8217;t really do anything it doesn&#8217;t build anything for us I&#8217;m just kind of showing you</p>



<p class="wp-block-paragraph">you know how to work with the make file like the very basics now let&#8217;s actually start to build</p>



<p class="wp-block-paragraph">things so the first thing I&#8217;d like to do is I&#8217;d like to make a target for the build directory</p>



<p class="wp-block-paragraph">if you you know again if you just kind of like look at my file system here I don&#8217;t actually have</p>



<p class="wp-block-paragraph">a build directory right so I want to make sure that a build directory exists I could of course</p>



<p class="wp-block-paragraph">dir and then type build but I want the build system to do this automatically for me and also</p>



<p class="wp-block-paragraph">as a lesson for what we&#8217;re doing so you know be sure the build directory exists so I&#8217;m going to</p>



<p class="wp-block-paragraph">name a target and this is not going to be a phony target I think this is our first non-phony target</p>



<p class="wp-block-paragraph">right yeah oh I forgot to put la default as a phony might regret that one day the defaults</p>



<p class="wp-block-paragraph">you is phony and everything&#8217;s funny. Okay. So now we have our first real build target. I&#8217;m just</p>



<p class="wp-block-paragraph">going to name the thing that I want to build. And I&#8217;m going to name it by typing the build directory</p>



<p class="wp-block-paragraph">variable. I could type, you know, underscore build or whatever it is that I put for that variable.</p>



<p class="wp-block-paragraph">What did I put there again? Underscore build. Yeah, I could put that if I wanted to. But again,</p>



<p class="wp-block-paragraph">try not to hard code things. It&#8217;s better to stick things in variables if you can.</p>



<p class="wp-block-paragraph">So since this is a target, I&#8217;m going to put a colon. It doesn&#8217;t really depend on anything,</p>



<p class="wp-block-paragraph">because if we&#8217;re just talking about building that folder all we really have to do is execute a command</p>



<p class="wp-block-paragraph">to just make sure that the folder is created right so i&#8217;m going to do no dependencies and</p>



<p class="wp-block-paragraph">then i&#8217;m going to like maybe do a little all say function call just to announce that we&#8217;re going</p>



<p class="wp-block-paragraph">to ensure the build directory a lot of people don&#8217;t do this but i&#8217;m going to do it ensuring</p>



<p class="wp-block-paragraph">the builder and now i could put you know what the builder is probably a pretty good idea so that i</p>



<p class="wp-block-paragraph">probably a pretty good idea so that I can see what I&#8217;m trying to ensure let&#8217;s</p>



<p class="wp-block-paragraph">just run that real fast if I say oh shoot I guess I would have to do make</p>



<p class="wp-block-paragraph">and then name build let&#8217;s see if that actually works yeah okay so I&#8217;m naming</p>



<p class="wp-block-paragraph">the build directory you wouldn&#8217;t normally actually name the build</p>



<p class="wp-block-paragraph">directory in the command line but I&#8217;m doing it so it says we&#8217;re ensuring the</p>



<p class="wp-block-paragraph">build directory and then now it says the build thing is up to date because the</p>



<p class="wp-block-paragraph">because the target finished executing,</p>



<p class="wp-block-paragraph">but nothing actually got created, right?</p>



<p class="wp-block-paragraph">So what I would like to do before we actually create it</p>



<p class="wp-block-paragraph">is replace this builder variable with a special variable</p>



<p class="wp-block-paragraph">that GNU make gives you called $at.</p>



<p class="wp-block-paragraph">The $at variable, and I&#8217;m quoting it,</p>



<p class="wp-block-paragraph">you don&#8217;t have to quote it,</p>



<p class="wp-block-paragraph">it always ends up being the name of the current build target.</p>



<p class="wp-block-paragraph">So again, it&#8217;s a bad idea to hard code</p>



<p class="wp-block-paragraph">It&#8217;s a bad idea to hard code lots of different values</p>



<p class="wp-block-paragraph">and it&#8217;s way better to put things into a variable.</p>



<p class="wp-block-paragraph">But at the same time, if you can get away with</p>



<p class="wp-block-paragraph">hard coding a variable name multiple times</p>



<p class="wp-block-paragraph">and you can use something more generic,</p>



<p class="wp-block-paragraph">well then that can also increase the power</p>



<p class="wp-block-paragraph">of what you&#8217;re doing, make things easier for you</p>



<p class="wp-block-paragraph">and easier for you to debug.</p>



<p class="wp-block-paragraph">Save yourself some time, right?</p>



<p class="wp-block-paragraph">Because coding is already hard enough.</p>



<p class="wp-block-paragraph">So if I do dollar sign at,</p>



<p class="wp-block-paragraph">it should show up as whatever the builder contains</p>



<p class="wp-block-paragraph">because that&#8217;s the current target.</p>



<p class="wp-block-paragraph">So let&#8217;s run that one more time.</p>



<p class="wp-block-paragraph">that one more time and we&#8217;ll say clear and make build notice how it says ensuring the builder and</p>



<p class="wp-block-paragraph">then it quoted the current target which is underscore built nice so we got that now let&#8217;s</p>



<p class="wp-block-paragraph">actually run a command to create the directory that&#8217;s just going to be you know in linux the</p>



<p class="wp-block-paragraph">command mkdir to make a directory and again i could put a builder here but it&#8217;s probably a</p>



<p class="wp-block-paragraph">special variable that will change because what if later on i want to change the name of that variable</p>



<p class="wp-block-paragraph">uh if i did then i&#8217;d have to change it in three places now but uh you know and possibly way more</p>



<p class="wp-block-paragraph">places later down the line but if i use that special you know dollar at symbol then i only</p>



<p class="wp-block-paragraph">have to change it in one spot okay so mkdir so that basically says it&#8217;s going to look to see if</p>



<p class="wp-block-paragraph">that folder is created if it&#8217;s not then it&#8217;s going to create it with that command so if i do that</p>



<p class="wp-block-paragraph">So if I do that, notice how it executed that command and also printed the command.</p>



<p class="wp-block-paragraph">So it&#8217;s like mkdir build.</p>



<p class="wp-block-paragraph">If we list the directory again, notice how there is a build directory.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">You go inside of there.</p>



<p class="wp-block-paragraph">Everything&#8217;s fine.</p>



<p class="wp-block-paragraph">I&#8217;m going to remove it real fast.</p>



<p class="wp-block-paragraph">Whoops.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">All right.</p>



<p class="wp-block-paragraph">our make file until it&#8217;s somewhat decent it&#8217;s not going to be amazing but it&#8217;s going to be somewhat</p>



<p class="wp-block-paragraph">decent okay so we have a target that will build the build directory now let&#8217;s make our first real</p>



<p class="wp-block-paragraph">target that is it&#8217;s going to be a phony target but it&#8217;s going to it&#8217;s going to do something for us</p>



<p class="wp-block-paragraph">so run the program we&#8217;re going to make a target called run and so if you type make run then it</p>



<p class="wp-block-paragraph">which in my opinion would be building the program first.</p>



<p class="wp-block-paragraph">Your opinion may vary, but you know, so I&#8217;m going to do it this way.</p>



<p class="wp-block-paragraph">I&#8217;m going to say run colon because that&#8217;s the name of the target.</p>



<p class="wp-block-paragraph">And I&#8217;m going to say that the run target depends on the build target.</p>



<p class="wp-block-paragraph">So remember this means that before run can actually execute its steps,</p>



<p class="wp-block-paragraph">it will go quickly to the build target and execute all the steps in its recipe.</p>



<p class="wp-block-paragraph">So essentially I&#8217;m saying before we try to run, let&#8217;s build.</p>



<p class="wp-block-paragraph">So it depends on build.</p>



<p class="wp-block-paragraph">By the way, build is not created yet.</p>



<p class="wp-block-paragraph">We&#8217;re going to do that in a second.</p>



<p class="wp-block-paragraph">not created yet we&#8217;re going to do that in a second the only line in this recipe that i&#8217;m going to put</p>



<p class="wp-block-paragraph">is just the name of the binary meaning after build is finished running i can assume that</p>



<p class="wp-block-paragraph">the entire executable is actually built and it&#8217;s ready to run so then i&#8217;m just going to run it so</p>



<p class="wp-block-paragraph">it&#8217;s just like first go build it somewhere else and then run it and again indirection and modular</p>



<p class="wp-block-paragraph">thinking is is a lot more powerful than just sticking all the build commands right inside of</p>



<p class="wp-block-paragraph">run target and duplicate all those commands for the build target so this is way better and then</p>



<p class="wp-block-paragraph">i&#8217;ll name run as a phony because this is not an actual file i&#8217;m trying to build the run the there&#8217;s</p>



<p class="wp-block-paragraph">no file named run then we&#8217;ll do the build target build and link the object files and executable</p>



<p class="wp-block-paragraph">okay and this is where it gets a little funny so we&#8217;re going to make a target called build</p>



<p class="wp-block-paragraph">actually build everything we shouldn&#8217;t hard code them here we should treat every source code file</p>



<p class="wp-block-paragraph">as as one separate thing that needs to be built every corresponding object file that comes from</p>



<p class="wp-block-paragraph">a source file should be one separate thing that that gets built from the source code that needs</p>



<p class="wp-block-paragraph">to be used to build i guess is what i should say so what should the build target depend on like</p>



<p class="wp-block-paragraph">before we can say that build is satisfied.</p>



<p class="wp-block-paragraph">How about just the executable file itself?</p>



<p class="wp-block-paragraph">So I&#8217;m going to say the bin.</p>



<p class="wp-block-paragraph">So our main program,</p>



<p class="wp-block-paragraph">it should be totally built and finished</p>



<p class="wp-block-paragraph">and set up and created and everything</p>



<p class="wp-block-paragraph">before we can say build is satisfied.</p>



<p class="wp-block-paragraph">And then hilariously, once that&#8217;s satisfied,</p>



<p class="wp-block-paragraph">then the build target is totally satisfied too</p>



<p class="wp-block-paragraph">because it doesn&#8217;t really do anything.</p>



<p class="wp-block-paragraph">It just asks, you know, this is more of a shortcut.</p>



<p class="wp-block-paragraph">Okay, so now let&#8217;s,</p>



<p class="wp-block-paragraph">Let&#8217;s maybe first before we link let&#8217;s start writing commands to actually build the source code files. So I&#8217;m gonna do</p>



<p class="wp-block-paragraph">build the first object file</p>



<p class="wp-block-paragraph">So remember we have three source code files here. We&#8217;ve got first dot CPP and</p>



<p class="wp-block-paragraph">Second dot C and third dot ASM. So that&#8217;s just three source code files. They should map to three object files</p>



<p class="wp-block-paragraph">Let me let me draw this for you for a second before we talk about it further because I want to make sure</p>



<p class="wp-block-paragraph">that what I&#8217;m about to do is crystal clear when we&#8217;re talking about like the dependency graph.</p>



<p class="wp-block-paragraph">Okay. So my mouse is all over the place. I gotta execute a command real fast.</p>



<p class="wp-block-paragraph">I have many monitors going on right now and the pen just keeps forgetting that it&#8217;s only</p>



<p class="wp-block-paragraph">supposed to be on this one monitor. Okay. So I got that. Okay. So the first thing that we</p>



<p class="wp-block-paragraph">executable called main.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to draw that on the graph here for you Windows people.</p>



<p class="wp-block-paragraph">You can imagine there&#8217;s a dot exe on the end of it, but in, you know, in Linux and</p>



<p class="wp-block-paragraph">other link and other operating systems, we don&#8217;t really need that.</p>



<p class="wp-block-paragraph">So main, we want to build that.</p>



<p class="wp-block-paragraph">That&#8217;s the, that&#8217;s the primary thing we&#8217;re trying to build.</p>



<p class="wp-block-paragraph">What does it depend on though?</p>



<p class="wp-block-paragraph">What needs to be built before we can, we can create our executable?</p>



<p class="wp-block-paragraph">Well, we need to compile every piece of source code into a corresponding</p>



<p class="wp-block-paragraph">all the object files will be linked together into the executable so maybe i&#8217;ll i&#8217;ll write</p>



<p class="wp-block-paragraph">down first what the uh what the source code files are going to be so i&#8217;m going to do let&#8217;s see first</p>



<p class="wp-block-paragraph">sorry about my writing i don&#8217;t have a smoother right now first dot cpp and i got like a really</p>



<p class="wp-block-paragraph">small draw pad um i&#8217;m i&#8217;m making lots of excuses but i think probably my penmanship in real life is</p>



<p class="wp-block-paragraph">maybe even a little worse i don&#8217;t know i was at a job a long time ago and i was taking down</p>



<p class="wp-block-paragraph">names of customers it was like a tech support center and my boss after he saw the paper that</p>



<p class="wp-block-paragraph">i was writing down he just looked at me and he went chicken scratches and then he walked away</p>



<p class="wp-block-paragraph">okay so we have first dot cpp and then we have second this is why i like typing second dot c</p>



<p class="wp-block-paragraph">okay so we got that and then we&#8217;ll have third dot asm so third maybe i should go slower a</p>



<p class="wp-block-paragraph">At least I&#8217;m not making misspellings.</p>



<p class="wp-block-paragraph">I know these are simple file names, but it could happen.</p>



<p class="wp-block-paragraph">So we have three source code files.</p>



<p class="wp-block-paragraph">They don&#8217;t really depend on anything because they just are themselves.</p>



<p class="wp-block-paragraph">We don&#8217;t need to build these source code files.</p>



<p class="wp-block-paragraph">So we&#8217;re not going to draw any arrows indicating that these files depend on something else.</p>



<p class="wp-block-paragraph">They&#8217;re kind of like the primary source.</p>



<p class="wp-block-paragraph">Like these are the things that would actually go into your Git repository,</p>



<p class="wp-block-paragraph">whereas the object files that we&#8217;re going to generate and the executable that we generate,</p>



<p class="wp-block-paragraph">they would definitely not go into your repository.</p>



<p class="wp-block-paragraph">your git repository. Okay, so what&#8217;s going to happen? First.cpp is going to generate first.o.</p>



<p class="wp-block-paragraph">We&#8217;re going to type that out in a second, but basically first.o. That&#8217;s awful. That just looks</p>



<p class="wp-block-paragraph">disgusting. I&#8217;m going to keep it though. Okay, so in order to indicate dependency,</p>



<p class="wp-block-paragraph">we&#8217;re going to draw an arrow from first.o to first.cpp indicating, all right,</p>



<p class="wp-block-paragraph">if we&#8217;re trying to build first.o, then it will look at first.cpp and it&#8217;ll check.</p>



<p class="wp-block-paragraph">check does it exist if it doesn&#8217;t then there&#8217;s an error if it does exist then then the the the</p>



<p class="wp-block-paragraph">build system is actually going to check the modification dates of first.o and first.cpp</p>



<p class="wp-block-paragraph">assuming that a first.o already exists it&#8217;s just going to check it&#8217;s going to say</p>



<p class="wp-block-paragraph">does is first.cpp newer than first.o if yes then that means i have to recompile first.o if no i&#8217;m</p>



<p class="wp-block-paragraph">not going to recompile it and i&#8217;m going to save a bunch of time this is kind of the heart of why</p>



<p class="wp-block-paragraph">So same thing for 2nd.0.</p>



<p class="wp-block-paragraph">2nd.0, I&#8217;ll just circle it here, and we&#8217;ll say that it depends on 2nd.c.</p>



<p class="wp-block-paragraph">And then, of course, the 3rd.0 object file, it&#8217;s going to depend on 3rd.asm.</p>



<p class="wp-block-paragraph">So again, notice how they don&#8217;t really depend on each other.</p>



<p class="wp-block-paragraph">Maybe if you have a C++ file, maybe if you have a C++ program that&#8217;s really complicated,</p>



<p class="wp-block-paragraph">maybe your first.o, it would depend on the CPP file,</p>



<p class="wp-block-paragraph">and it might also depend on some other header files that you have set up somewhere.</p>



<p class="wp-block-paragraph">So then there would be more circles and more arrows that we draw.</p>



<p class="wp-block-paragraph">But for now, it&#8217;s just a simple program, so I&#8217;m just going to leave it this way.</p>



<p class="wp-block-paragraph">But just keep in mind that when we name dependencies in the make file,</p>



<p class="wp-block-paragraph">you want to name a dependency of everything that a source file depends on.</p>



<p class="wp-block-paragraph">So like first.o, it&#8217;s definitely going to depend on first.cpp,</p>



<p class="wp-block-paragraph">includes that are custom or from someone&#8217;s library and not the C++ standard libraries,</p>



<p class="wp-block-paragraph">then you would want to say that first.o depends on those as well. Because if you change</p>



<p class="wp-block-paragraph">a header that you made elsewhere in the program, then you probably want to recompile</p>



<p class="wp-block-paragraph">that corresponding object file, right? So just keep that in mind.</p>



<p class="wp-block-paragraph">Anyway, we&#8217;ll do first.o. Okay, so now the executable program main, that needs to be</p>



<p class="wp-block-paragraph">all the object files so I can just say that it depends on all three object files</p>



<p class="wp-block-paragraph">with just this right here and this is the basic idea of what we&#8217;re about to</p>



<p class="wp-block-paragraph">type up in the make file itself keep in mind that the make system will actually</p>



<p class="wp-block-paragraph">build this graph in memory under the hood to try and figure out which things</p>



<p class="wp-block-paragraph">actually need to be built or not you could even launch make with multiple</p>



<p class="wp-block-paragraph">threads I&#8217;ll probably forget to do it but it&#8217;s a things like dash J and then</p>



<p class="wp-block-paragraph">things like dash j and then the number of threads you want to launch in order to totally saturate</p>



<p class="wp-block-paragraph">your cpu and have as many things compiling as possibly can be compiled make will figure out</p>



<p class="wp-block-paragraph">which things don&#8217;t actually depend on each other and then build them in separate threads at the</p>



<p class="wp-block-paragraph">same time so your build system is just like so much faster so let&#8217;s see we got uh corresponding</p>



<p class="wp-block-paragraph">object dial for every source file and then we got the binary that depends on the object notice how</p>



<p class="wp-block-paragraph">source code file what would happen is when we wanted to build the let&#8217;s say we wanted to just</p>



<p class="wp-block-paragraph">you know this is the the target the binary target that is just named main what will happen is it&#8217;ll</p>



<p class="wp-block-paragraph">look at its dependencies and the way we&#8217;re going to write it it&#8217;ll say okay it depends on the three</p>



<p class="wp-block-paragraph">object files if they&#8217;re already there and they&#8217;re already satisfied then it it won&#8217;t actually</p>



<p class="wp-block-paragraph">if they&#8217;re already there and they are all newer than their corresponding source files then none</p>



<p class="wp-block-paragraph">corresponding source files, then none of them will get rebuilt. If main itself sees that it is newer,</p>



<p class="wp-block-paragraph">like the existing on disk version of main is newer than all the object files, then that tells the</p>



<p class="wp-block-paragraph">build system, oh, I don&#8217;t actually even need to relink the binary at all because the object files</p>



<p class="wp-block-paragraph">didn&#8217;t change, which means the source code didn&#8217;t change. And so you could actually like type make</p>



<p class="wp-block-paragraph">build and nothing happens because nothing needs to happen. It&#8217;s going to be pretty cool. I&#8217;ll show</p>



<p class="wp-block-paragraph">I&#8217;ll show you in a moment.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">So for now, I&#8217;m going to try not to erase this.</p>



<p class="wp-block-paragraph">I&#8217;m going to do a toggle.</p>



<p class="wp-block-paragraph">Do I can, I don&#8217;t know if I remember, I think it&#8217;s like control.</p>



<p class="wp-block-paragraph">Let me do the menu here.</p>



<p class="wp-block-paragraph">I don&#8217;t want to screw it up.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">It would have been control.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">So I&#8217;m going to toggle visibility.</p>



<p class="wp-block-paragraph">Just get that off there.</p>



<p class="wp-block-paragraph">Just in case I want to show it to you again later.</p>



<p class="wp-block-paragraph">So now let&#8217;s make the first object file.</p>



<p class="wp-block-paragraph">So remember the first object file is first.o.</p>



<p class="wp-block-paragraph">to create a target that will build the object file based on the first source code file.</p>



<p class="wp-block-paragraph">I&#8217;m going to put a colon there to indicate that it&#8217;s a target.</p>



<p class="wp-block-paragraph">And then remember on the right side, we can do dependencies.</p>



<p class="wp-block-paragraph">Well, we have to say that this depends on the first CPP file.</p>



<p class="wp-block-paragraph">If we didn&#8217;t, then every single time we run the make system,</p>



<p class="wp-block-paragraph">then this object file is just going to get built over and over and over again,</p>



<p class="wp-block-paragraph">even if it doesn&#8217;t need to.</p>



<p class="wp-block-paragraph">So now with a dependency there, it&#8217;s going to look at first.cpp</p>



<p class="wp-block-paragraph">and then it&#8217;s going to look at first.o if one exists if one doesn&#8217;t exist it&#8217;ll</p>



<p class="wp-block-paragraph">definitely build it but if one does exist it&#8217;ll go is first.o newer than</p>



<p class="wp-block-paragraph">first.cpp if it is don&#8217;t do anything but if it&#8217;s not then rebuild it make sure</p>



<p class="wp-block-paragraph">it&#8217;s fresh here&#8217;s the other thing though I kind of wanted to build everything</p>



<p class="wp-block-paragraph">inside of the of the build folder so I&#8217;m gonna add the variable build in front of</p>



<p class="wp-block-paragraph">it let me do it first without doing that so that you can kind of see what will</p>



<p class="wp-block-paragraph">So it&#8217;s going to depend on first dot CPP.</p>



<p class="wp-block-paragraph">And then there&#8217;s another thing you can do in make files where you can,</p>



<p class="wp-block-paragraph">I forgot the proper name for this,</p>



<p class="wp-block-paragraph">but you can specify other types of dependencies where they only need to exist</p>



<p class="wp-block-paragraph">as a dependency.</p>



<p class="wp-block-paragraph">They don&#8217;t necessarily need to be freshly fully updated because,</p>



<p class="wp-block-paragraph">you know, the way files and folders work,</p>



<p class="wp-block-paragraph">if you start adding or removing files from a directory,</p>



<p class="wp-block-paragraph">then the directory thinks that it&#8217;s been updated.</p>



<p class="wp-block-paragraph">And so that can kind of throw off the build system&#8217;s thinking</p>



<p class="wp-block-paragraph">the build system&#8217;s thinking because your build directory will always think that it&#8217;s been updated</p>



<p class="wp-block-paragraph">if anything happens. But we don&#8217;t really care about the date of when the build directory was</p>



<p class="wp-block-paragraph">built. We just want to make sure that it exists, right? So we put a little or bar and we put those</p>



<p class="wp-block-paragraph">types of dependencies on the right side of the or bar. Okay, maybe I&#8217;ll leave a comment or something</p>



<p class="wp-block-paragraph">at a later date specifying the official name for that, but I mean, that&#8217;s how it works.</p>



<p class="wp-block-paragraph">So that&#8217;s the recipe.</p>



<p class="wp-block-paragraph">It&#8217;s got dependencies.</p>



<p class="wp-block-paragraph">You know, in the past, I&#8217;ve said when you name a dependency,</p>



<p class="wp-block-paragraph">it goes off and make sure that that dependency is resolved.</p>



<p class="wp-block-paragraph">Well, that&#8217;s true for phony targets and targets that sort of do other things.</p>



<p class="wp-block-paragraph">But in this case, if we&#8217;re just naming a file, all it&#8217;s going to do is just look</p>



<p class="wp-block-paragraph">at the modification date of the file.</p>



<p class="wp-block-paragraph">So now let&#8217;s do the recipe.</p>



<p class="wp-block-paragraph">I&#8217;m going to do CPP, which means that&#8217;s the C++ compiler.</p>



<p class="wp-block-paragraph">And I could write, you know, G++ and all the commands here directly</p>



<p class="wp-block-paragraph">directly if I want to, but it&#8217;s kind of a waste of time.</p>



<p class="wp-block-paragraph">And it&#8217;s not, it&#8217;s not very smart because we said before, what if you want to change</p>



<p class="wp-block-paragraph">the flags and you have a hundred objects that you&#8217;re building, you probably just want to</p>



<p class="wp-block-paragraph">be able to change one variable instead of a hundred different things.</p>



<p class="wp-block-paragraph">So we&#8217;ll do CPP flags and then we&#8217;ll, let&#8217;s see, we&#8217;ll take first.cpp as a source.</p>



<p class="wp-block-paragraph">You can imagine again, this is like, you know, G++ happening inside of here and then wall</p>



<p class="wp-block-paragraph">inside of here.</p>



<p class="wp-block-paragraph">and then at some point you specify the source.</p>



<p class="wp-block-paragraph">Okay, so just keep that in mind.</p>



<p class="wp-block-paragraph">And then after I specify the source,</p>



<p class="wp-block-paragraph">I want to specify the output</p>



<p class="wp-block-paragraph">and the output is going to be first.o.</p>



<p class="wp-block-paragraph">And now let&#8217;s use another trick</p>



<p class="wp-block-paragraph">which allows us to make slightly more powerful make files.</p>



<p class="wp-block-paragraph">So again, you want to avoid hard coding stuff if you can.</p>



<p class="wp-block-paragraph">There&#8217;s a special variable.</p>



<p class="wp-block-paragraph">Well, okay, let&#8217;s go back first to the other special variable.</p>



<p class="wp-block-paragraph">Remember $and, or sorry, $at.</p>



<p class="wp-block-paragraph">that always refers to the current target right so first.o is the is the current</p>



<p class="wp-block-paragraph">target so I don&#8217;t even have to type first.o here I can just do dollar sign</p>



<p class="wp-block-paragraph">at there&#8217;s another special variable which just basically means the first</p>



<p class="wp-block-paragraph">dependency that&#8217;s been named so if I just do quotes and then I say this it&#8217;s</p>



<p class="wp-block-paragraph">weird I know dollar sign and then angle bracket pointing to the left or like a</p>



<p class="wp-block-paragraph">typing first dot CPP. If you wanted to send a bunch more stuff, like if you wanted to</p>



<p class="wp-block-paragraph">send all of the names of all dependencies that you named into the command line, then</p>



<p class="wp-block-paragraph">you can use the carrot like dollar carrot. That&#8217;ll do all of the dependencies. But if</p>



<p class="wp-block-paragraph">we&#8217;re just compiling one source code file, you probably want to just do one dependency.</p>



<p class="wp-block-paragraph">Like for example, if I had other thing dot HPP as a dependency, I probably wouldn&#8217;t want</p>



<p class="wp-block-paragraph">because then that would be telling the compiler,</p>



<p class="wp-block-paragraph">here, I want you to compile first.cpp and also other thing.hpp,</p>



<p class="wp-block-paragraph">which probably wouldn&#8217;t work.</p>



<p class="wp-block-paragraph">It&#8217;s probably not what you want.</p>



<p class="wp-block-paragraph">So instead, if I do this like arrow to the left,</p>



<p class="wp-block-paragraph">then it will only give it first.cpp rather than both dependencies.</p>



<p class="wp-block-paragraph">But I guess we&#8217;re simple.</p>



<p class="wp-block-paragraph">We don&#8217;t really need all that right now.</p>



<p class="wp-block-paragraph">So we got that finished.</p>



<p class="wp-block-paragraph">Let&#8217;s see.</p>



<p class="wp-block-paragraph">We now have the binary.</p>



<p class="wp-block-paragraph">okay this is only going to run if i do make first dot oh maybe i should do that right now so that</p>



<p class="wp-block-paragraph">we can we can take more baby steps to making this more complicated so i&#8217;ll do here and make</p>



<p class="wp-block-paragraph">and then i&#8217;ll do make first dot o so notice how when i typed first dot o it went right to this</p>



<p class="wp-block-paragraph">target no problem and then it started to you know it looked at first dot cpp just to see you know</p>



<p class="wp-block-paragraph">built or not and it it also looked at the build directory as a dependency and</p>



<p class="wp-block-paragraph">then finally it actually compiled so what we should see right now is first</p>



<p class="wp-block-paragraph">dot o sitting in the directory and then also we should see the build directory</p>



<p class="wp-block-paragraph">again let&#8217;s just double check that so if I list everything notice how the build</p>



<p class="wp-block-paragraph">directory exists if I go remove and then remove the build directory and then</p>



<p class="wp-block-paragraph">clear it again notice how we also have first dot o so I can say remove first</p>



<p class="wp-block-paragraph">So if we go clear and list everything again, now I&#8217;m going to do one more time.</p>



<p class="wp-block-paragraph">Make first.o and then if I do list, then the first.o got built and the build directory got built.</p>



<p class="wp-block-paragraph">Notice also that as soon as I ran that command, it did make dir on build.</p>



<p class="wp-block-paragraph">So it built the build directory.</p>



<p class="wp-block-paragraph">So that was the build dir target.</p>



<p class="wp-block-paragraph">And then it went over to the first.o target and it executed that command to actually compile it.</p>



<p class="wp-block-paragraph">All my variables expanded, so it&#8217;s like G++, wall, pedantic, whatever.</p>



<p class="wp-block-paragraph">That special variable with the arrow pointing to the left was the first source code, or source code file.</p>



<p class="wp-block-paragraph">And then the $at variable expanded to the current target, which is just first.o.</p>



<p class="wp-block-paragraph">If we run this again, I&#8217;m not going to clear it, I&#8217;m just going to go make first.o.</p>



<p class="wp-block-paragraph">Notice how nothing actually happens.</p>



<p class="wp-block-paragraph">It&#8217;s missing two lines.</p>



<p class="wp-block-paragraph">Up here we had two lines where we made the build directory</p>



<p class="wp-block-paragraph">and we also compiled the object file.</p>



<p class="wp-block-paragraph">But notice how here it just says the object file is up to date.</p>



<p class="wp-block-paragraph">It did not recompile it because it can tell that the source code was not changed.</p>



<p class="wp-block-paragraph">Let me go into another directory right here and I&#8217;ll just modify the source code file.</p>



<p class="wp-block-paragraph">I&#8217;ll just add an extra line to it and then I&#8217;ll go back here.</p>



<p class="wp-block-paragraph">and if I compile it now we should see that it chooses to compile it again</p>



<p class="wp-block-paragraph">because now the source code is newer than the object file so if I go make</p>



<p class="wp-block-paragraph">first notice how it did not build the build directory because it already</p>



<p class="wp-block-paragraph">existed but it did rebuild the object file because the source code was updated</p>



<p class="wp-block-paragraph">if I immediately try to build it again it does not need to rebuild it because</p>



<p class="wp-block-paragraph">the source code didn&#8217;t get updated since the last time I built and so it says</p>



<p class="wp-block-paragraph">it&#8217;s up to date up to date sometimes you might see a message that says something</p>



<p class="wp-block-paragraph">just says something like nothing to do, I think.</p>



<p class="wp-block-paragraph">So just keep that in mind.</p>



<p class="wp-block-paragraph">We&#8217;re getting a little bit better now.</p>



<p class="wp-block-paragraph">But I&#8217;m also making a mistake here</p>



<p class="wp-block-paragraph">because we have a build directory</p>



<p class="wp-block-paragraph">but there&#8217;s nothing inside of it.</p>



<p class="wp-block-paragraph">I wanna put everything inside of my build directory</p>



<p class="wp-block-paragraph">just to show you how annoying this could be.</p>



<p class="wp-block-paragraph">Notice how we got a first.cpp and a first.o.</p>



<p class="wp-block-paragraph">Imagine if you had a million source code files,</p>



<p class="wp-block-paragraph">you&#8217;ll have a million object files</p>



<p class="wp-block-paragraph">sitting in your repository or your directory</p>



<p class="wp-block-paragraph">kinda cluttering the place up, right?</p>



<p class="wp-block-paragraph">cluttering the place up, right? I don&#8217;t like it. I&#8217;m not a fan. You probably want to edit your</p>



<p class="wp-block-paragraph">git ignore so that you don&#8217;t accidentally put object files into your repo. But for me, I think</p>



<p class="wp-block-paragraph">it&#8217;s better to just ignore, git ignore a build directory, and then just stick everything inside</p>



<p class="wp-block-paragraph">of the build directory. It&#8217;s up to you, but this is the way I&#8217;m going to do it. So how do we get</p>



<p class="wp-block-paragraph">it to be inside of the build directory? First, let me remove the object file. Okay, let&#8217;s see,</p>



<p class="wp-block-paragraph">I think I can get rid of that. That&#8217;s responsible for the swap file. We probably want to put</p>



<p class="wp-block-paragraph">star.swap inside of gitignore so that the temporary files from nano don&#8217;t go into our</p>



<p class="wp-block-paragraph">repository. So now I&#8217;m going to prefix this object file. And a lot of people don&#8217;t do this,</p>



<p class="wp-block-paragraph">but I think it&#8217;s pretty cool. I&#8217;m going to do build dir slash the object. And then now</p>



<p class="wp-block-paragraph">everything&#8217;s going to show up inside of the builder or at least that one. So if I remove</p>



<p class="wp-block-paragraph">directory just kind of list things again then I can do make first oh and then</p>



<p class="wp-block-paragraph">notice how it mmm what happened oh what did I do wrong well I did something wrong</p>



<p class="wp-block-paragraph">okay hang on let me see if I can fix that first oh what in the heck did I do</p>



<p class="wp-block-paragraph">second and third. Okay, so I didn&#8217;t break anything.</p>



<p class="wp-block-paragraph">First.o. Oh, because when I typed this on the command line, I was typing first.o and</p>



<p class="wp-block-paragraph">well, that&#8217;s not the target anymore. The real target now is underscore build first.o.</p>



<p class="wp-block-paragraph">So maybe this is a good time to stick our binary target inside of there.</p>



<p class="wp-block-paragraph">So we have the binary target. I kind of ignored it for a second because I wanted to show you an object file first.</p>



<p class="wp-block-paragraph">We want to make the main file that gets executed.</p>



<p class="wp-block-paragraph">We have to link everything together.</p>



<p class="wp-block-paragraph">So, well, maybe this is a better description down here for that.</p>



<p class="wp-block-paragraph">And then up here, I&#8217;ll say alias for just building the binary.</p>



<p class="wp-block-paragraph">Whoops.</p>



<p class="wp-block-paragraph">Binary building.</p>



<p class="wp-block-paragraph">Building.</p>



<p class="wp-block-paragraph">There we go.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">So now we&#8217;re actually going to do it.</p>



<p class="wp-block-paragraph">So we&#8217;ll put bin.</p>



<p class="wp-block-paragraph">So now bin is its own target, meaning our main program that we want to create</p>



<p class="wp-block-paragraph">main program that we want to create is uh it&#8217;s going to happen somehow the uh dependencies that</p>



<p class="wp-block-paragraph">it needs though should be all of our object files that we intend to create so first you know one of</p>



<p class="wp-block-paragraph">its dependencies should be uh inside of the builder and i know this is annoying to type these variables</p>



<p class="wp-block-paragraph">all over the place but kind of the price you pay for having everything outside of the working</p>



<p class="wp-block-paragraph">directory but i guess that&#8217;s why a lot of people don&#8217;t do this we say builder first dot o so</p>



<p class="wp-block-paragraph">So basically saying before we can create the executable, we have to first build the first</p>



<p class="wp-block-paragraph">object file.</p>



<p class="wp-block-paragraph">And then we&#8217;ll just name more dependencies.</p>



<p class="wp-block-paragraph">I&#8217;ll say the builder, we separate dependencies using spaces.</p>



<p class="wp-block-paragraph">That&#8217;s another reason that make has problems with spaces if you&#8217;re going to do like an</p>



<p class="wp-block-paragraph">absolute path or something.</p>



<p class="wp-block-paragraph">So then we&#8217;re going to grab the second object file as a dependency and then the third object</p>



<p class="wp-block-paragraph">file as a dependency.</p>



<p class="wp-block-paragraph">means we just need to set up targets for each one of those object files we only have first.o</p>



<p class="wp-block-paragraph">set up so far we&#8217;ll have to set up the second and the third one so aside from those dependencies we</p>



<p class="wp-block-paragraph">want to make sure that the builder is actually created so we&#8217;ll put builder as another uh you</p>



<p class="wp-block-paragraph">know non-time stamped uh dependency like we did with the object file then the command we&#8217;ll actually</p>



<p class="wp-block-paragraph">and remember CPP is just GCC and then the link flags is the stuff that we set up up above</p>



<p class="wp-block-paragraph">which is basically going to be you know wall pedantic G and then M64 no pi no you know all</p>



<p class="wp-block-paragraph">the stuff we don&#8217;t want to type manually at the very bottom so we&#8217;re going to do that link flags</p>



<p class="wp-block-paragraph">you know we want to give it every single object file as an input so we&#8217;ll name you know first.o</p>



<p class="wp-block-paragraph">and then we&#8217;ll name second.o second.o and you know i&#8217;m getting irritated i hope you can tell</p>



<p class="wp-block-paragraph">already i don&#8217;t want to type all these things so we can use a shell trick we can put a wild card</p>



<p class="wp-block-paragraph">there we can say how about i just give you every file asterisk that ends in.o so star.o basically</p>



<p class="wp-block-paragraph">on that command line it&#8217;s going to go look into the build directory and just</p>



<p class="wp-block-paragraph">give it every object file that it sees it&#8217;s not a great idea if you have</p>



<p class="wp-block-paragraph">multiple different executables that you want to make and they&#8217;ve all got their</p>



<p class="wp-block-paragraph">own main functions and they&#8217;re all in the same builder but in our case we only</p>



<p class="wp-block-paragraph">have one executable with one main function so we can just throw all of the</p>



<p class="wp-block-paragraph">object files we want at it if you had other types of object files you wanted</p>



<p class="wp-block-paragraph">to link into your executable like for example shared object files you could</p>



<p class="wp-block-paragraph">object files you could basically do the same thing but just go you know builder star star.so</p>



<p class="wp-block-paragraph">or maybe not even in the builder if i if let&#8217;s say if i gave you a shared object file</p>



<p class="wp-block-paragraph">and i wanted you to link that into your program you would just specify wherever it was</p>



<p class="wp-block-paragraph">you know maybe it&#8217;s in the root something.so maybe it&#8217;s in a different folder um and maybe</p>



<p class="wp-block-paragraph">you want to create a variable up top to just kind of like name where the shared object files are</p>



<p class="wp-block-paragraph">libraries are it&#8217;s up to you but I&#8217;m just letting you know this is how you</p>



<p class="wp-block-paragraph">would do it to get a shared object file in there as well for this program it&#8217;s</p>



<p class="wp-block-paragraph">very simple we just are gonna grab the object files and that&#8217;s it so now we&#8217;re</p>



<p class="wp-block-paragraph">just ready to specify the output file with a dash o and we&#8217;ll use that same</p>



<p class="wp-block-paragraph">trick again dollar sign and at so we don&#8217;t have to specify the the full</p>



<p class="wp-block-paragraph">target which is just going to be the bin variable so let&#8217;s see what do I got to</p>



<p class="wp-block-paragraph">If we run it right now, it should fail because it&#8217;ll complain that we don&#8217;t have second and third built.</p>



<p class="wp-block-paragraph">But at least I have enough now to use the make run target.</p>



<p class="wp-block-paragraph">So we can stop specifying the names of files and just say something like make run or make build and it&#8217;s just way easier to type.</p>



<p class="wp-block-paragraph">So I&#8217;m going to type make run.</p>



<p class="wp-block-paragraph">It&#8217;s going to depend on build.</p>



<p class="wp-block-paragraph">Build is going to execute before run even tries to run.</p>



<p class="wp-block-paragraph">Build is going to say, well, I depend on the binary, the executable.</p>



<p class="wp-block-paragraph">Then that means the binary&#8217;s target is going to run.</p>



<p class="wp-block-paragraph">run it&#8217;s going to depend on all these object files so before it even tries to do anything</p>



<p class="wp-block-paragraph">it&#8217;s going to go down here to the first dot o object file it&#8217;s actually going to build it</p>



<p class="wp-block-paragraph">then it&#8217;s going to come back and try to handle the next dependency which is second dot o</p>



<p class="wp-block-paragraph">but there&#8217;s no target for second dot o and it&#8217;s not on disk um so it&#8217;s just going to fail at that</p>



<p class="wp-block-paragraph">point so let&#8217;s see if let&#8217;s see if i&#8217;m right we&#8217;re going to do make run clear and whoops</p>



<p class="wp-block-paragraph">Make run</p>



<p class="wp-block-paragraph">Okay, so ensuring the build directory. Oh, I forgot to mention that yet</p>



<p class="wp-block-paragraph">It&#8217;s gonna ensure the build directory then it actually builds the first object file so far so good</p>



<p class="wp-block-paragraph">Then it complains no rule to make the target second auto so we can&#8217;t continue Oh</p>



<p class="wp-block-paragraph">drat</p>



<p class="wp-block-paragraph">By the way just to show you I think it&#8217;s like a J</p>



<p class="wp-block-paragraph">Let&#8217;s say we wanted to launch this with eight threads. I think it might be low</p>



<p class="wp-block-paragraph">Is it lowercase or uppercase J? I can never remember. Let me try lowercase</p>



<p class="wp-block-paragraph">second how about uppercase nope okay so it&#8217;s lowercase well I guess it just fails right there</p>



<p class="wp-block-paragraph">I was kind of hoping it would try to spawn off two threads to look at second and also third</p>



<p class="wp-block-paragraph">at the same time and then fail twice maybe that&#8217;s why it didn&#8217;t do that because it automatically</p>



<p class="wp-block-paragraph">saw right away oh we can&#8217;t do anything so let&#8217;s just cut the whole build process so now I&#8217;m going</p>



<p class="wp-block-paragraph">Cut cut cut paste paste and then I&#8217;m going to say build the second object file</p>



<p class="wp-block-paragraph">So we&#8217;re going to depend on seconds</p>



<p class="wp-block-paragraph">There are actually advanced patterns you can use so that you don&#8217;t even have to specify the object files you can</p>



<p class="wp-block-paragraph">There&#8217;s there&#8217;s these things that people do I did it a couple times</p>



<p class="wp-block-paragraph">But I don&#8217;t really like it where you can have make sort of scan your source code directory for all CPP files and</p>



<p class="wp-block-paragraph">Automatically compile them in the exact same way and then the output file is like</p>



<p class="wp-block-paragraph">And then the output file is like the name of the source code file and then.o concatenated at the end of it.</p>



<p class="wp-block-paragraph">But this video is not like that advanced, so I&#8217;m not going to do that.</p>



<p class="wp-block-paragraph">So we&#8217;re going to compile second.c into second.o.</p>



<p class="wp-block-paragraph">And we need to make sure the build directory is created.</p>



<p class="wp-block-paragraph">And instead of using the CPP compiler, we&#8217;re going to use the regular C compiler.</p>



<p class="wp-block-paragraph">And then we&#8217;re going to do cc flags right there.</p>



<p class="wp-block-paragraph">and I think that&#8217;s all we need so then we&#8217;re gonna do the last object file by</p>



<p class="wp-block-paragraph">the way in nano I&#8217;m going control K to cut and control you to paste and it&#8217;s</p>



<p class="wp-block-paragraph">kind of convenient if you want to like duplicate you know a few lines we&#8217;re</p>



<p class="wp-block-paragraph">gonna use the ASM to assemble the assembly code so I&#8217;m gonna do third dot</p>



<p class="wp-block-paragraph">what it was and then we have to use a totally different command now we have to use the assembly</p>



<p class="wp-block-paragraph">assembler variable so that&#8217;s the name of the tool that assembles and then we&#8217;ll give it the assembly</p>



<p class="wp-block-paragraph">flags i mean i guess it&#8217;s not that different and then we&#8217;ll say give it the first dependency which</p>



<p class="wp-block-paragraph">is just the source code and then output to the at target so we should have like a lot of stuff</p>



<p class="wp-block-paragraph">ready to go let&#8217;s see if this works now if i say clear and make run then what is it going to do it</p>



<p class="wp-block-paragraph">then what is it going to do it the first thing it does is it compiles the second object file</p>



<p class="wp-block-paragraph">notice how it did not compile the first object file because remember we just compiled that</p>



<p class="wp-block-paragraph">and we didn&#8217;t change the source code so it just ignored it and we have a faster compile</p>



<p class="wp-block-paragraph">then it assembles aka compiles the assembly to its own object file and then</p>



<p class="wp-block-paragraph">now that all those object files are satisfied notice how like you know for the binary</p>



<p class="wp-block-paragraph">all of those object files first and make sure the build directory is there. Then finally it can</p>



<p class="wp-block-paragraph">execute its own recipe, which is just one command saying, you know, let&#8217;s link this stuff together</p>



<p class="wp-block-paragraph">by grabbing all the object files. So that&#8217;s this line right here, the linking flags and the linker.</p>



<p class="wp-block-paragraph">So it&#8217;s like GCC and all the linking flags, the no pie and all that stuff. And it&#8217;s expanded that</p>



<p class="wp-block-paragraph">variable. Remember we put builder slash star dot O. So that glob right there basically says grab</p>



<p class="wp-block-paragraph">glob right there basically says grab all the object files from the build directory and then</p>



<p class="wp-block-paragraph">output the main program in the build directory no no i think even if you&#8217;re using a build directory</p>



<p class="wp-block-paragraph">sometimes people will still put their executable in the root i don&#8217;t know it&#8217;s up to you i don&#8217;t</p>



<p class="wp-block-paragraph">really care finally after all that is done you&#8217;ll see let&#8217;s see what we actually did is we said let&#8217;s</p>



<p class="wp-block-paragraph">its recipe it goes down here for build and then build says first we need to build that binary</p>



<p class="wp-block-paragraph">and then binaries like first we got to build the object files and then you know all those</p>



<p class="wp-block-paragraph">get built finally when the object files are built then the binary gets to link itself</p>



<p class="wp-block-paragraph">when it&#8217;s done linking itself then we go back to this point because now finally the dependencies</p>



<p class="wp-block-paragraph">on line 108 are satisfied then that means the build target its dependencies are satisfied</p>



<p class="wp-block-paragraph">dependencies are satisfied. It would execute its recipe, but there&#8217;s no recipe there. So it just</p>



<p class="wp-block-paragraph">goes back to run because in the first place, run said, I need you to make sure that build is handled</p>



<p class="wp-block-paragraph">before I&#8217;ll execute my recipe or all of my statements. So finally, after all that stuff</p>



<p class="wp-block-paragraph">was done, then it&#8217;s just a command line that just names the executable, which is going to run it.</p>



<p class="wp-block-paragraph">And that&#8217;s this last part right here. So right there, it just names the executable using a</p>



<p class="wp-block-paragraph">using a whoops using a relative path to our main executable so now below that</p>



<p class="wp-block-paragraph">line the program is actually running it&#8217;s like hello from first hello from</p>



<p class="wp-block-paragraph">second hello from third and watch this if I do make run again nothing happens</p>



<p class="wp-block-paragraph">except executing the program notice how none of the object files are getting</p>



<p class="wp-block-paragraph">built the binary is not getting linked nothing is happening because it&#8217;s</p>



<p class="wp-block-paragraph">already done all it does for the run target now is just run the executable</p>



<p class="wp-block-paragraph">run the executable. It&#8217;s the same thing as if we did build main, just to run it. That&#8217;s it.</p>



<p class="wp-block-paragraph">You know, of course, it&#8217;s a little more proper to go dot slash, right? You don&#8217;t have to use the</p>



<p class="wp-block-paragraph">dot if the thing you&#8217;re naming is in a different directory, but you do if it&#8217;s in the same directory.</p>



<p class="wp-block-paragraph">Like if we just went into the build directory, by the way, here&#8217;s all our build files. They&#8217;re</p>



<p class="wp-block-paragraph">in one convenient place. You can do a git ignore on that, or you can just delete the folder if</p>



<p class="wp-block-paragraph">if you want to clean everything.</p>



<p class="wp-block-paragraph">But we can&#8217;t just type main here, it&#8217;s not going to work.</p>



<p class="wp-block-paragraph">We have to do a dot slash main because we&#8217;re in the same folder.</p>



<p class="wp-block-paragraph">But if we&#8217;re one level higher, then we can just name build main and it&#8217;ll work.</p>



<p class="wp-block-paragraph">Okay, so let&#8217;s do another thing real fast here.</p>



<p class="wp-block-paragraph">Let&#8217;s do another target that is kind of typical.</p>



<p class="wp-block-paragraph">It is the clean target.</p>



<p class="wp-block-paragraph">useful when people have object files just scattered around the root of their of their file system</p>



<p class="wp-block-paragraph">there their repository but i like to add it in anyway for mine even though mine&#8217;s a little bit</p>



<p class="wp-block-paragraph">cleaner right now so we&#8217;ll do another target called clean and we&#8217;ll just say clean the uh the</p>



<p class="wp-block-paragraph">build area system thing stuff and i&#8217;m just going to put the word clean with a colon no dependencies</p>



<p class="wp-block-paragraph">meaning it&#8217;ll always run right away and not depend on anything it&#8217;s obviously a phony target because</p>



<p class="wp-block-paragraph">It&#8217;s obviously a phony target because I&#8217;m not going to make a file called clean so I&#8217;m</p>



<p class="wp-block-paragraph">going to stick that as a dependency to phony.</p>



<p class="wp-block-paragraph">And then what is it going to do?</p>



<p class="wp-block-paragraph">Usually this is where you put something like let&#8217;s remove star dot o, let&#8217;s remove all</p>



<p class="wp-block-paragraph">of the object files and then let&#8217;s remove the binary file and let&#8217;s remove anything</p>



<p class="wp-block-paragraph">that we built so that we can just clean it.</p>



<p class="wp-block-paragraph">Maybe I could put that here, build dir slash o, I&#8217;m going to make it a little bit better</p>



<p class="wp-block-paragraph">in a second.</p>



<p class="wp-block-paragraph">inside of the builder and then we&#8217;ll also remove the binary.</p>



<p class="wp-block-paragraph">So when we go back into our file system,</p>



<p class="wp-block-paragraph">if we list the build directory,</p>



<p class="wp-block-paragraph">we should see that it&#8217;s empty after we run this.</p>



<p class="wp-block-paragraph">So I&#8217;m going to do that right now.</p>



<p class="wp-block-paragraph">I&#8217;m going to do make clean.</p>



<p class="wp-block-paragraph">And then you can see that these two removal commands got executed.</p>



<p class="wp-block-paragraph">And then if I list the directory again, notice how it&#8217;s empty.</p>



<p class="wp-block-paragraph">But the remove command will fail</p>



<p class="wp-block-paragraph">if it tries to remove something that doesn&#8217;t exist.</p>



<p class="wp-block-paragraph">to remove something that doesn&#8217;t exist so we&#8217;ll actually get like a a nasty message from clean</p>



<p class="wp-block-paragraph">or from make if we try to clean again so we say make clean it says remove tried to remove object</p>



<p class="wp-block-paragraph">files but there was nothing inside of there no such file or directory so then it just stops the</p>



<p class="wp-block-paragraph">whole process well that seems okay for now but what if you uh what if you had gone in and removed or</p>



<p class="wp-block-paragraph">and that stopped other things from being cleaned you&#8217;d probably end up being</p>



<p class="wp-block-paragraph">pretty frustrated right so for the clean target I&#8217;m just gonna say remove is a</p>



<p class="wp-block-paragraph">command that won&#8217;t stop the build or the target so I&#8217;m gonna put a minus in</p>



<p class="wp-block-paragraph">front of there meaning don&#8217;t stop if something goes wrong just keep</p>



<p class="wp-block-paragraph">executing all these commands and so now if we do clear and make clean notice how</p>



<p class="wp-block-paragraph">it actually tries to remove both types of things it doesn&#8217;t just stop on the</p>



<p class="wp-block-paragraph">I guess this is the first problem.</p>



<p class="wp-block-paragraph">It&#8217;s trying to remove the object files.</p>



<p class="wp-block-paragraph">Then remove says, no, I can&#8217;t do that.</p>



<p class="wp-block-paragraph">There&#8217;s nothing there.</p>



<p class="wp-block-paragraph">And then make says, I&#8217;m ignoring you.</p>



<p class="wp-block-paragraph">Stop whining.</p>



<p class="wp-block-paragraph">There is no bathroom.</p>



<p class="wp-block-paragraph">And then the same thing happens for removing the executable main.</p>



<p class="wp-block-paragraph">But we can make this actually a little bit more efficient.</p>



<p class="wp-block-paragraph">I mean, this is kind of what you&#8217;ll do if everything is sitting at the root of your repo.</p>



<p class="wp-block-paragraph">But if we simply have a build directory and you&#8217;re absolutely sure that you already have</p>



<p class="wp-block-paragraph">you know set to the correct value then you could just remove i don&#8217;t know if i want to do it now</p>



<p class="wp-block-paragraph">because i&#8217;m getting scared you could just remove the entire build directory i&#8217;m going to do it but</p>



<p class="wp-block-paragraph">i&#8217;ll explain to you why i kind of don&#8217;t want to do it in a second we could remove the entire build</p>



<p class="wp-block-paragraph">directory so like with the remove command remove recursively the entire build directory</p>



<p class="wp-block-paragraph">just so you don&#8217;t see it if you feel like it&#8217;s an eyesore so i&#8217;m going to do make clean</p>



<p class="wp-block-paragraph">do it again do it again do it again and notice well why wasn&#8217;t it</p>



<p class="wp-block-paragraph">i feel like it should have failed but i guess remove felt like it wasn&#8217;t a failure if build</p>



<p class="wp-block-paragraph">didn&#8217;t exist but notice how the builder is gone so i didn&#8217;t really have to specify</p>



<p class="wp-block-paragraph">the object files but it&#8217;s a little bit safer i don&#8217;t know it depends on your philosophy</p>



<p class="wp-block-paragraph">this is way more compact and nicer that was my first feeling but it&#8217;s also a little more</p>



<p class="wp-block-paragraph">there into the variables area and i like change the builder somehow i change its name or i change</p>



<p class="wp-block-paragraph">its value and i accidentally now have this variable pointed to like a dangerous path</p>



<p class="wp-block-paragraph">and then if i type make clean it just erases everything not sure i really like that idea so</p>



<p class="wp-block-paragraph">i&#8217;m going to do i&#8217;m going to go back to the original way which takes more typing</p>



<p class="wp-block-paragraph">remove every object file and maybe before that let&#8217;s remove the binary so if we do</p>



<p class="wp-block-paragraph">if we do make build which by the way will only build things it won&#8217;t run anything remember</p>



<p class="wp-block-paragraph">the dependency graph that we looked at a little while ago or not the dependency graph that we</p>



<p class="wp-block-paragraph">explained the dependencies so it does everything required to build but it doesn&#8217;t actually run the</p>



<p class="wp-block-paragraph">program and that&#8217;s fine i just wanted to go look inside of the build directory</p>



<p class="wp-block-paragraph">and you can see it&#8217;s got all the stuff there so then if i just run make clean one more time</p>



<p class="wp-block-paragraph">by the way, if I try to run make clean from here,</p>



<p class="wp-block-paragraph">there&#8217;s no make file in this directory.</p>



<p class="wp-block-paragraph">So nothing&#8217;s going to happen.</p>



<p class="wp-block-paragraph">So I&#8217;m going to go up one level, make clean.</p>



<p class="wp-block-paragraph">And then if I list the build directory,</p>



<p class="wp-block-paragraph">there&#8217;s just nothing inside of it.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">All right.</p>



<p class="wp-block-paragraph">Let me just look at my notes right here.</p>



<p class="wp-block-paragraph">I just finished building this whole giant make file.</p>



<p class="wp-block-paragraph">It&#8217;s not even like that complicated,</p>



<p class="wp-block-paragraph">but I hope that you&#8217;ve learned a lot</p>



<p class="wp-block-paragraph">about making make files at this point.</p>



<p class="wp-block-paragraph">this point i hope you kind of like the idea let me just double check there&#8217;s nothing else i wanted</p>



<p class="wp-block-paragraph">to say for this video oh i should point out that gnu make is not the only build system available</p>



<p class="wp-block-paragraph">it&#8217;s just the one that i like the most um remember you can also put shortcuts in there like any</p>



<p class="wp-block-paragraph">command line that you could actually type could be part of the recipe of a target it doesn&#8217;t have</p>



<p class="wp-block-paragraph">to only build it doesn&#8217;t have to only be build targets so again you could make commands in there</p>



<p class="wp-block-paragraph">like deploy your executable somewhere or check something or like a long time ago I used to have</p>



<p class="wp-block-paragraph">a recipe actually it was that program I was talking about at the beginning where I converted</p>



<p class="wp-block-paragraph">an hour-long compilation to just like a minute I had another target in there called deploy so I&#8217;d</p>



<p class="wp-block-paragraph">say make deploy and what it would do is it would build and if it built then it would run unit tests</p>



<p class="wp-block-paragraph">on my code and if those succeeded then it would copy my source code to one of my other servers</p>



<p class="wp-block-paragraph">my other servers then remotely it would tell that other server to build and run tests and if all</p>



<p class="wp-block-paragraph">that succeeded you know if it didn&#8217;t succeed then it would just quit if all that succeeded then it</p>



<p class="wp-block-paragraph">would shut down the the server that I had written as a running service and then it would copy the</p>



<p class="wp-block-paragraph">freshly built executable to the right location and then it would restart the service so basically I</p>



<p class="wp-block-paragraph">just like do a bunch of coding and then I you know run my test if everything seems cool then I go make</p>



<p class="wp-block-paragraph">five minutes or whatever it took to run all the tests and do another compile and deploy everything</p>



<p class="wp-block-paragraph">and my server was just totally updated just by that so there&#8217;s a lot of stuff you can do but</p>



<p class="wp-block-paragraph">there are other great build systems out there there&#8217;s one called gradle there&#8217;s one called</p>



<p class="wp-block-paragraph">maven there&#8217;s other like node.js systems there&#8217;s a ton of build systems out there</p>



<p class="wp-block-paragraph">probably a slightly more popular popular c++ build system is called cmake it&#8217;s more tailored to c++</p>



<p class="wp-block-paragraph">um but you know you obviously don&#8217;t need to do it it&#8217;s just i think like a little bit easier</p>



<p class="wp-block-paragraph">depending on what you want to do so keep that in mind this is not the only system there&#8217;s a lot</p>



<p class="wp-block-paragraph">out there to explore but this is this is definitely a great first step um let&#8217;s see what else can i do</p>



<p class="wp-block-paragraph">oh we showed you the diagram showed you the info function and the targets and the dependencies</p>



<p class="wp-block-paragraph">and the run build well i guess i&#8217;m out of stuff to show you that&#8217;s that&#8217;s all i had written down</p>



<p class="wp-block-paragraph">that I wanted to show you maybe I could this is not a git video I&#8217;ll make you</p>



<p class="wp-block-paragraph">know I have other videos forget but you know if this is a git repository you</p>



<p class="wp-block-paragraph">would nano git ignore just because I kept mentioning this we&#8217;ll do nano git</p>



<p class="wp-block-paragraph">ignore and then I&#8217;ll just say ignore the build directory and ignore swap files so</p>



<p class="wp-block-paragraph">I&#8217;ll say like ignore the build directory and ignore anything that&#8217;s edited and</p>



<p class="wp-block-paragraph">your git status and git add and git commit and stuff then the build directory wouldn&#8217;t even show</p>



<p class="wp-block-paragraph">up so yeah kind of i guess it&#8217;s kind of unnecessary for this project okay i think that concludes this</p>



<p class="wp-block-paragraph">video assuming i was actually recording this entire time thank you so much for watching i</p>



<p class="wp-block-paragraph">hope you learned a little bit of stuff and had a little bit of fun i&#8217;ll see you in the next video</p>



<p class="wp-block-paragraph">practice practice practice and start making your own make file videos and let me know</p>



<p class="wp-block-paragraph">files in your own programs and let me know if you liked the content of this video and like if it</p>



<p class="wp-block-paragraph">helped you i love receiving emails way after the fact when people say hey i love make files now</p>



<p class="wp-block-paragraph">and it&#8217;s all because of you and i do it all the time because then i get to sit alone in my dark</p>



<p class="wp-block-paragraph">room and giggle to myself it&#8217;s all because of me um okay i think that&#8217;s probably a good note to</p>



<p class="wp-block-paragraph">hey everybody thanks for watching this video again from the bottom of my heart I really</p>



<p class="wp-block-paragraph">appreciate it I do hope you did learn something and have some fun if you could do me a please a</p>



<p class="wp-block-paragraph">small little favor could you please subscribe and follow this channel or these videos or whatever it</p>



<p class="wp-block-paragraph">is you do on the current social media website that you&#8217;re looking at right now it would really mean</p>



<p class="wp-block-paragraph">the world to me and it&#8217;ll help make more videos and grow this community so we&#8217;ll be able to do</p>



<p class="wp-block-paragraph">videos, longer videos, better videos, or just I&#8217;ll be able to keep making videos in general. So please</p>



<p class="wp-block-paragraph">do me a kindness and subscribe. You know, sometimes I&#8217;m sleeping in the middle of the night</p>



<p class="wp-block-paragraph">and I just wake up because I know somebody subscribed or followed. It just wakes me up</p>



<p class="wp-block-paragraph">and I get filled with joy. That&#8217;s exactly what happens every single time. So you could do it as</p>



<p class="wp-block-paragraph">a nice favor to me or you could you could troll me if you want to just wake me up in the middle</p>



<p class="wp-block-paragraph">of the night, just subscribe and then I&#8217;ll just wake up. I promise that&#8217;s what will happen.</p>



<p class="wp-block-paragraph">Also, if you look at the middle of the screen right now, you should see a QR code which you can scan in order to go to the website</p>



<p class="wp-block-paragraph">which I think is also named somewhere at the bottom of this video and</p>



<p class="wp-block-paragraph">It&#8217;ll take you to my main website where you can just kind of like see all the videos</p>



<p class="wp-block-paragraph">I published and the services and tutorials and things that I offer and all that good stuff and</p>



<p class="wp-block-paragraph">If you have a suggestion for</p>



<p class="wp-block-paragraph">Clarifications or errata or just future videos that you want to see</p>



<p class="wp-block-paragraph">please leave a comment or if you just want to say hey what&#8217;s up what&#8217;s going on you know just send</p>



<p class="wp-block-paragraph">me a comment whatever i also wake up for those in the middle of the night i get i wake up in a cold</p>



<p class="wp-block-paragraph">sweat and i&#8217;m like it would really it really mean the world to me i would really appreciate it so</p>



<p class="wp-block-paragraph">again thank you so much for watching this video and um enjoy the cool music</p>



<p class="wp-block-paragraph">as as i fade into the darkness which is coming for us all</p>



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/master-gnu-makefiles-streamline-coding-builds-with-c-c-assembly/">Master GNU Makefiles: Streamline Coding Builds with C++, C &amp; Assembly</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/master-gnu-makefiles-streamline-coding-builds-with-c-c-assembly/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Ultimate Beginner&#8217;s Guide to Linux Command Line: Ubuntu Terminal Basics &#038; More</title>
		<link>https://www.NeuralLantern.com/ultimate-beginners-guide-to-linux-command-line-ubuntu-terminal-basics-more/</link>
					<comments>https://www.NeuralLantern.com/ultimate-beginners-guide-to-linux-command-line-ubuntu-terminal-basics-more/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sun, 18 May 2025 05:18:19 +0000</pubDate>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Conversions]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[APT package manager]]></category>
		<category><![CDATA[C++ programming]]></category>
		<category><![CDATA[command line basics]]></category>
		<category><![CDATA[GCC compiler]]></category>
		<category><![CDATA[Linux desktop environment]]></category>
		<category><![CDATA[Linux file navigation]]></category>
		<category><![CDATA[Linux for beginners]]></category>
		<category><![CDATA[Linux tutorial]]></category>
		<category><![CDATA[Nano editor]]></category>
		<category><![CDATA[open source tools]]></category>
		<category><![CDATA[sudo command]]></category>
		<category><![CDATA[terminal commands]]></category>
		<category><![CDATA[terminal emulator]]></category>
		<category><![CDATA[Ubuntu terminal]]></category>
		<category><![CDATA[Vim tutorial]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=107</guid>

					<description><![CDATA[<p>Master Linux command line basics on Ubuntu! Learn terminal commands, file navigation, and more in this fun beginner guide.</p>
<p>The post <a href="https://www.NeuralLantern.com/ultimate-beginners-guide-to-linux-command-line-ubuntu-terminal-basics-more/">Ultimate Beginner&#8217;s Guide to Linux Command Line: Ubuntu Terminal Basics &amp; More</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe loading="lazy" title="Ultimate Beginner?s Guide to Linux Command Line: Ubuntu Terminal Basics &amp; More" width="1380" height="776" src="https://www.youtube.com/embed/2bhhH2ykaiE?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">Hey there, Linux newbies! Ready to unlock the power of the Linux command line? In this fun and approachable guide, we dive into the Ubuntu terminal to teach you the essentials of command-line magic. Perfect for beginners, this video covers everything from launching a terminal (like the awesome Terminator emulator) to mastering commands like ls, cd, mkdir, and rm. You’ll learn how to navigate the file system, create and delete files, edit code with Nano (sorry, Vim fans!), and even compile C++ programs with GCC. Plus, we’ll show you how to install cool programs like GIMP using apt and wield sudo like a pro. Whether you’re switching from a GUI or just curious about the terminal’s hacker vibes, this video is your gateway to a whole new world of open-source tools. Stick around till the end for a quick peek at graphical editing and a heartfelt call to join our community! Hit that subscribe button, scan the QR code to check out more tutorials, and let’s keep exploring Linux together. Drop a comment with your favorite command or what you want to learn next! #Linux #CommandLine #Ubuntu</p>



<p class="wp-block-paragraph">Introduction to Linux Command Line 00:00:00<br>Ubuntu Linux Terminal 00:00:04<br>Benefits of Terminal Usage 00:00:09<br>Desktop Environments (XFCE vs. GNOME) 00:01:07<br>Launching the Terminal 00:01:55<br>Terminal Emulator (Terminator) 00:02:06<br>Understanding the Shell (Bash) 00:04:00<br>Echo Command and Variables 00:04:06<br>Clear Command 00:07:34<br>Navigating File System (PWD) 00:08:21<br>Listing Directory Contents (LS) 00:08:56<br>Using Man Pages 00:10:37<br>Changing Directories (CD) 00:13:15<br>Creating Directories (MKDIR) 00:14:51<br>Going Up Directory Levels 00:15:57<br>Creating and Deleting Files (Touch, RM) 00:19:03<br>Editing Files with Nano 00:21:00<br>Editing Files with Vim 00:26:24<br>Installing Programs with APT 00:28:06<br>Using Sudo for Root Access 00:32:29<br>Updating and Upgrading System 00:34:54<br>Graphical File Editing 00:36:05<br>Compiling C++ Programs (GCC, G++) 00:39:53<br>Executing Programs 00:40:57<br>Conclusion and Subscription Call 00:43:04</p>



<p class="wp-block-paragraph">Thanks for watching!</p>



<p class="wp-block-paragraph">Find us on other social media here:</p>



<ul class="wp-block-list">
<li>https://www.NeuralLantern.com/social</li>
</ul>



<p class="wp-block-paragraph">Please help support us!</p>



<ul class="wp-block-list">
<li>Subscribing + Sharing on Social Media</li>



<li>Leaving a comment or suggestion</li>



<li>Subscribing to our Blog</li>



<li>Watching the main &#8220;pinned&#8221; video of this channel for offers and extras</li>
</ul>



<p class="wp-block-paragraph">Hello there. Today I&#8217;d like to show you a little bit about the Linux command line</p>



<p class="wp-block-paragraph">inside of a terminal. More specifically I&#8217;m going to be doing this on Ubuntu Linux.</p>



<p class="wp-block-paragraph">This is great for beginners to start to get to know how to issue commands and do</p>



<p class="wp-block-paragraph">things like that and if you&#8217;re used to doing everything in a GUI in a graphical</p>



<p class="wp-block-paragraph">user interface then you probably have no idea how much fun it is to actually</p>



<p class="wp-block-paragraph">work inside of a terminal. There are tons and tons of programs that you can gain</p>



<p class="wp-block-paragraph">can gain access to once you start getting more comfortable with the terminal.</p>



<p class="wp-block-paragraph">When you look around at the open source world and all the wonderful tools that people make,</p>



<p class="wp-block-paragraph">you&#8217;ll find out pretty quickly that a lot of programmers just write tools that only</p>



<p class="wp-block-paragraph">work with the command line.</p>



<p class="wp-block-paragraph">And you know, maybe later if someone else comes along and wants to add a graphical</p>



<p class="wp-block-paragraph">interface for it, then they do.</p>



<p class="wp-block-paragraph">But lots of times that doesn&#8217;t actually ever happen.</p>



<p class="wp-block-paragraph">And so you sort of open up a whole new world for yourself when you learn to use the terminal.</p>



<p class="wp-block-paragraph">when you learn to use the terminal.</p>



<p class="wp-block-paragraph">Anyway, and then you also look really cool like a hacker.</p>



<p class="wp-block-paragraph">So I&#8217;m on a desktop engine called XFCE</p>



<p class="wp-block-paragraph">or a desktop environment called XFCE.</p>



<p class="wp-block-paragraph">Most new Linux users who are on Ubuntu</p>



<p class="wp-block-paragraph">are probably looking at the GNOME desktop.</p>



<p class="wp-block-paragraph">So let me just say real fast,</p>



<p class="wp-block-paragraph">if you have a desktop that looks nothing like this</p>



<p class="wp-block-paragraph">and you think you&#8217;re on GNOME because you just installed vanilla Ubuntu or something,</p>



<p class="wp-block-paragraph">then you probably want to take a look at the top left corner of the screen</p>



<p class="wp-block-paragraph">for a little button called Activities,</p>



<p class="wp-block-paragraph">or at the bottom left of the screen for a button that I think is like nine dots.</p>



<p class="wp-block-paragraph">Both of those buttons will allow you to search for programs on the system.</p>



<p class="wp-block-paragraph">What you should do is basically click one of those buttons</p>



<p class="wp-block-paragraph">and then start typing in the word Terminal</p>



<p class="wp-block-paragraph">until you see a terminal pop up and then you can click on it</p>



<p class="wp-block-paragraph">and then you can launch it.</p>



<p class="wp-block-paragraph">and then you can, you can launch it. Okay. So for me though,</p>



<p class="wp-block-paragraph">I already have this set up on my desktop.</p>



<p class="wp-block-paragraph">So I&#8217;m going to click on my little terminal icon and I&#8217;m going to launch a</p>



<p class="wp-block-paragraph">terminal. For those of you who don&#8217;t know what terminal I&#8217;m using right now,</p>



<p class="wp-block-paragraph">this is called terminator. I think it&#8217;s really cool.</p>



<p class="wp-block-paragraph">I&#8217;m personally a huge fan of this terminal. Uh,</p>



<p class="wp-block-paragraph">the main reason is that it&#8217;s really easy and fast to split the panes.</p>



<p class="wp-block-paragraph">So you can do multiple, uh, sessions.</p>



<p class="wp-block-paragraph">If you&#8217;re connected to multiple remote machines at the same time, um,</p>



<p class="wp-block-paragraph">machines at the same time, you know, later in your career. It&#8217;s really convenient. It&#8217;s actually</p>



<p class="wp-block-paragraph">kind of broken right now a little bit, but not too bad. I still love it. Okay, so I open up a</p>



<p class="wp-block-paragraph">terminal. Technically, this is called a terminal emulator. The real terminal would just be like a</p>



<p class="wp-block-paragraph">completely black screen, and you wouldn&#8217;t be able to see anything else graphical. So this is sort of</p>



<p class="wp-block-paragraph">like a windowed program that runs another program under the hood that helps this program talk with</p>



<p class="wp-block-paragraph">talk with the operating system and it sort of performs two-way communication and shows you</p>



<p class="wp-block-paragraph">what the operating system is saying to you and doing and things like that. So,</p>



<p class="wp-block-paragraph">but for all intent and purpose, this is a, this is a terminal. I always call this a terminal.</p>



<p class="wp-block-paragraph">Okay. Let&#8217;s see. Maybe I need to increase the font size real fast. Um,</p>



<p class="wp-block-paragraph">I got a profiles out if I do mono space and I just do it like a little bit, a little bit bigger</p>



<p class="wp-block-paragraph">bigger than the default so it&#8217;s easier to watch on a video. Okay how about that is that better?</p>



<p class="wp-block-paragraph">I think that&#8217;s probably better. Okay so for starters uh you&#8217;re looking at a command line</p>



<p class="wp-block-paragraph">interface you&#8217;re looking at a terminal this is a terminal emulator program uh we have like a</p>



<p class="wp-block-paragraph">blinking cursor you can enter commands and stuff like that it&#8217;s important to understand at first</p>



<p class="wp-block-paragraph">that um you&#8217;re actually already inside of a program remember I said that the terminal emulator is a</p>



<p class="wp-block-paragraph">and it helps go between you and the operating system.</p>



<p class="wp-block-paragraph">There&#8217;s also another program that sort of interprets the things that you&#8217;re saying</p>



<p class="wp-block-paragraph">before sending that off to the operating system.</p>



<p class="wp-block-paragraph">The program is different depending on what environment you&#8217;re using,</p>



<p class="wp-block-paragraph">but in Ubuntu, it usually defaults to bash.</p>



<p class="wp-block-paragraph">So I&#8217;m going to type a quick command.</p>



<p class="wp-block-paragraph">We&#8217;ll explain what these commands do in a second.</p>



<p class="wp-block-paragraph">And I&#8217;m going to type echo shell,</p>



<p class="wp-block-paragraph">and that&#8217;s going to tell me what interpreter we&#8217;re using.</p>



<p class="wp-block-paragraph">So by default, we&#8217;re using an interpreter called bash.</p>



<p class="wp-block-paragraph">So if you hear anybody say, hey, I&#8217;m in bash or I got a bash script.</p>



<p class="wp-block-paragraph">Well, this is what it is.</p>



<p class="wp-block-paragraph">It&#8217;s a program that will be understood by bash.</p>



<p class="wp-block-paragraph">Okay, so what did I just type?</p>



<p class="wp-block-paragraph">I typed echo and then I typed a dollar sign and then I typed shell.</p>



<p class="wp-block-paragraph">So on the terminal, you know, you can type any command you want.</p>



<p class="wp-block-paragraph">It may not actually work, but you know, you can type.</p>



<p class="wp-block-paragraph">The way that your command is usually interpreted is if you type just one thing,</p>



<p class="wp-block-paragraph">then that&#8217;s considered the program that you want to execute.</p>



<p class="wp-block-paragraph">the program that you want to execute so if i type the word echo by itself and hit enter</p>



<p class="wp-block-paragraph">then bash or i&#8217;ll just say you know the shell or the terminal is going to look for a program named</p>



<p class="wp-block-paragraph">echo and if it finds it it&#8217;ll execute it um there&#8217;s a there&#8217;s a special way that it searches</p>



<p class="wp-block-paragraph">for programs like uh the the program echo for example it has to it has to go somewhere in the</p>



<p class="wp-block-paragraph">operating system right there has to be a path so if you type which echo you can see exactly where</p>



<p class="wp-block-paragraph">system so slash user slash bin slash echo so that&#8217;s where it is but i can just type echo by</p>



<p class="wp-block-paragraph">itself because the system knows how to go search through special system paths looking for the echo</p>



<p class="wp-block-paragraph">program that you typed so it can find the real location anyway so i type echo and this program</p>



<p class="wp-block-paragraph">launches and it doesn&#8217;t really do anything the thing about the echo program is if you just type</p>



<p class="wp-block-paragraph">actually receive what you typed after after the echo program executable name</p>



<p class="wp-block-paragraph">and it&#8217;ll just print it back to you.</p>



<p class="wp-block-paragraph">So what&#8217;s happening here is the bash interpreter, the shell,</p>



<p class="wp-block-paragraph">it&#8217;ll always take the first argument.</p>



<p class="wp-block-paragraph">We call these arguments, words or symbols separated by spaces.</p>



<p class="wp-block-paragraph">The first argument is echo.</p>



<p class="wp-block-paragraph">That&#8217;s considered the program that you want to run.</p>



<p class="wp-block-paragraph">And every argument after that is actually just sent into the program that you launch.</p>



<p class="wp-block-paragraph">thing that&#8217;s actually launching here is the echo program and then hello is a string that gets sent</p>



<p class="wp-block-paragraph">into the echo program you can do as many arguments as you want actually i don&#8217;t know if there&#8217;s like</p>



<p class="wp-block-paragraph">a huge limit huge limit you can probably type a lot of these before you run out and so i&#8217;ve typed</p>



<p class="wp-block-paragraph">three arguments technically the echo program is is argument zero the first argument but um i&#8217;ve</p>



<p class="wp-block-paragraph">typed out three arguments that will get sent into the echo program and you can see that echo received</p>



<p class="wp-block-paragraph">three of them and just printed them out and that&#8217;s it so it&#8217;s the echo program is pretty simple but</p>



<p class="wp-block-paragraph">if i if i type a dollar sign and i like actually let me just type shell by itself if i say echo</p>



<p class="wp-block-paragraph">shell it just prints the word shell because that&#8217;s interpreted as just like a regular string but if i</p>



<p class="wp-block-paragraph">put a dollar sign in front of it then bash considers that to be a variable and so what it&#8217;ll do is it&#8217;ll</p>



<p class="wp-block-paragraph">go into memory wherever the variables are stored and it&#8217;ll try to find a variable named shell</p>



<p class="wp-block-paragraph">variable named shell and if there is one it&#8217;ll take the value that&#8217;s inside of shell which in</p>



<p class="wp-block-paragraph">this case is just you know bash and it&#8217;ll convert the symbol dollar sign shell into</p>



<p class="wp-block-paragraph">the actual variable value and then it&#8217;ll print that it&#8217;ll send that into the echo command</p>



<p class="wp-block-paragraph">so if i say echo shell step one it looks for variable name shell step two it grabs bin bash</p>



<p class="wp-block-paragraph">and replaces that where the dollar sign shell was written and then it sends that into the echo program</p>



<p class="wp-block-paragraph">into the echo program.</p>



<p class="wp-block-paragraph">So now you know how to launch a program.</p>



<p class="wp-block-paragraph">Here&#8217;s another program.</p>



<p class="wp-block-paragraph">It&#8217;s called clear.</p>



<p class="wp-block-paragraph">If you just type the, you know, the command clear, then a program called clear gets launched.</p>



<p class="wp-block-paragraph">And all it does is just to help you clear the terminal.</p>



<p class="wp-block-paragraph">If you want to keep things a little clean, just to prove to you that this is a program,</p>



<p class="wp-block-paragraph">we can type which clear and notice how it actually has a path in your operating system.</p>



<p class="wp-block-paragraph">User bin clear.</p>



<p class="wp-block-paragraph">This will be different if you&#8217;re on a different operating system than mine, but it&#8217;s all okay.</p>



<p class="wp-block-paragraph">It&#8217;s all okay.</p>



<p class="wp-block-paragraph">All right.</p>



<p class="wp-block-paragraph">So where am I?</p>



<p class="wp-block-paragraph">Because you can see that I&#8217;m at some sort of a location.</p>



<p class="wp-block-paragraph">It says Mike at lectures.</p>



<p class="wp-block-paragraph">That sounds like the name of my computer and the name of my profile.</p>



<p class="wp-block-paragraph">But where am I in the file system?</p>



<p class="wp-block-paragraph">Because your computer is like, you know, a big file system.</p>



<p class="wp-block-paragraph">There&#8217;s lots of files and folders all over the place.</p>



<p class="wp-block-paragraph">Where is the terminal sitting?</p>



<p class="wp-block-paragraph">Is it sitting anywhere in the file system?</p>



<p class="wp-block-paragraph">It actually is.</p>



<p class="wp-block-paragraph">It&#8217;s sitting in your home directory by default, unless you&#8217;ve made some customizations.</p>



<p class="wp-block-paragraph">unless you&#8217;ve made some customizations, I can access the current working directory</p>



<p class="wp-block-paragraph">by typing the command PWD, print working directory.</p>



<p class="wp-block-paragraph">And again, this is a program and its whole job is just to print</p>



<p class="wp-block-paragraph">where the working directory currently is.</p>



<p class="wp-block-paragraph">So the working directory means where you&#8217;re currently at,</p>



<p class="wp-block-paragraph">where you&#8217;re situated, where you&#8217;re looking at.</p>



<p class="wp-block-paragraph">And it&#8217;s saying that I&#8217;m in my home folder.</p>



<p class="wp-block-paragraph">In Linux, the home folders are usually slash home slash your username.</p>



<p class="wp-block-paragraph">So if I want to see what&#8217;s inside of my home folder,</p>



<p class="wp-block-paragraph">I can use another program called LS, which just lists the contents of a folder.</p>



<p class="wp-block-paragraph">So I&#8217;m going to type LS and it tells me I&#8217;ve got all these folders,</p>



<p class="wp-block-paragraph">desktop documents, downloads and so forth.</p>



<p class="wp-block-paragraph">LS takes arguments.</p>



<p class="wp-block-paragraph">Remember, we have arguments like if we did echo hello,</p>



<p class="wp-block-paragraph">then it&#8217;ll print the word hello, but we can give the LS command some arguments too.</p>



<p class="wp-block-paragraph">We can say LS, I&#8217;d like you to do, you know, some stuff.</p>



<p class="wp-block-paragraph">So what do we want it to do?</p>



<p class="wp-block-paragraph">Let&#8217;s make it print all the files and folders,</p>



<p class="wp-block-paragraph">even those that might be hidden because they,</p>



<p class="wp-block-paragraph">on Linux, if a file or folder starts with a period</p>



<p class="wp-block-paragraph">in the name, it&#8217;ll usually be hidden by default.</p>



<p class="wp-block-paragraph">So if we want to print everything, we can say dash a.</p>



<p class="wp-block-paragraph">And if I want to print in a vertical list style,</p>



<p class="wp-block-paragraph">I can put an L in front of there.</p>



<p class="wp-block-paragraph">So I can say LS, which is the program</p>



<p class="wp-block-paragraph">and then dash LA is the arguments I give it.</p>



<p class="wp-block-paragraph">And that&#8217;s going to tell it to print my directory</p>



<p class="wp-block-paragraph">with all hidden files and folders shown.</p>



<p class="wp-block-paragraph">Notice how all this stuff showed up</p>



<p class="wp-block-paragraph">that wasn&#8217;t there before,</p>



<p class="wp-block-paragraph">like bash history.</p>



<p class="wp-block-paragraph">I have a cache folder.</p>



<p class="wp-block-paragraph">But then there was also some stuff</p>



<p class="wp-block-paragraph">that was there before,</p>



<p class="wp-block-paragraph">like the documents folder,</p>



<p class="wp-block-paragraph">the music and the pictures folder,</p>



<p class="wp-block-paragraph">and so forth.</p>



<p class="wp-block-paragraph">So you saw these things before.</p>



<p class="wp-block-paragraph">Like, let me just at least highlight one.</p>



<p class="wp-block-paragraph">So you saw the videos folder there before.</p>



<p class="wp-block-paragraph">You just didn&#8217;t see all those other hidden ones</p>



<p class="wp-block-paragraph">because they had dots</p>



<p class="wp-block-paragraph">in front of their file name.</p>



<p class="wp-block-paragraph">in front of their file name or folder name depending on what they are okay and</p>



<p class="wp-block-paragraph">then of course you can see that this is a vertical list and you&#8217;re getting a</p>



<p class="wp-block-paragraph">little bit better now at giving arguments to programs so how did we know</p>



<p class="wp-block-paragraph">that ls takes dash la as an argument or as some arguments you could search on</p>



<p class="wp-block-paragraph">the internet which is pretty fast usually you can also use a program</p>



<p class="wp-block-paragraph">called man the man program will give you information on another program most</p>



<p class="wp-block-paragraph">programs have MAN entries so when you install the program there there will be</p>



<p class="wp-block-paragraph">like a new manual page that shows up in the MAN program so I&#8217;m going to type MAN</p>



<p class="wp-block-paragraph">LS and hit enter I&#8217;m basically going to launch the MAN program and I&#8217;m going to</p>



<p class="wp-block-paragraph">tell it that I want information on the LS program so I hit enter and then it</p>



<p class="wp-block-paragraph">sort of shows me like a big you know little instruction thing a little sheet</p>



<p class="wp-block-paragraph">a little well it&#8217;s actually not little depending on the program this could be</p>



<p class="wp-block-paragraph">tells you all the things that we can do with this program. So right here you can see the</p>



<p class="wp-block-paragraph">dash LA part that we did earlier. Whoops, what did I do wrong? The dash LA part that we did earlier.</p>



<p class="wp-block-paragraph">That&#8217;s the dash A. And we could also instead have just said dash dash all.</p>



<p class="wp-block-paragraph">That&#8217;s what the manual is telling us. Where&#8217;s that dash L, the listing? Let&#8217;s see, it&#8217;s somewhere in</p>



<p class="wp-block-paragraph">here. H I J K L, maybe I should do a page down.</p>



<p class="wp-block-paragraph">Maybe I should do a page down.</p>



<p class="wp-block-paragraph">Yeah, there we go.</p>



<p class="wp-block-paragraph">So, well, there&#8217;s no dash dash list.</p>



<p class="wp-block-paragraph">I was hoping that there would be a dash dash list,</p>



<p class="wp-block-paragraph">but this tells you at least that you can say dash L to use a listing format.</p>



<p class="wp-block-paragraph">And there&#8217;s tons of other options that you can learn and read about</p>



<p class="wp-block-paragraph">if you just take some time to explore the man page.</p>



<p class="wp-block-paragraph">Kind of cool, right?</p>



<p class="wp-block-paragraph">Okay, so how do you get out of this?</p>



<p class="wp-block-paragraph">By the way, how do you search for stuff?</p>



<p class="wp-block-paragraph">I&#8217;m going to search by using the slash key.</p>



<p class="wp-block-paragraph">key so like you know the the web slash key I&#8217;m gonna hit slash and then I&#8217;m</p>



<p class="wp-block-paragraph">gonna type something I&#8217;m gonna say maybe block and then hit enter and notice how</p>



<p class="wp-block-paragraph">it highlights on the first match I can do a regular end to go down to the next</p>



<p class="wp-block-paragraph">match or I can do shift in like a capital N to go backwards up to the</p>



<p class="wp-block-paragraph">previous match so this helps you you know kind of search through man pages and</p>



<p class="wp-block-paragraph">things like that and the cool thing about what the man page is using right</p>



<p class="wp-block-paragraph">It&#8217;s using a way to display itself.</p>



<p class="wp-block-paragraph">I think it&#8217;s either using a program called less or it&#8217;s using a program that works very</p>



<p class="wp-block-paragraph">similarly to a program called less.</p>



<p class="wp-block-paragraph">So the program less, it&#8217;s just, it loads up a document for you and it lets you do things</p>



<p class="wp-block-paragraph">like this, scroll up and down, search for things, go to a line number, you know, and</p>



<p class="wp-block-paragraph">just, you know, it&#8217;s, it&#8217;s, it&#8217;s very convenient, right?</p>



<p class="wp-block-paragraph">Like it pages in the terminal.</p>



<p class="wp-block-paragraph">If you want to exit this, you just got to hit Q.</p>



<p class="wp-block-paragraph">So I hit Q right now.</p>



<p class="wp-block-paragraph">So I&#8217;m going to do man LS again, hit Q, and then I get out.</p>



<p class="wp-block-paragraph">So now we know a few commands.</p>



<p class="wp-block-paragraph">We know how to see where we&#8217;re at in the file system and list directories and things like that.</p>



<p class="wp-block-paragraph">Let&#8217;s go into the documents directory with a special command called CD.</p>



<p class="wp-block-paragraph">So CD stands for change directory.</p>



<p class="wp-block-paragraph">And if I just say documents and hit enter, now the shell itself is inside of a different folder.</p>



<p class="wp-block-paragraph">It was in my home folder before.</p>



<p class="wp-block-paragraph">Now it&#8217;s in my documents folder.</p>



<p class="wp-block-paragraph">If you&#8217;re ever unsure of where you are, use the PWD command again to figure out what&#8217;s going on.</p>



<p class="wp-block-paragraph">Okay. Oh, look, I am inside of my documents folder.</p>



<p class="wp-block-paragraph">If you ever find yourself in some sort of a deep, deep subfolder, let&#8217;s see.</p>



<p class="wp-block-paragraph">I don&#8217;t even let&#8217;s do like user live live.</p>



<p class="wp-block-paragraph">LiveX32.</p>



<p class="wp-block-paragraph">Oops.</p>



<p class="wp-block-paragraph">What am I doing?</p>



<p class="wp-block-paragraph">There we go.</p>



<p class="wp-block-paragraph">What about this library?</p>



<p class="wp-block-paragraph">I&#8217;m just going into a random folder right now just to show you that we can go pretty</p>



<p class="wp-block-paragraph">deep.</p>



<p class="wp-block-paragraph">So I think that I&#8217;ve reached the end of that.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">So suppose I&#8217;m navigating around and I&#8217;m in some, some kind of a folder and I&#8217;m at,</p>



<p class="wp-block-paragraph">I do PWD and it says, oh no, you&#8217;re like way deep in some other folder.</p>



<p class="wp-block-paragraph">How do I get back to my home folder?</p>



<p class="wp-block-paragraph">Well, you could type out the whole home folder if you wanted to, but the easiest way to get</p>



<p class="wp-block-paragraph">pwd with no arguments.</p>



<p class="wp-block-paragraph">Once you hit enter, it&#8217;ll drop back down to your home folder.</p>



<p class="wp-block-paragraph">And if you&#8217;re not sure, then use the pwd command.</p>



<p class="wp-block-paragraph">Okay, so we&#8217;re doing pretty well.</p>



<p class="wp-block-paragraph">We&#8217;re kind of like navigating in here.</p>



<p class="wp-block-paragraph">Let&#8217;s make a directory.</p>



<p class="wp-block-paragraph">I&#8217;m going to go into my documents folder again.</p>



<p class="wp-block-paragraph">And let&#8217;s see.</p>



<p class="wp-block-paragraph">So right here I&#8217;ve got like, whoops, I&#8217;ve got some documents.</p>



<p class="wp-block-paragraph">Let me make a directory called temp with the command make directory.</p>



<p class="wp-block-paragraph">so uh well mkdir is the name of the program the first argument i gave it was temp and so it just</p>



<p class="wp-block-paragraph">created a folder for me called temp so if i say cd temp i can now go into the folder that i just</p>



<p class="wp-block-paragraph">created if i list the contents of that directory again it&#8217;s empty because i just made it pwd lets</p>



<p class="wp-block-paragraph">me know where i am just to make sure when you&#8217;re new to the terminal you actually i still use this</p>



<p class="wp-block-paragraph">customize my terminal so it doesn&#8217;t print the full the full path there it just prints the current</p>



<p class="wp-block-paragraph">directory name so i kind of get lost sometimes so you just use the pwd command to figure out where</p>



<p class="wp-block-paragraph">you are and by the way just as a reminder we could always do man and the name of a program so i&#8217;m</p>



<p class="wp-block-paragraph">going to say man make dir and there&#8217;s options even for making a directory i&#8217;m not going to go over</p>



<p class="wp-block-paragraph">those but just to let you know there&#8217;s a lot to explore okay so now i&#8217;m inside of the temp directory</p>



<p class="wp-block-paragraph">I&#8217;ve made a folder. What if I want to go one level up? What if I don&#8217;t exactly want to drop</p>



<p class="wp-block-paragraph">to the home directory, but maybe I went one level too deep and I want to go back up one level.</p>



<p class="wp-block-paragraph">Well, again, I could type out the whole thing. I could say go home and I could say documents</p>



<p class="wp-block-paragraph">and whatever. But by the way, I&#8217;m hitting control C when you see that care at C that usually tries</p>



<p class="wp-block-paragraph">to get the current program to stop. But when you&#8217;re inside of bash, it&#8217;ll just sort of like</p>



<p class="wp-block-paragraph">abort the current command and go to another line.</p>



<p class="wp-block-paragraph">Okay, so how do I go up one level?</p>



<p class="wp-block-paragraph">Well, in Linux, there are two special directories</p>



<p class="wp-block-paragraph">that have periods in the name, well, they are periods.</p>



<p class="wp-block-paragraph">The directory known as period,</p>



<p class="wp-block-paragraph">actually, let me show you the full,</p>



<p class="wp-block-paragraph">yeah, okay, well, the empty directory listing,</p>



<p class="wp-block-paragraph">notice how it actually does show me two things.</p>



<p class="wp-block-paragraph">It doesn&#8217;t show me nothing,</p>



<p class="wp-block-paragraph">it shows me these two directories right here,</p>



<p class="wp-block-paragraph">that&#8217;s not a mistake.</p>



<p class="wp-block-paragraph">So this directory, the one with just one period, that always represents the current directory</p>



<p class="wp-block-paragraph">that you&#8217;re in.</p>



<p class="wp-block-paragraph">So if I use just a period to go into a directory or to do something to a directory, that period</p>



<p class="wp-block-paragraph">will represent something different based on where I am.</p>



<p class="wp-block-paragraph">Am I in my home folder?</p>



<p class="wp-block-paragraph">Am I in the desktop?</p>



<p class="wp-block-paragraph">Am I somewhere else?</p>



<p class="wp-block-paragraph">The period changes based on where you are.</p>



<p class="wp-block-paragraph">dot it always means i&#8217;m getting used to this new pen setup it always means it always means there we</p>



<p class="wp-block-paragraph">go it looks like a emo guy with his hair like to the side um it always means the parent directory</p>



<p class="wp-block-paragraph">so remember before we could type we could type cd and then some directory name right to go into a</p>



<p class="wp-block-paragraph">directory uh now we can type cd dot dot and that&#8217;s basically saying we would like to change directories</p>



<p class="wp-block-paragraph">change directories, we would like to go to the documents directory.</p>



<p class="wp-block-paragraph">Why?</p>



<p class="wp-block-paragraph">Because the documents directory is the parent directory of the temp directory.</p>



<p class="wp-block-paragraph">So if I say cd dot dot, notice how it goes up one level.</p>



<p class="wp-block-paragraph">Let&#8217;s do that again just to be sure.</p>



<p class="wp-block-paragraph">So I&#8217;m going to say pwd, and if I say cd dot dot, and then pwd again,</p>



<p class="wp-block-paragraph">notice how we were in temp, and as soon as we went up one level,</p>



<p class="wp-block-paragraph">it went to documents.</p>



<p class="wp-block-paragraph">So it&#8217;s just kind of a quick way.</p>



<p class="wp-block-paragraph">you know, use a bunch of directory names separated by slashes.</p>



<p class="wp-block-paragraph">You can also put dot dot in any directory that you want.</p>



<p class="wp-block-paragraph">So like imagine I&#8217;m in the temp directory again.</p>



<p class="wp-block-paragraph">I could say let&#8217;s go up one directory and then a slash and then up another directory</p>



<p class="wp-block-paragraph">and then a slash and then up another directory.</p>



<p class="wp-block-paragraph">And I should end up in the home folder.</p>



<p class="wp-block-paragraph">Isn&#8217;t that kind of funny, right?</p>



<p class="wp-block-paragraph">So I&#8217;m saying like give me the parent directory of the current directory</p>



<p class="wp-block-paragraph">and then give me its parent directory and then give me its parent directory.</p>



<p class="wp-block-paragraph">So I went up three levels.</p>



<p class="wp-block-paragraph">its parent directory. So I went up three levels.</p>



<p class="wp-block-paragraph">So let me drop to my home folder and go back into documents and go back into</p>



<p class="wp-block-paragraph">temp. Whoops.</p>



<p class="wp-block-paragraph">I forgot to do CD.</p>



<p class="wp-block-paragraph">Now we&#8217;re getting pretty good at navigating. Let me make another directory.</p>



<p class="wp-block-paragraph">I&#8217;ll call it delete me because I intend to delete this directory.</p>



<p class="wp-block-paragraph">There&#8217;s a program called RM remove that lets you delete stuff.</p>



<p class="wp-block-paragraph">Actually first, before we delete that, let&#8217;s use a program called touch.</p>



<p class="wp-block-paragraph">and the program touch just sort of like creates a blank file.</p>



<p class="wp-block-paragraph">I think if the file already exists, it won&#8217;t mess with the contents,</p>



<p class="wp-block-paragraph">but let&#8217;s do an experiment in a moment.</p>



<p class="wp-block-paragraph">So I&#8217;m going to say touch blank file.</p>



<p class="wp-block-paragraph">It should create a file for me called blank file.</p>



<p class="wp-block-paragraph">So now I&#8217;ve got a directory and a file called blank file.</p>



<p class="wp-block-paragraph">Now I can remove the blank file with the RM command.</p>



<p class="wp-block-paragraph">So just RM and then give it the name of the file.</p>



<p class="wp-block-paragraph">Be careful with RM.</p>



<p class="wp-block-paragraph">He&#8217;ll destroy your file system if you&#8217;re not careful.</p>



<p class="wp-block-paragraph">and now let&#8217;s remove the delete me folder when you try to remove folders you have to tell the</p>



<p class="wp-block-paragraph">remove command that you intend to delete a folder by specifying also the dash r command which means</p>



<p class="wp-block-paragraph">this is a folder i would like you to recursively delete it so let me just type it without that</p>



<p class="wp-block-paragraph">real fast and it says hey i can&#8217;t do it it&#8217;s a directory so i&#8217;m going to say all right now</p>



<p class="wp-block-paragraph">And it did it.</p>



<p class="wp-block-paragraph">Some other useful flags you might want in the future.</p>



<p class="wp-block-paragraph">The first one that I like is V for Verbo.</p>



<p class="wp-block-paragraph">So it&#8217;ll print everything that it deletes.</p>



<p class="wp-block-paragraph">And F for Force.</p>



<p class="wp-block-paragraph">If you&#8217;re absolutely sure that you know exactly what you&#8217;re about to delete,</p>



<p class="wp-block-paragraph">then Force will make it so that this program won&#8217;t start asking you,</p>



<p class="wp-block-paragraph">are you sure? Are you sure? Are you sure?</p>



<p class="wp-block-paragraph">So it&#8217;s kind of dangerous, but it&#8217;s also pretty convenient.</p>



<p class="wp-block-paragraph">Imagine that.</p>



<p class="wp-block-paragraph">Anyway, so let&#8217;s see what else can I when I talk about here, we know how to like touch to create a blank file and create a folder and navigate all around. Let&#8217;s edit a file. Let&#8217;s actually edit a file in the terminal. So there&#8217;s kind of like an age old argument between the Vim people, or the V people, and the nano people. And so I just want to say that if you were a Vim person, don&#8217;t ever talk to me again for the rest of your life.</p>



<p class="wp-block-paragraph">again for the rest of your life just kidding you&#8217;re okay we can sort of be</p>



<p class="wp-block-paragraph">friends but I&#8217;m personally a nano person so what am I talking about nano is just</p>



<p class="wp-block-paragraph">another program it may or may not be on your system I think on a boon to it</p>



<p class="wp-block-paragraph">should be there by default let me just double check yeah it should be there by</p>



<p class="wp-block-paragraph">default we&#8217;ll talk about how to install programs in a second I&#8217;ll go sudo apt</p>



<p class="wp-block-paragraph">install just to remind myself but so you type nano to execute the nano program</p>



<p class="wp-block-paragraph">of a file that you want to edit.</p>



<p class="wp-block-paragraph">So let&#8217;s edit a file called my program.</p>



<p class="wp-block-paragraph">Whoops, program.cpp, just if you&#8217;re writing some code.</p>



<p class="wp-block-paragraph">And this tells the nano program that you would like</p>



<p class="wp-block-paragraph">to edit this file named my program.cpp.</p>



<p class="wp-block-paragraph">You hit enter and you have like a nice little editor</p>



<p class="wp-block-paragraph">that shows up.</p>



<p class="wp-block-paragraph">Notice at the bottom,</p>



<p class="wp-block-paragraph">you have a bunch of little shortcuts, right?</p>



<p class="wp-block-paragraph">So if you do, actually let&#8217;s look at this one</p>



<p class="wp-block-paragraph">Actually, let&#8217;s look at this one over here first.</p>



<p class="wp-block-paragraph">If you hit control O, that means save the file, write it out.</p>



<p class="wp-block-paragraph">If you hit control X, that means you&#8217;d like to exit the editor.</p>



<p class="wp-block-paragraph">So if I want to get rid of the editor and just like, you know, go back to the terminal,</p>



<p class="wp-block-paragraph">the normal command line, I&#8217;ll do control X.</p>



<p class="wp-block-paragraph">There&#8217;s a bunch of other stuff you can do.</p>



<p class="wp-block-paragraph">And there&#8217;s like a big help menu.</p>



<p class="wp-block-paragraph">alt n to see line numbers in nano so that makes it a lot more convenient for coding so i&#8217;m going</p>



<p class="wp-block-paragraph">to do alt n to get those lines off let me just type the word hello real fast hello</p>



<p class="wp-block-paragraph">okay so now i want to save this let&#8217;s do uh we can do control o to just save it but we&#8217;ll stay</p>



<p class="wp-block-paragraph">inside of the editor or we can do control x to save it and then exit the editor so i think i&#8217;m</p>



<p class="wp-block-paragraph">going to exit them say control x notice how at the bottom it asks me do i want to save the modified</p>



<p class="wp-block-paragraph">That just means I&#8217;ve been editing inside of this like, you know, temporary area.</p>



<p class="wp-block-paragraph">Do I want to actually save it?</p>



<p class="wp-block-paragraph">So I&#8217;m going to hit Y for yes.</p>



<p class="wp-block-paragraph">Then it asks me, you know, what&#8217;s the name of the file that you want to save?</p>



<p class="wp-block-paragraph">Well, since I specified my program when I launched Nano, it already knows what I want to do.</p>



<p class="wp-block-paragraph">If you didn&#8217;t specify the name of a file, then you could provide it here.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to hit enter.</p>



<p class="wp-block-paragraph">And now the program exits.</p>



<p class="wp-block-paragraph">If I list the contents of the directory, I can see that I now have</p>



<p class="wp-block-paragraph">the world&#8217;s worst C++ program ever because it&#8217;s just hello that&#8217;s not going</p>



<p class="wp-block-paragraph">to compile so how do I see the contents of a file with the terminal well for</p>



<p class="wp-block-paragraph">starters obviously you could just type the name of the program again for nano</p>



<p class="wp-block-paragraph">and it&#8217;ll show you there it is I&#8217;m gonna hit ctrl X to exit out of it but</p>



<p class="wp-block-paragraph">there&#8217;s another popular command that people like to use called cat cat</p>



<p class="wp-block-paragraph">basically will go to a file load it into memory and spill it onto the terminal</p>



<p class="wp-block-paragraph">to the terminal for you. I mean really what it does is it prints to something called standard</p>



<p class="wp-block-paragraph">output and then the shell interpreter grabs standard output and it you know renders it to</p>



<p class="wp-block-paragraph">the terminal but we&#8217;ll just say that this prints it to the terminal. So if I say cat and the name</p>



<p class="wp-block-paragraph">of my program then it prints it to the terminal so you can check any program this way. Do yourself</p>



<p class="wp-block-paragraph">a favor well do me a favor and do cat at the following path etc os release. The etc</p>



<p class="wp-block-paragraph">The etc directory off of the root of the file system in Linux is usually where all of the</p>



<p class="wp-block-paragraph">configuration files get stored.</p>



<p class="wp-block-paragraph">At least the ones that are system wide.</p>



<p class="wp-block-paragraph">So like system wide programs, their configurations are usually in the etc folder.</p>



<p class="wp-block-paragraph">So there&#8217;s a special file in many operating systems, definitely Ubuntu, called OS release,</p>



<p class="wp-block-paragraph">which just describes the operating system to you.</p>



<p class="wp-block-paragraph">So here, if you&#8217;re not sure what operating system you&#8217;re using, or if you just want to</p>



<p class="wp-block-paragraph">and kind of see information on it.</p>



<p class="wp-block-paragraph">Well, you can say cat, etc.</p>



<p class="wp-block-paragraph">OS release and see your OS.</p>



<p class="wp-block-paragraph">So there it is, all this stuff.</p>



<p class="wp-block-paragraph">Pretty fun.</p>



<p class="wp-block-paragraph">Okay, so we did my program.</p>



<p class="wp-block-paragraph">Let&#8217;s edit my program real fast.</p>



<p class="wp-block-paragraph">I&#8217;m going to go myprogram.cvp.</p>



<p class="wp-block-paragraph">And if I want to just say, I don&#8217;t know,</p>



<p class="wp-block-paragraph">maybe I want to make this look a little bit more like a program.</p>



<p class="wp-block-paragraph">So I can say integer main and we&#8217;ll just pretend that we&#8217;re not going to do any arguments.</p>



<p class="wp-block-paragraph">Return zero.</p>



<p class="wp-block-paragraph">So this probably would compile.</p>



<p class="wp-block-paragraph">I think this would compile.</p>



<p class="wp-block-paragraph">If not, then you might have to go into the number of arguments and then…</p>



<p class="wp-block-paragraph">Don&#8217;t worry about this.</p>



<p class="wp-block-paragraph">This is not a programming video.</p>



<p class="wp-block-paragraph">A character pointer.</p>



<p class="wp-block-paragraph">I can never remember if the brackets go before or after the variable name.</p>



<p class="wp-block-paragraph">a new program i usually compile it both ways and see which one works um okay so oh i did it too</p>



<p class="wp-block-paragraph">fast okay so i edited and uh if i want to just save my changes i&#8217;m going to say control o</p>



<p class="wp-block-paragraph">notice how it asked me again at the bottom do you want to save it under the same name i just say</p>



<p class="wp-block-paragraph">enter to say yes if i uh wanted to instead just exit the program i do control x and then</p>



<p class="wp-block-paragraph">inside a weird area where you can&#8217;t really hit keys and you can&#8217;t exit very</p>



<p class="wp-block-paragraph">well you might be inside of Vim some some operating system use Vim as the</p>



<p class="wp-block-paragraph">default or some some programs so I&#8217;m gonna just enter Vim manually whoops</p>



<p class="wp-block-paragraph">what am I doing is it Vim or V so I&#8217;m not a Vim user okay there we go so Vim is</p>



<p class="wp-block-paragraph">like you know it&#8217;s very complicated some people say it&#8217;s lightning fast and it&#8217;s</p>



<p class="wp-block-paragraph">By the time you need so many features,</p>



<p class="wp-block-paragraph">you might as well just mount the remote file system</p>



<p class="wp-block-paragraph">and use an actual graphical editor.</p>



<p class="wp-block-paragraph">I&#8217;m just not a fan.</p>



<p class="wp-block-paragraph">Don&#8217;t hate me.</p>



<p class="wp-block-paragraph">You know, we can still be friends.</p>



<p class="wp-block-paragraph">So if you&#8217;re inside of Vim, you hit the insert key</p>



<p class="wp-block-paragraph">and then you can kind of like type and stuff like that.</p>



<p class="wp-block-paragraph">So it&#8217;s whatever, but what?</p>



<p class="wp-block-paragraph">Insert?</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">I&#8217;m getting lost already inside of Vim.</p>



<p class="wp-block-paragraph">I&#8217;m just going to delete this stuff that I created and so if you want to exit from</p>



<p class="wp-block-paragraph">Vim hit the escape key first to make sure you&#8217;re not inside of insert mode or any</p>



<p class="wp-block-paragraph">special mode and then say shift holen to enter command mode you&#8217;ll know you&#8217;re in</p>



<p class="wp-block-paragraph">command mode because you see this little colon here next to your prompt or next</p>



<p class="wp-block-paragraph">to a prompt and then I&#8217;m gonna say write quit write quit means save the file and</p>



<p class="wp-block-paragraph">and then quit if you want to quit without saving the file you can just put q but uh vim will</p>



<p class="wp-block-paragraph">complain if you&#8217;ve actually changed something and you&#8217;re refusing to save the changes so if you are</p>



<p class="wp-block-paragraph">absolutely sure you want to discard the changes just say yes i want to quit with an exclamation</p>



<p class="wp-block-paragraph">point so q exclamation hit enter now you&#8217;re out of vim hopefully you&#8217;ll never go back for the rest</p>



<p class="wp-block-paragraph">of your life sorry okay so now we know you know a lot of a lot of stuff that we can do in the</p>



<p class="wp-block-paragraph">Maybe we should learn how to install programs real fast or search for programs.</p>



<p class="wp-block-paragraph">And then we&#8217;ll do a little bit of some graphical stuff.</p>



<p class="wp-block-paragraph">Alright, so here&#8217;s the command that I wanted to remind myself of.</p>



<p class="wp-block-paragraph">So how do we search for programs?</p>



<p class="wp-block-paragraph">If you didn&#8217;t know this already, almost every single Linux distribution has a repository</p>



<p class="wp-block-paragraph">of pre-compiled programs that are open source that you can use for free.</p>



<p class="wp-block-paragraph">better and a lot safer than the old Windows method of just sort of like going</p>



<p class="wp-block-paragraph">to random websites online and downloading programs and just kind of crossing your</p>



<p class="wp-block-paragraph">fingers that you didn&#8217;t just download a virus.</p>



<p class="wp-block-paragraph">What happens is the people who run the operating system, they&#8217;ll take the source</p>



<p class="wp-block-paragraph">code for popular programs and packages.</p>



<p class="wp-block-paragraph">They&#8217;ll compile it for you.</p>



<p class="wp-block-paragraph">They&#8217;ll store the binaries, which are just the compiled executable files.</p>



<p class="wp-block-paragraph">And then you can use certain command line tools to install those programs one by one.</p>



<p class="wp-block-paragraph">those programs one by one there&#8217;s so many available that it wouldn&#8217;t make sense to install them all</p>



<p class="wp-block-paragraph">by default because you&#8217;ll probably never use the vast majority but so we have a nice package</p>



<p class="wp-block-paragraph">manager in ubuntu called apt it&#8217;s the apt package manager if you want to see more information about</p>



<p class="wp-block-paragraph">it let&#8217;s see is it called aptitude or just apt we can say man apt yeah it&#8217;s just a command line</p>



<p class="wp-block-paragraph">interface this actually i think this talks to d package under the hood but you know it&#8217;s just a</p>



<p class="wp-block-paragraph">the package manager one of the sub commands for apt is search so we can say uh launch the apt</p>



<p class="wp-block-paragraph">program with apt then we could say apt i would like you to search and what would you like app</p>



<p class="wp-block-paragraph">to search for i don&#8217;t know how about a program called mousepad it&#8217;s one of my favorite text</p>



<p class="wp-block-paragraph">editors on linux so what it does is it searches the ubuntu repositories and it tries to find you</p>



<p class="wp-block-paragraph">know a package or a program that matches and if it does it&#8217;ll show you the listing okay so what do i</p>



<p class="wp-block-paragraph">listing. Okay, so what do I have here? Mousepad is already installed on this system. Yeah,</p>



<p class="wp-block-paragraph">that makes sense because I think I was just using it. And, you know, some other stuff that</p>



<p class="wp-block-paragraph">you could find. So you can just kind of search for for anything like do you want a free accounting</p>



<p class="wp-block-paragraph">program that you don&#8217;t have to pay for? It&#8217;s not necessarily going to be the best, you know,</p>



<p class="wp-block-paragraph">but it&#8217;s free and it works and it&#8217;s good and a lot of people swear by it. Well, you can search</p>



<p class="wp-block-paragraph">and there it is i don&#8217;t have it installed on this machine but new cache free accounting software</p>



<p class="wp-block-paragraph">do you want to learn to make memes against your enemies well there&#8217;s a program for that called</p>



<p class="wp-block-paragraph">gimp it&#8217;s basically it&#8217;s kind of like at this point i think an old school photoshop clone</p>



<p class="wp-block-paragraph">not clone but alternative it&#8217;s really good for memes and there are actually a lot of very</p>



<p class="wp-block-paragraph">talented people who use gimp to do like very artistic things so there it is right there gimp</p>



<p class="wp-block-paragraph">and it&#8217;s GIMP because it&#8217;s the GNU image manipulation program.</p>



<p class="wp-block-paragraph">There&#8217;s also another one that&#8217;s a little bit more artistic, I think.</p>



<p class="wp-block-paragraph">I haven&#8217;t used it.</p>



<p class="wp-block-paragraph">I think I used it once.</p>



<p class="wp-block-paragraph">It&#8217;s called Krita.</p>



<p class="wp-block-paragraph">Oops, sorry, not apt-Krita, apt-search-Krita.</p>



<p class="wp-block-paragraph">And there it is.</p>



<p class="wp-block-paragraph">So there&#8217;s like a bunch of different choices for any idea that you could have.</p>



<p class="wp-block-paragraph">Just think of what you want.</p>



<p class="wp-block-paragraph">You want another browser, another image editor.</p>



<p class="wp-block-paragraph">You want accounting software.</p>



<p class="wp-block-paragraph">accounting software you want an audio let&#8217;s see is there I think there&#8217;s one called our door let</p>



<p class="wp-block-paragraph">me see apt search you want to like mix music at home so I want to type the name of the program</p>



<p class="wp-block-paragraph">our door but I want to see if I can find it by just searching for a music term let&#8217;s say a</p>



<p class="wp-block-paragraph">DAW digital audio workstation let me scroll up a little bit yeah there it is okay so I searched</p>



<p class="wp-block-paragraph">program that came up right here it&#8217;s like a very very very popular free and open source</p>



<p class="wp-block-paragraph">digital audio workstation with like so many tracks that you can mix and and effects and</p>



<p class="wp-block-paragraph">you can record with it and do all these crazy things um so i&#8217;m just trying to show you that</p>



<p class="wp-block-paragraph">linux is not just for you know coding and and boring stuff there&#8217;s there&#8217;s a lot of fun stuff</p>



<p class="wp-block-paragraph">on linux that you can access for free uh through these repositories okay so let&#8217;s actually install</p>



<p class="wp-block-paragraph">Suppose I&#8217;m ready to make memes against my enemies.</p>



<p class="wp-block-paragraph">So I&#8217;m going to say sudo apt install instead of search install.</p>



<p class="wp-block-paragraph">And I&#8217;m just going to type the name of the program GIMP.</p>



<p class="wp-block-paragraph">Oh wait, hang on.</p>



<p class="wp-block-paragraph">I&#8217;m not supposed to show you sudo just yet.</p>



<p class="wp-block-paragraph">So let&#8217;s do sudo, let&#8217;s do apt install GIMP.</p>



<p class="wp-block-paragraph">By the way, sudo is supposedly outdated and people are saying you should use something</p>



<p class="wp-block-paragraph">else, but I don&#8217;t know.</p>



<p class="wp-block-paragraph">Old habits die hard.</p>



<p class="wp-block-paragraph">apt install GIMP, the system is telling me that I don&#8217;t have permission to install a program</p>



<p class="wp-block-paragraph">on this machine. And that makes sense. That&#8217;s probably a good thing, right? You don&#8217;t want to</p>



<p class="wp-block-paragraph">just let any user totally, you know, redo your system. So it&#8217;s saying, you know, could not open</p>



<p class="wp-block-paragraph">the lock file permission denied. Oh, no. Unable to acquire the d package front end lock. Are you</p>



<p class="wp-block-paragraph">root? Oh, okay. So what this is basically saying is that in order for us to do root level activities,</p>



<p class="wp-block-paragraph">like install a program on the system, we need to elevate the command line to root.</p>



<p class="wp-block-paragraph">And how we do that is we pretty much just say sudo, which is the name of a program that</p>



<p class="wp-block-paragraph">helps us quickly elevate. It also actually does like a lot of other stuff, but</p>



<p class="wp-block-paragraph">for now, we&#8217;re just going to use it to elevate the command up to root.</p>



<p class="wp-block-paragraph">So if I say sudo apt install gimp, what&#8217;s happening is the sudo program gets invoked,</p>



<p class="wp-block-paragraph">and then it just executes apt install GIMP as root.</p>



<p class="wp-block-paragraph">Let me just prove to you that sudo will elevate a command.</p>



<p class="wp-block-paragraph">So if I go, who am I?</p>



<p class="wp-block-paragraph">It&#8217;ll tell you the name of the current user.</p>



<p class="wp-block-paragraph">If I say sudo who am I,</p>



<p class="wp-block-paragraph">then sudo will launch who am I as the root user.</p>



<p class="wp-block-paragraph">And then who am I should tell us,</p>



<p class="wp-block-paragraph">whoops, got to enter the sudo password.</p>



<p class="wp-block-paragraph">You actually have to be an admin to use sudo, just FYI.</p>



<p class="wp-block-paragraph">So if I say sudo who am I, notice how it prints root.</p>



<p class="wp-block-paragraph">So if I say sudo apt install gimp, it&#8217;s really just going to invoke apt install gimp as the</p>



<p class="wp-block-paragraph">root user and it should allow me to install that program.</p>



<p class="wp-block-paragraph">Gimp is already installed.</p>



<p class="wp-block-paragraph">Okay, I guess I was making memes earlier and I forgot about it.</p>



<p class="wp-block-paragraph">Well we could remove it.</p>



<p class="wp-block-paragraph">Gimp.</p>



<p class="wp-block-paragraph">Then it removes it.</p>



<p class="wp-block-paragraph">Yes.</p>



<p class="wp-block-paragraph">I don&#8217;t think I was making memes on this machine.</p>



<p class="wp-block-paragraph">I think something funny is going on here.</p>



<p class="wp-block-paragraph">And now that it&#8217;s removed, I could install it again if I wanted to.</p>



<p class="wp-block-paragraph">I could say sudo apt install Gimp, and then it might ask you to push yes and enter.</p>



<p class="wp-block-paragraph">And then it just kind of finishes.</p>



<p class="wp-block-paragraph">Also if when you&#8217;re trying to install things, you get a message that says, repository could</p>



<p class="wp-block-paragraph">like a 404 error cannot be connected to not found your repos out of date you know whatever that</p>



<p class="wp-block-paragraph">might just mean you need to update your system so i&#8217;m going to say sudo apt update telling apt that</p>



<p class="wp-block-paragraph">i would like to update its idea of all the packages and then sudo apt upgrade</p>



<p class="wp-block-paragraph">so update just contacts the server and gets an idea of what packages there are and their versions</p>



<p class="wp-block-paragraph">the system or it actually upgrades the system when you&#8217;re done with that you</p>



<p class="wp-block-paragraph">usually want to do auto remove to just kind of get rid of any junk that&#8217;s left</p>



<p class="wp-block-paragraph">over if you happen to remove things recently this stuff up here this is sort</p>



<p class="wp-block-paragraph">of like a corporate upsell you can probably ignore that at least for now</p>



<p class="wp-block-paragraph">but yeah so we know how to like do lots of stuff in the terminal just just to</p>



<p class="wp-block-paragraph">open up the let&#8217;s see we&#8217;re inside of the temp folder okay so I have the temp</p>



<p class="wp-block-paragraph">folder inside the terminal I&#8217;m gonna open up my file system here and I&#8217;m gonna</p>



<p class="wp-block-paragraph">go into the same path so we were inside of let me just show you again with PWD</p>



<p class="wp-block-paragraph">we were inside of home mic documents temp so let me go inside of the home</p>



<p class="wp-block-paragraph">folder it&#8217;s not downloads documents temp and notice how I have the same file</p>



<p class="wp-block-paragraph">I can right click on this or even double click on it and I can open it up with</p>



<p class="wp-block-paragraph">Mousepad or even this nifty little code editor called genie if you&#8217;re interested in genie</p>



<p class="wp-block-paragraph">It&#8217;s actually pretty nice pseudo apt install genie and it&#8217;ll tell me that this program is already installed</p>



<p class="wp-block-paragraph">I like to use it because you know vs code and other IDEs. They&#8217;re great for productivity</p>



<p class="wp-block-paragraph">But they kind of help you a lot and if you&#8217;re trying to learn, you know coding or whatever</p>



<p class="wp-block-paragraph">or whatever sometimes it&#8217;s a little bit better if you just use something kind of plain because</p>



<p class="wp-block-paragraph">then you&#8217;ll learn more it&#8217;s harder uh you know that&#8217;s up to you anyway so i&#8217;m gonna right click</p>



<p class="wp-block-paragraph">on this and i&#8217;m gonna say let&#8217;s open this up with the how about mousepad i guess</p>



<p class="wp-block-paragraph">now i am graphically editing uh this file because maybe maybe you want to you know edit everything</p>



<p class="wp-block-paragraph">in nano maybe you don&#8217;t maybe you only want to use the terminal when you have to but uh well</p>



<p class="wp-block-paragraph">have to but well here you are let me do a cat command let&#8217;s see my program cat</p>



<p class="wp-block-paragraph">notice how it&#8217;s the same exact file I can I don&#8217;t know maybe put some empty</p>



<p class="wp-block-paragraph">comments up above the function name for fun and save the document and then just</p>



<p class="wp-block-paragraph">kind of do the cat command again and you can see that my changes have been</p>



<p class="wp-block-paragraph">updated so you can delete in the regular file system here in XFCE the file</p>



<p class="wp-block-paragraph">thunar and there should be a symbol somewhere or if you just kind of hit the start menu let&#8217;s see</p>



<p class="wp-block-paragraph">how about office where is thunar usually oh it&#8217;s in accessories okay and then if you&#8217;re on a gnome</p>



<p class="wp-block-paragraph">uh it&#8217;s probably just called files or i forget what the name of the file system is but you know</p>



<p class="wp-block-paragraph">something that just looks like a folder um so we&#8217;ve edited that we&#8217;ve got all the basics here</p>



<p class="wp-block-paragraph">we know how to navigate we know how to get to our home folder we&#8217;re like making directories</p>



<p class="wp-block-paragraph">deleting directories removing files touching files editing files we&#8217;re doing a lot and just to let</p>



<p class="wp-block-paragraph">you know there&#8217;s like so much more you can do on the terminal for instance you can let&#8217;s see do we</p>



<p class="wp-block-paragraph">have gcc on this computer no gcc is what people use to code in c plus plus right so i&#8217;m gonna say</p>



<p class="wp-block-paragraph">package on Ubuntu called build essential.</p>



<p class="wp-block-paragraph">I think it&#8217;s singular, not plural.</p>



<p class="wp-block-paragraph">And this is sort of like a meta package, which means it&#8217;s like a dummy package</p>



<p class="wp-block-paragraph">that installs a bunch of other packages.</p>



<p class="wp-block-paragraph">So build essential.</p>



<p class="wp-block-paragraph">It&#8217;ll grab all these other programs for you for like,</p>



<p class="wp-block-paragraph">it looks like a bunch of C++ stuff and there should be like GNU Mac in there</p>



<p class="wp-block-paragraph">and some Perl stuff, I guess.</p>



<p class="wp-block-paragraph">Yeah, I&#8217;ve never actually looked at this.</p>



<p class="wp-block-paragraph">That&#8217;s not a lot of stuff that I use.</p>



<p class="wp-block-paragraph">There&#8217;s just a few things that I use in there.</p>



<p class="wp-block-paragraph">But anyway, you install that and then you&#8217;ll get GCC,</p>



<p class="wp-block-paragraph">which will help you code in C++.</p>



<p class="wp-block-paragraph">You can also do sudo apt install,</p>



<p class="wp-block-paragraph">Yasm to install your assembler.</p>



<p class="wp-block-paragraph">What else?</p>



<p class="wp-block-paragraph">So GCC and G++ and Yasm and make and an editor.</p>



<p class="wp-block-paragraph">I think that&#8217;s kind of like almost all you need.</p>



<p class="wp-block-paragraph">Well, you can install a debugger,</p>



<p class="wp-block-paragraph">Well, you can install a debugger sudo apt install</p>



<p class="wp-block-paragraph">GDB to install your GNU debugger, which is already installed.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">Anyway, well, just to let you know, we can do GCC to compile some programs.</p>



<p class="wp-block-paragraph">It&#8217;ll complain.</p>



<p class="wp-block-paragraph">We don&#8217;t have anything.</p>



<p class="wp-block-paragraph">Let&#8217;s see.</p>



<p class="wp-block-paragraph">Actually, let me go in there.</p>



<p class="wp-block-paragraph">Let me go to documents temp.</p>



<p class="wp-block-paragraph">Let&#8217;s see if it&#8217;ll compile this just as is GCC my program output.</p>



<p class="wp-block-paragraph">And I&#8217;ll just say that we want a program called main.</p>



<p class="wp-block-paragraph">It&#8217;s going to work.</p>



<p class="wp-block-paragraph">main is this going to work did it actually work oh my gosh i got it right on the first try even</p>



<p class="wp-block-paragraph">though it was an empty program doesn&#8217;t really do anything oh by the way um in linux or in the</p>



<p class="wp-block-paragraph">command line you probably will see a lot of people do this sort of thing where it&#8217;s like dot</p>



<p class="wp-block-paragraph">slash in the name of a program the thing is in order to execute a program uh i&#8217;ll tell you about</p>



<p class="wp-block-paragraph">permissions in a second first it needs permission to execute but then you need to provide a path</p>



<p class="wp-block-paragraph">path to the program. You can&#8217;t just type main as is because the system, you know, the shell is going</p>



<p class="wp-block-paragraph">to think that you&#8217;re talking about a system program somewhere. So it&#8217;s going to look in all the system</p>



<p class="wp-block-paragraph">areas and it doesn&#8217;t find a program named main. So you have to give it a path to your custom</p>



<p class="wp-block-paragraph">programs to run. So I&#8217;m going to say dot slash main. And basically remember the dot was a special</p>



<p class="wp-block-paragraph">directory that meant the current directory. So if I type dot main, it&#8217;s actually kind of the same</p>



<p class="wp-block-paragraph">home mic documents temp main.</p>



<p class="wp-block-paragraph">So if I just type this whole path right here, it runs the program</p>



<p class="wp-block-paragraph">or I can do, you know, dot slash main.</p>



<p class="wp-block-paragraph">It also runs the program.</p>



<p class="wp-block-paragraph">In both cases, it works.</p>



<p class="wp-block-paragraph">Let me edit this real fast to see if I can just get something exciting going on here.</p>



<p class="wp-block-paragraph">I&#8217;ll stream and then I&#8217;m just going to go.</p>



<p class="wp-block-paragraph">Okay, so I&#8217;m just going to like do that.</p>



<p class="wp-block-paragraph">just gonna like do that let me try to compile again gcc my program output to</p>



<p class="wp-block-paragraph">execute what called me oh what did I do wrong oh gcc is for just regular C</p>



<p class="wp-block-paragraph">programs you&#8217;re not supposed to do that I want to use G plus plus and then I&#8217;m</p>



<p class="wp-block-paragraph">gonna say standard library I don&#8217;t know C plus 21 or something std what did I do</p>



<p class="wp-block-paragraph">Is 21 not a valid year?</p>



<p class="wp-block-paragraph">I don&#8217;t even remember.</p>



<p class="wp-block-paragraph">I&#8217;ve been using C++17 forever.</p>



<p class="wp-block-paragraph">What did I do wrong?</p>



<p class="wp-block-paragraph">STD equals C++.</p>



<p class="wp-block-paragraph">Okay, 17 I know definitely works.</p>



<p class="wp-block-paragraph">What am I doing wrong here?</p>



<p class="wp-block-paragraph">Okay, so 17, I guess 19 wasn&#8217;t a thing.</p>



<p class="wp-block-paragraph">Been using 17 for a long time.</p>



<p class="wp-block-paragraph">Okay, so I just compiled the program again with the C++17.</p>



<p class="wp-block-paragraph">Well, then what the heck was I doing yesterday?</p>



<p class="wp-block-paragraph">Was I using 23?</p>



<p class="wp-block-paragraph">Hang on, sorry.</p>



<p class="wp-block-paragraph">I forgot what standard I was on yesterday.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">So then if we run the program again, it prints a message.</p>



<p class="wp-block-paragraph">So maybe I should retitle this video, your first C++ program, because that&#8217;s literally</p>



<p class="wp-block-paragraph">what we just did.</p>



<p class="wp-block-paragraph">You know, I&#8217;ll make another video.</p>



<p class="wp-block-paragraph">the basics of the Linux command line.</p>



<p class="wp-block-paragraph">And well, you&#8217;re off.</p>



<p class="wp-block-paragraph">Well, I hope you enjoyed this video and you learned a little bit of stuff.</p>



<p class="wp-block-paragraph">Keep watching all the other videos and I&#8217;ll see you in the next one.</p>



<p class="wp-block-paragraph">Hey, everybody.</p>



<p class="wp-block-paragraph">Thanks for watching this video again from the bottom of my heart.</p>



<p class="wp-block-paragraph">I really appreciate it.</p>



<p class="wp-block-paragraph">I do hope you did learn something and have some fun.</p>



<p class="wp-block-paragraph">If you could do me a please, a small little favor, could you please subscribe and follow this channel or these videos or whatever it is you do on the current social media website that you&#8217;re looking at right now.</p>



<p class="wp-block-paragraph">It would really mean the world to me and it&#8217;ll help make more videos and grow this community.</p>



<p class="wp-block-paragraph">So we&#8217;ll be able to do more videos, longer videos, better videos, or just I&#8217;ll be able to keep making videos in general.</p>



<p class="wp-block-paragraph">So please do me a kindness and subscribe.</p>



<p class="wp-block-paragraph">the middle of the night and I just wake up because I know somebody subscribed or followed.</p>



<p class="wp-block-paragraph">It just wakes me up and I get filled with joy. That&#8217;s exactly what happens every single time.</p>



<p class="wp-block-paragraph">So you could do it as a nice favor to me or you could troll me if you want to just wake me up in</p>



<p class="wp-block-paragraph">the middle of the night. Just subscribe and then I&#8217;ll just wake up. I promise that&#8217;s what will</p>



<p class="wp-block-paragraph">happen. Also, if you look at the middle of the screen right now, you should see a QR code which</p>



<p class="wp-block-paragraph">you can scan in order to go to the website, which I think is also named somewhere at the bottom of</p>



<p class="wp-block-paragraph">to my main website where you can just kind of like see all the videos i published and the services</p>



<p class="wp-block-paragraph">and tutorials and things that i offer and all that good stuff and uh if you have a suggestion</p>



<p class="wp-block-paragraph">for uh uh clarifications or errata or just future videos that you want to see please leave a comment</p>



<p class="wp-block-paragraph">or if you just want to say hey what&#8217;s up what&#8217;s going on you know just send me a comment whatever</p>



<p class="wp-block-paragraph">i also wake up for those in the middle of the night i get i wake up in a cold sweat and i&#8217;m like</p>



<p class="wp-block-paragraph">it would really mean the world to me. I would really appreciate it. So again,</p>



<p class="wp-block-paragraph">thank you so much for watching this video and enjoy the cool music as I fade into the darkness,</p>



<p class="wp-block-paragraph">which is coming for us all.</p>



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/ultimate-beginners-guide-to-linux-command-line-ubuntu-terminal-basics-more/">Ultimate Beginner&#8217;s Guide to Linux Command Line: Ubuntu Terminal Basics &amp; More</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/ultimate-beginners-guide-to-linux-command-line-ubuntu-terminal-basics-more/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
