1 00:00:05,300 --> 00:00:06,850 Hello everyone, welcome back. 2 00:00:06,850 --> 00:00:10,350 In this video, I will create a default project template, 3 00:00:10,350 --> 00:00:13,650 that we can then use to create new projects from. 4 00:00:14,150 --> 00:00:18,550 This makes us so much more productive and a lot less chances for errors as well. 5 00:00:18,550 --> 00:00:21,550 So we're going to create the project, save it as a template, 6 00:00:21,550 --> 00:00:25,110 then when we create new projects, we'll use that template as the base. 7 00:00:25,110 --> 00:00:26,470 So let's get started. 8 00:00:26,470 --> 00:00:28,170 You notice here that I've got the 9 00:00:28,170 --> 00:00:31,530 previous workspace that I was working on in the installation videos. 10 00:00:31,530 --> 00:00:34,520 So let me just create a brand new workspace, I'll go through the flow again 11 00:00:34,520 --> 00:00:36,720 just so that you can see what it's like one more time. 12 00:00:36,720 --> 00:00:38,720 The more you see it, the easier it becomes. 13 00:00:38,720 --> 00:00:42,320 So I'm going to click right here new, create a new workspace. 14 00:00:43,310 --> 00:00:46,910 I'm going to select C++ workspace, click OK. 15 00:00:47,600 --> 00:00:50,500 Then I'm going to put it right inside my users folder, 16 00:00:50,500 --> 00:00:53,490 workspaces folder, I'm going to call this one Workspace2. 17 00:00:54,390 --> 00:00:56,390 Again you can name that anything you like. 18 00:00:56,390 --> 00:01:00,190 Make sure create the workspace under a separate directory is checked, 19 00:01:00,190 --> 00:01:01,190 I'll click OK. 20 00:01:01,990 --> 00:01:04,790 Perfect, so now you can see our workspace has been created. 21 00:01:04,790 --> 00:01:08,390 Now I can right click on the workspace and create a new project. 22 00:01:09,990 --> 00:01:14,290 We can name this project again, whatever we like, so I'll just call it project1. 23 00:01:15,890 --> 00:01:19,190 Make sure that create the project in its own folder is checked. 24 00:01:19,190 --> 00:01:20,990 The category is console, 25 00:01:21,590 --> 00:01:24,280 type is simple executable g++, 26 00:01:24,280 --> 00:01:26,280 the compiler is MinGW, 27 00:01:26,680 --> 00:01:29,980 on Linux and Mac you'll choose GCC for the compiler. 28 00:01:30,580 --> 00:01:33,080 The debugger is the GNU gdb debugger, 29 00:01:33,080 --> 00:01:36,580 on Mac you will choose lldb vs-code 30 00:01:36,580 --> 00:01:38,270 and then we want to select the codelite, 31 00:01:38,270 --> 00:01:41,270 make file generator as the build system. 32 00:01:41,270 --> 00:01:43,770 So I'll select and click OK. 33 00:01:44,270 --> 00:01:45,810 And that's going to create my project, 34 00:01:45,810 --> 00:01:48,610 as you can see in the workspace here with the source folder 35 00:01:48,610 --> 00:01:53,210 and the default main CPP which we are going to remove and write our own. 36 00:01:54,010 --> 00:01:55,510 So let's do that real quick. 37 00:01:55,510 --> 00:01:59,110 Pound include iostream, just like we did before 38 00:02:00,110 --> 00:02:02,710 using, I'll put a space here. 39 00:02:04,310 --> 00:02:08,710 Using namespace standard. 40 00:02:09,310 --> 00:02:12,310 Then we'll create our main function right here. 41 00:02:12,310 --> 00:02:15,310 We'll say cout and what I'm going to do here is I'm going to display 42 00:02:15,310 --> 00:02:17,310 default template. 43 00:02:20,310 --> 00:02:24,310 End line again endl not end1 44 00:02:24,310 --> 00:02:25,610 and we'll return zero. 45 00:02:26,410 --> 00:02:27,010 That's it. 46 00:02:27,010 --> 00:02:29,810 Notice that this is red, so we need to save our project, 47 00:02:29,810 --> 00:02:33,110 I'm going to press CTRL S on Windows or command S on Mac 48 00:02:33,710 --> 00:02:36,110 and we've got just what we had before. 49 00:02:36,110 --> 00:02:38,610 Now before we build this, let's set up our project. 50 00:02:38,610 --> 00:02:42,510 So I'm going to select project 1 and click on that wrench. 51 00:02:44,510 --> 00:02:47,710 In the general tab I want to go to the 52 00:02:47,710 --> 00:02:49,610 working directory right here, 53 00:02:49,610 --> 00:02:52,610 delete that and replace it with project path. 54 00:02:55,210 --> 00:02:59,210 Just like we did before, again uppercase P for Project and Path, 55 00:02:59,210 --> 00:03:01,900 I'll press tab and it'll light up dark like that. 56 00:03:01,900 --> 00:03:03,600 You don't have to change anything else, 57 00:03:03,600 --> 00:03:06,600 in fact don't touch anything else, It's just like it's supposed to be, 58 00:03:06,600 --> 00:03:09,900 we'll click on compiler now, over here on the left, 59 00:03:10,700 --> 00:03:12,600 go to my compiler options 60 00:03:12,600 --> 00:03:15,200 and click those three dots in the button. 61 00:03:15,800 --> 00:03:19,600 And I'm going to select enable C++ 17 features right 62 00:03:19,600 --> 00:03:23,100 there which is the STD equals C++ 17. 63 00:03:24,000 --> 00:03:26,700 I'll click OK, then I can come over to my linker 64 00:03:26,700 --> 00:03:29,500 and if you like you can put a dash static 65 00:03:30,490 --> 00:03:34,480 in the linker options again, dash static, no spaces in there. 66 00:03:34,480 --> 00:03:36,480 Mac users do not do this, 67 00:03:36,480 --> 00:03:39,170 leave that blank, otherwise you're going to get linker errors. 68 00:03:39,170 --> 00:03:42,530 So you can do this for Windows and for Linux, but 69 00:03:42,530 --> 00:03:45,030 Mac users leave it blank, that's it. 70 00:03:45,030 --> 00:03:47,530 I'll apply, I'll press OK. 71 00:03:47,530 --> 00:03:50,530 Now let's make sure that we can build, so we're going to come up here to build, 72 00:03:50,530 --> 00:03:51,830 rebuild project. 73 00:03:53,130 --> 00:03:55,130 We've got a clean build, no errors. 74 00:03:55,130 --> 00:03:57,330 Let's run it to make sure we can run it. 75 00:03:58,130 --> 00:04:01,730 And it should display default template, 76 00:04:01,730 --> 00:04:05,730 It does indeed, so we've got a good build, we've got a good project. 77 00:04:06,090 --> 00:04:09,450 Now what we can do is we can save this project as a template 78 00:04:09,450 --> 00:04:12,250 and we can use it later to create new projects 79 00:04:12,250 --> 00:04:14,750 from it, without having to do all this setting stuff again. 80 00:04:15,150 --> 00:04:17,750 So let's do that, let's right click on the project 1. 81 00:04:18,440 --> 00:04:21,339 And we'll comedown here to where it says save as template, 82 00:04:21,339 --> 00:04:21,839 okay? 83 00:04:21,839 --> 00:04:26,040 Let me do that one more time, right click on project 1, save as template. 84 00:04:27,030 --> 00:04:29,720 The project name I'm just going to call this 85 00:04:29,720 --> 00:04:31,720 default project. 86 00:04:32,320 --> 00:04:33,820 You can call this anything you like. 87 00:04:34,810 --> 00:04:37,810 The project category, this says where am I going to store this? 88 00:04:37,810 --> 00:04:41,110 I'm going to store it in a category called user templates, 89 00:04:41,110 --> 00:04:44,110 It doesn't really matter where you put it as long as you remember where you put it. 90 00:04:44,110 --> 00:04:48,710 So user templates works for me and the description again can be anything. 91 00:04:48,710 --> 00:04:50,910 Just going to say my default project. 92 00:04:53,810 --> 00:04:55,410 There we go, and I'm going to press OK. 93 00:04:56,400 --> 00:04:57,200 Done. 94 00:04:57,200 --> 00:04:58,600 Now what we can do is? 95 00:04:58,600 --> 00:05:01,900 We can create new projects from that template, so let's do that. 96 00:05:01,900 --> 00:05:06,500 I'll click on the workspace, I'll right click, new project. 97 00:05:08,400 --> 00:05:12,000 The project's name could be anything, I'll just say Project 2, again remember, 98 00:05:12,000 --> 00:05:15,900 no spaces, no special characters, no international characters anywhere. 99 00:05:16,600 --> 00:05:18,800 The category now, what we'll do is? 100 00:05:18,800 --> 00:05:20,400 We'll pick user templates 101 00:05:21,300 --> 00:05:24,990 and for type, we'll pick default project which is what we just created. 102 00:05:25,890 --> 00:05:30,250 Double check that, if got MinGW or GCC on Linux and Mac 103 00:05:30,250 --> 00:05:34,750 and the GNU debugger or the lldb vscode on Mac. 104 00:05:34,750 --> 00:05:37,750 They should be populated from the template. 105 00:05:38,050 --> 00:05:40,050 We've got CodeLite make file generators, 106 00:05:40,050 --> 00:05:42,950 you can just give it a once over and make sure everything looks good 107 00:05:42,950 --> 00:05:44,550 and I'll press OK. 108 00:05:45,050 --> 00:05:47,650 Now you can see that Project2 has been created, 109 00:05:47,650 --> 00:05:50,650 however project1 is still the active project. 110 00:05:50,650 --> 00:05:54,450 So we can make Project 2 the active project by just double clicking on it. 111 00:05:55,050 --> 00:05:58,740 And now Project 2, you can see it's italicized in bold. 112 00:05:58,740 --> 00:06:00,940 So let me close this up here 113 00:06:00,940 --> 00:06:04,540 and let's open up our project 2's main CPP. 114 00:06:04,540 --> 00:06:07,540 Notice I got the default template code which I wrote earlier. 115 00:06:08,140 --> 00:06:11,140 If I select project two and I click the wrench, 116 00:06:11,140 --> 00:06:15,140 you can see that in the general, it did not keep the project 117 00:06:15,140 --> 00:06:16,580 path unfortunately. 118 00:06:16,580 --> 00:06:19,580 This is a bug that hopefully will be fixed soon, 119 00:06:19,580 --> 00:06:22,580 so in the mean time, we'll just have to type Project path, 120 00:06:24,080 --> 00:06:25,080 just like that. 121 00:06:25,880 --> 00:06:27,880 But the compiler option did take, 122 00:06:28,380 --> 00:06:31,380 you can see the STD equals C++ 17 123 00:06:31,380 --> 00:06:34,180 and the linker option, you can see the static right here. 124 00:06:34,180 --> 00:06:37,680 So unfortunately, we still have to come in here and type Project Path, 125 00:06:37,680 --> 00:06:40,280 but it's a little bit less work than we had to do before. 126 00:06:40,280 --> 00:06:42,270 Apply, okay 127 00:06:42,270 --> 00:06:45,770 and we're good to go now, we can come over here to Project 2, build it. 128 00:06:48,770 --> 00:06:51,570 And you can see the C++ 17 over here, 129 00:06:51,570 --> 00:06:54,570 you can see the static being used over here, so all this is good 130 00:06:54,570 --> 00:06:56,570 and we can build and run. 131 00:06:58,070 --> 00:07:01,070 And I'll execute it and it should say default template, 132 00:07:01,870 --> 00:07:03,070 just like we did before. 133 00:07:03,070 --> 00:07:07,760 We can obviously change this and I'm going to say hello from Project 2. 134 00:07:09,760 --> 00:07:13,060 I'll save that and I can build and run again. 135 00:07:14,660 --> 00:07:15,660 There's our build, 136 00:07:15,660 --> 00:07:18,960 It's a clean build, always be sure that you don't have any errors here before you run. 137 00:07:18,960 --> 00:07:23,320 I'll execute and hello from Project 2. 138 00:07:23,320 --> 00:07:25,920 So there you go, this makes life a little bit easier, 139 00:07:25,920 --> 00:07:30,520 unfortunately we still have to set that project path right here 140 00:07:30,520 --> 00:07:32,320 for the general options. 141 00:07:32,320 --> 00:07:36,010 But it's a lot less than we had to do before and I think we're good to go here. 142 00:07:36,010 --> 00:07:39,010 So you can use this technique, so that finishes up the 143 00:07:39,010 --> 00:07:41,910 configuration of the default template. 144 00:07:41,910 --> 00:07:44,110 I'll see you in the next videos and we'll start coding.