1 00:00:05,400 --> 00:00:08,400 In this video, we'll take our first program, 2 00:00:08,400 --> 00:00:12,300 which we've compiled to show that it's got no errors and we'll build it. 3 00:00:12,500 --> 00:00:14,600 Now if you recall building means 4 00:00:14,600 --> 00:00:18,400 compiling, linking together with extra libraries 5 00:00:18,400 --> 00:00:22,700 and external files if we need to and creating an executable file. 6 00:00:23,000 --> 00:00:24,800 That's what building is all about. 7 00:00:24,800 --> 00:00:27,000 There are several steps involved with building. 8 00:00:27,000 --> 00:00:29,000 The first one obviously is compiling. 9 00:00:29,200 --> 00:00:32,900 If we can't get a clean compile, then there's no way we're going to build the system. 10 00:00:33,700 --> 00:00:36,700 So we want to be able to compile and then link 11 00:00:36,700 --> 00:00:40,690 to create the exe file. Finally, we can run our executable. 12 00:00:41,090 --> 00:00:43,690 So in this case, you'll notice here's the source code. 13 00:00:43,690 --> 00:00:46,390 And there's a lot of space in here. Normally, we don't have all this space in here. 14 00:00:46,390 --> 00:00:49,890 I just put it in because it makes a little bit easier for you to read 15 00:00:49,890 --> 00:00:52,890 when you're first learning. So let's just keep it like that. 16 00:00:52,890 --> 00:00:55,390 This program is exactly the same as it was before. 17 00:00:55,390 --> 00:00:59,590 We're entering -- we're asking the user to enter their favorite number between 1 and 100. 18 00:00:59,590 --> 00:01:03,990 We're getting that number and storing it in a variable called favorite number. 19 00:01:04,239 --> 00:01:08,340 And then we're just saying amazing that's my favorite number too. So it's really really simple program. 20 00:01:08,840 --> 00:01:10,340 And we've already compiled it. 21 00:01:10,340 --> 00:01:12,240 There's a couple of ways to compile. 22 00:01:12,240 --> 00:01:16,040 One is you can come to the source file itself, right click, 23 00:01:16,040 --> 00:01:19,540 compile or you can come up to build, 24 00:01:20,440 --> 00:01:21,940 compile current file 25 00:01:23,740 --> 00:01:25,840 and that's only taking care of the compilation. 26 00:01:25,840 --> 00:01:29,840 There's also a lot of things you could do at the project level right here. So if I select the project 27 00:01:29,840 --> 00:01:32,840 and right click, you can see that it says build, 28 00:01:32,840 --> 00:01:35,840 rebuild, clean, stop build and so forth. 29 00:01:35,840 --> 00:01:38,040 Let's talk about clean first. 30 00:01:38,840 --> 00:01:42,040 think about this. When I compile 31 00:01:43,030 --> 00:01:47,430 a c++ program, I'm converting the cpp source code, 32 00:01:47,430 --> 00:01:51,830 this source code you see here, to an object format, right. A machine 33 00:01:51,830 --> 00:01:54,130 language or a binary format. 34 00:01:55,030 --> 00:01:59,030 That's going to create a .o file or a .obj file, as we mentioned in 35 00:01:59,030 --> 00:02:00,030 previous lectures. 36 00:02:01,130 --> 00:02:03,130 That's the purpose of compiling. 37 00:02:04,030 --> 00:02:06,630 Now as your programs are compiled, 38 00:02:06,630 --> 00:02:09,229 they will have many of these .object files. 39 00:02:10,229 --> 00:02:14,230 The clean process removes all those object files 40 00:02:14,230 --> 00:02:17,030 and puts your project in a clean state. 41 00:02:17,030 --> 00:02:20,930 In other words source code only. No object files. 42 00:02:20,930 --> 00:02:22,290 Now why is this important. 43 00:02:23,090 --> 00:02:26,590 It's important because when you compile your programs 44 00:02:26,590 --> 00:02:28,090 and build your programs, 45 00:02:28,090 --> 00:02:31,090 sometimes you want to do a clean build. 46 00:02:31,090 --> 00:02:33,590 What that means is I want to start from a 47 00:02:33,590 --> 00:02:37,090 position where nothing has been built. I just want to clean everything out. 48 00:02:37,090 --> 00:02:40,690 Now when we're working with a single cpp file like here, 49 00:02:41,050 --> 00:02:44,450 it's pretty much a moot point because it's just one file. 50 00:02:44,450 --> 00:02:47,850 But typically, c++ programs are very large 51 00:02:47,850 --> 00:02:50,620 and you've got a lot of c++ files. 52 00:02:50,620 --> 00:02:54,220 Each one of them is being compiled to an object format 53 00:02:55,020 --> 00:02:57,820 and when you say, hey compiler build for me, 54 00:02:57,820 --> 00:03:01,520 the compiler is only going to build exactly what it needs to build. 55 00:03:01,520 --> 00:03:05,020 So if it realizes that this source code 56 00:03:05,020 --> 00:03:08,020 already has an object file associated with it 57 00:03:08,020 --> 00:03:11,620 and the source code hasn't changed, then why bother building it again, right. 58 00:03:12,120 --> 00:03:16,220 So it's not going to build it and it does that to be efficient, which makes a lot of sense. 59 00:03:16,880 --> 00:03:21,480 But occasionally, you want to do a clean that removes all of that stuff. 60 00:03:21,480 --> 00:03:23,680 It removes the exe that was created. 61 00:03:23,680 --> 00:03:27,340 And then you want to build again. So now we're going to get a clean build. 62 00:03:28,000 --> 00:03:32,200 Again, this is really not an issue here when we've got one cpp file. 63 00:03:32,200 --> 00:03:35,500 But if you've got thousands and thousands and thousands of files, 64 00:03:36,000 --> 00:03:39,600 there can be a significant difference in the amount of time 65 00:03:39,600 --> 00:03:41,000 that it takes to do that build. 66 00:03:41,500 --> 00:03:45,300 Okay. So in this case, I can come over here to the project. 67 00:03:45,660 --> 00:03:47,760 I could right click, and I can say clean. 68 00:03:48,360 --> 00:03:50,960 And you'll see here the clean is complete. 69 00:03:50,960 --> 00:03:54,960 All it did was remove any object files and all in the exe files. 70 00:03:55,660 --> 00:03:57,660 Then I can say build. 71 00:03:58,160 --> 00:04:00,520 Now when I say build, 72 00:04:00,520 --> 00:04:04,620 by saying build project here pressing F7 73 00:04:04,620 --> 00:04:07,620 or on mac whatever the option, command option is 74 00:04:08,420 --> 00:04:10,820 or I can right click on the project and say build. 75 00:04:10,820 --> 00:04:13,620 Now what's going to happen here is it's going to go through 76 00:04:13,620 --> 00:04:16,390 your project looking at all the c++ files 77 00:04:16,390 --> 00:04:18,390 and only build what it needs to build. 78 00:04:18,990 --> 00:04:23,090 Okay. Now in this case it's going to build everything because it's just the one file and I haven't built it yet. 79 00:04:23,690 --> 00:04:27,990 But it's going to not build what it doesn't need to build and that's important to understand. 80 00:04:28,490 --> 00:04:32,690 Rebuild is the combination of a clean and a build. 81 00:04:32,940 --> 00:04:36,040 So when you say hey rebuild the project, it's going to do a clean, 82 00:04:36,040 --> 00:04:38,400 it's going to clean everything out and then it's going to build it again. 83 00:04:39,760 --> 00:04:43,160 For the beginning of this course, all of these are going to be just fine. 84 00:04:43,160 --> 00:04:45,160 You can use rebuilds because it's going to be pretty quick. 85 00:04:45,960 --> 00:04:48,560 Finally, once we get a build, we can run the project. 86 00:04:48,560 --> 00:04:52,560 The way we do that is we come up. Again remember, we've got the active project here. 87 00:04:52,560 --> 00:04:54,960 I can come up to build and run. 88 00:04:55,760 --> 00:04:57,160 Now if I do that now, 89 00:04:57,960 --> 00:05:02,160 we have an option we can simply execute the exe file 90 00:05:02,160 --> 00:05:06,360 if there if there is one there or we can choose to build and execute. 91 00:05:07,160 --> 00:05:09,960 I would generally tell you to select build and execute 92 00:05:09,960 --> 00:05:14,060 and probably remember my answer don't ask me again would be a pretty good idea 93 00:05:14,420 --> 00:05:17,620 because most of the time our files are going to be fairly smalland the 94 00:05:17,620 --> 00:05:20,920 build is not going to take any time at all. So we can build and execute. 95 00:05:21,820 --> 00:05:23,820 Okay. So that's how you run. 96 00:05:23,820 --> 00:05:26,820 Let's say, I want to do that. Now I'm going to say build and execute, 97 00:05:28,220 --> 00:05:30,820 and there's my program it says, 98 00:05:30,820 --> 00:05:33,420 enter your favorite number between 1 and 100. 99 00:05:33,420 --> 00:05:36,720 Let's say I type in 24, press enter. 100 00:05:36,720 --> 00:05:39,320 It says amazing, that's my favorite number too. 101 00:05:40,120 --> 00:05:43,620 Now this time elapsed is how long the program took to run. 102 00:05:43,620 --> 00:05:46,420 This is being displayed in the latest version of CodeLite. 103 00:05:46,620 --> 00:05:50,820 Prior to this last version, you didn't see that and I think it's windows only it's being displayed. 104 00:05:50,820 --> 00:05:52,820 I didn't see that display on a mac. 105 00:05:52,820 --> 00:05:56,220 When you run the exe file that's created from the command line, 106 00:05:56,220 --> 00:05:59,820 you don't see that. That's just mostly for fyi. 107 00:05:59,820 --> 00:06:01,820 So that you can tell as a developer 108 00:06:01,820 --> 00:06:04,620 if there's something wrong and how quick your program is running. 109 00:06:04,620 --> 00:06:06,920 Press any key to continue, I'm done. 110 00:06:06,920 --> 00:06:07,620 Okay. 111 00:06:07,620 --> 00:06:12,060 Now one of the things that I want to show you. Notice this workspace view, 112 00:06:12,060 --> 00:06:13,660 which is where I'm at right now. 113 00:06:13,660 --> 00:06:17,160 And again, I've got three projects here. Each one has a main. 114 00:06:17,960 --> 00:06:20,960 Where's the exe files. Where are the object files. 115 00:06:20,960 --> 00:06:23,560 Where's all that stuff. They should be there, right. 116 00:06:24,160 --> 00:06:26,760 Absolutely, they should be there. And they are there. 117 00:06:27,260 --> 00:06:28,860 The IDEs 118 00:06:28,860 --> 00:06:32,860 generally hide that information from you because you don't need to know about it really. 119 00:06:33,110 --> 00:06:36,710 I mean do you care that there's an object file or an exe file, really what you 120 00:06:36,710 --> 00:06:39,410 care about is these error messages and so forth. 121 00:06:39,410 --> 00:06:41,960 But we have this explorer tab 122 00:06:41,960 --> 00:06:44,560 and that'll let you see all that I want to show you what that looks like. 123 00:06:44,960 --> 00:06:46,960 You can click on the explorer tab 124 00:06:47,460 --> 00:06:51,760 and then you can drag any folder from your operating system, from your file system onto here. 125 00:06:51,760 --> 00:06:54,660 So I can just right click, open folder 126 00:06:54,660 --> 00:06:58,360 and I'm going to select from my desktop cpp examples 127 00:06:58,360 --> 00:07:00,240 that section 4 folder. 128 00:07:00,240 --> 00:07:02,540 That's where my workspace is, and I'll select it. 129 00:07:03,900 --> 00:07:05,900 Okay. So you can see now if I expand this, 130 00:07:07,500 --> 00:07:11,600 you could see a bunch more stuff. Now I've got a .codelite folder that has 131 00:07:12,000 --> 00:07:16,000 things that are related to my favorites and compilation 132 00:07:16,000 --> 00:07:17,400 and refactoring and so forth. 133 00:07:18,100 --> 00:07:22,200 I've also got my three projects, first program project1, project2. 134 00:07:22,200 --> 00:07:24,970 I've got a make file. I've got my workspace file 135 00:07:24,970 --> 00:07:27,170 but let's look at first program for a second. 136 00:07:28,270 --> 00:07:30,870 Now you can see a little extra stuff going on, right. 137 00:07:30,870 --> 00:07:34,270 Before all we saw was main cpp. Now we see all this other. Stuff 138 00:07:34,770 --> 00:07:38,570 these are the files and the configuration files that CodeLite is using 139 00:07:38,570 --> 00:07:39,570 behind the scenes. 140 00:07:40,070 --> 00:07:42,430 The IDE workspace here 141 00:07:42,430 --> 00:07:46,430 abstracts that out since you don't really need to know all that information 142 00:07:46,430 --> 00:07:49,030 to build your system. It's building it for you. 143 00:07:49,030 --> 00:07:53,020 But if you really want to see them you can or you can just look right in your file system. 144 00:07:53,820 --> 00:07:56,420 Now if I look in my first program debug folder, 145 00:07:57,080 --> 00:08:01,480 you'll see that there's my exe, firstprogram.exe. 146 00:08:01,780 --> 00:08:06,770 You can see it right here. And there you can see my .object files and .d files and all kinds of stuff that's going on. 147 00:08:07,370 --> 00:08:09,970 Now you'll see first -- again first program debug. 148 00:08:10,470 --> 00:08:13,970 Now what I'm going to do now is I'm going to clean first program. 149 00:08:13,970 --> 00:08:16,570 And all of this stuff should be removed. 150 00:08:16,570 --> 00:08:18,870 So again, I'm going to go to build, 151 00:08:20,470 --> 00:08:21,470 clean project. 152 00:08:23,370 --> 00:08:27,470 Now if I refresh this view by right-clicking up here, refresh, 153 00:08:27,770 --> 00:08:30,970 and go back to first program, you can see it's all gone. 154 00:08:30,970 --> 00:08:35,470 The entire debug folder is gone. The object files are gone. The exe files are gone. 155 00:08:35,669 --> 00:08:39,970 Everything's gone. So now when I rebuild, all that will be created again. 156 00:08:40,470 --> 00:08:42,970 And now you'll notice that debug folder, right. 157 00:08:42,970 --> 00:08:44,770 Well, if I come back to my workspace, 158 00:08:45,570 --> 00:08:48,970 there's my first program. Notice that we've got 159 00:08:48,970 --> 00:08:53,070 build configurations here. And there's a couple you've got debug and release. 160 00:08:53,070 --> 00:08:54,770 You can choose either one. 161 00:08:54,770 --> 00:08:58,270 We're going to use debug throughout the entire course because that's what we're doing. 162 00:08:58,270 --> 00:09:00,270 We're basically developing right here. 163 00:09:00,270 --> 00:09:04,670 Release is when you want to release the file from two productions for your users to use. 164 00:09:04,670 --> 00:09:09,330 So in this case, debug creates that debug folder that you saw a little bit ago. 165 00:09:09,580 --> 00:09:13,780 If we do this in release mode, we'll get a release folder as well. So we'll have two exes. 166 00:09:13,780 --> 00:09:17,080 Now the difference is the debug configuration 167 00:09:17,080 --> 00:09:20,880 creates object files that has debugging information in them. 168 00:09:20,880 --> 00:09:22,780 It's got all those variable names and stuff. 169 00:09:22,780 --> 00:09:24,980 So later on when we debug our program, 170 00:09:24,980 --> 00:09:27,580 we can have all that information available to us 171 00:09:27,580 --> 00:09:30,080 and it makes us very, very productive. 172 00:09:30,080 --> 00:09:32,380 And it really helps us debug and test our code. 173 00:09:33,180 --> 00:09:36,780 The release configuration removes all of that stuff. 174 00:09:36,780 --> 00:09:38,180 And it does more optimizations. 175 00:09:38,180 --> 00:09:41,480 And it just makes your exe leaner and meaner. So that you don't need all 176 00:09:41,480 --> 00:09:44,080 that debugging information at runtime. 177 00:09:44,080 --> 00:09:46,080 Okay. So like I said we're going to use debug. 178 00:09:46,080 --> 00:09:48,080 You can certainly use this if you like 179 00:09:48,080 --> 00:09:51,580 if you do use this because you're curious or you want to see what's going on, 180 00:09:51,580 --> 00:09:53,910 don't modify anything from in here. 181 00:09:53,910 --> 00:09:57,210 I mean as a matter of fact if I try to open up this make file, 182 00:09:57,210 --> 00:10:00,410 you'll see it says auto generated by CodeLite. Don't change it 183 00:10:01,010 --> 00:10:03,610 or even if you do change it, we're going to blow it away anyway. 184 00:10:03,610 --> 00:10:05,610 So you really don't need any of that. 185 00:10:05,610 --> 00:10:08,210 This is where we're going to be working in the workspace mode. 186 00:10:08,210 --> 00:10:11,810 But I just wanted to show you how that clean really, really works. 187 00:10:12,110 --> 00:10:14,310 Okay. So again, let's recap here. 188 00:10:14,310 --> 00:10:17,310 I can select first program. Right click, 189 00:10:17,310 --> 00:10:18,210 clean. 190 00:10:18,210 --> 00:10:21,510 That'll remove all my object files in the exe file. 191 00:10:21,510 --> 00:10:25,500 I can rebuild in which case it will clean and build 192 00:10:25,750 --> 00:10:29,850 or I can simply build and that will only build what needs to be built. 193 00:10:30,350 --> 00:10:33,340 Okay hopefully, that makes sense. It's a little difference between them. 194 00:10:33,340 --> 00:10:36,110 But it said you should understand it's not that big that big a difference. 195 00:10:36,110 --> 00:10:39,110 Now finally, we want to run. We come here to run. 196 00:10:39,610 --> 00:10:42,810 So let's do this one more time. I'll build and execute, 197 00:10:44,510 --> 00:10:47,910 enter your favorite number. My favorite number is 100 this time. 198 00:10:48,710 --> 00:10:52,610 Amazing, that's my favorite number too. That's exactly what our program is supposed to do. 199 00:10:53,510 --> 00:10:55,110 Now you'll notice a couple of things here. 200 00:10:55,710 --> 00:10:58,710 One is we're really not using favorite number, 201 00:10:58,710 --> 00:11:01,710 are we? I mean the user is typing it in, but we're not really saying 202 00:11:02,610 --> 00:11:06,910 wow that's a great number 13 that you entered or 100 that you entered. 203 00:11:06,910 --> 00:11:09,510 And you'll do that in the challenge exercise in this section. 204 00:11:09,910 --> 00:11:13,710 But right now we're grabbing it, we're storing it into that variable. 205 00:11:13,710 --> 00:11:16,010 But we're not really using it afterward. 206 00:11:16,010 --> 00:11:18,710 And then, like I said, in the challenge video, you will use it. 207 00:11:18,710 --> 00:11:22,210 So that's it. That's pretty much the build process, the compile process, 208 00:11:22,210 --> 00:11:25,610 the run process. It's fairly straightforward. 209 00:11:25,610 --> 00:11:29,410 If you've got the toolbar, you can click on buttons to do this. 210 00:11:29,410 --> 00:11:33,410 But in this course, I'll come up here and do these things or I'll just right click here 211 00:11:33,410 --> 00:11:34,770 and do what I need to do here as well. 212 00:11:35,370 --> 00:11:38,970 That's it. Remember, you can also come up to the workspace, 213 00:11:39,520 --> 00:11:42,320 and right click on the workspace, you can build 214 00:11:42,320 --> 00:11:45,320 the entire workspace or clean the entire workspace. 215 00:11:45,820 --> 00:11:49,420 And that will create exe files for all the projects, all in one shot. 216 00:11:50,720 --> 00:11:52,280 Okay that's it for that. 217 00:11:52,280 --> 00:11:55,480 Now in the next video what we'll do is we'll talk about 218 00:11:55,480 --> 00:11:57,480 compiler errors and compiler warnings. 219 00:11:57,480 --> 00:11:59,480 And we'll mess around with this program a little bit. 220 00:11:59,480 --> 00:12:03,680 And I'll show you some of the common errors and some of the common warnings that you could get 221 00:12:03,680 --> 00:12:05,180 as well as why they happen. 222 00:12:05,880 --> 00:12:09,880 Now throughout the course, we're obviously going to see a lot of compiler errors. 223 00:12:09,880 --> 00:12:13,280 I make it a point that when I teach I'm just coding 224 00:12:13,280 --> 00:12:14,280 along with you. 225 00:12:14,280 --> 00:12:18,280 So I hope I make some mistakes, so you can see some of the common 226 00:12:18,280 --> 00:12:19,400 compiler errors. 227 00:12:19,400 --> 00:12:22,000 I'm not trying to make them intentionally, but sometimes 228 00:12:22,000 --> 00:12:24,000 you know you forget a semicolon or you forget to do this, 229 00:12:24,000 --> 00:12:28,400 this is the wrong type. So that's important that you see these types of errors 230 00:12:28,400 --> 00:12:30,800 happening, and you can know how to fix them. 231 00:12:31,200 --> 00:12:32,860 All right. So I'll see you in the next video.