1 00:00:00,106 --> 00:00:02,606 (intro music) 2 00:00:05,430 --> 00:00:07,380 Frank: In this video, we'll go over the steps necessary 3 00:00:07,380 --> 00:00:10,890 to create our own custom project template. 4 00:00:10,890 --> 00:00:11,730 The idea here is 5 00:00:11,730 --> 00:00:13,710 that we can create our own project templates. 6 00:00:13,710 --> 00:00:15,300 And when we create our projects, 7 00:00:15,300 --> 00:00:18,030 we can use this template as the starting point. 8 00:00:18,030 --> 00:00:21,750 That way we'll have a proper main.cpp file. 9 00:00:21,750 --> 00:00:23,550 We'll have all our switches set, 10 00:00:23,550 --> 00:00:25,140 we'll have our environment set. 11 00:00:25,140 --> 00:00:26,160 Alright, so let's get started. 12 00:00:26,160 --> 00:00:28,680 First thing you need to do is open up a workspace. 13 00:00:28,680 --> 00:00:31,650 I've got a workspace already open, I already created 14 00:00:31,650 --> 00:00:33,000 I should say I'm gonna open it now. 15 00:00:33,000 --> 00:00:34,530 I'm gonna say open workspace. 16 00:00:34,530 --> 00:00:36,510 If you don't have a workspace at all 17 00:00:36,510 --> 00:00:38,820 you could just say File, New Workspace. 18 00:00:38,820 --> 00:00:40,560 So I'll open the workspace that I've got. 19 00:00:40,560 --> 00:00:43,530 It's on my desktop and it's called CPPWorkspace. 20 00:00:43,530 --> 00:00:44,643 So I'll open that. 21 00:00:46,350 --> 00:00:47,520 And the first thing you wanna do is 22 00:00:47,520 --> 00:00:48,720 you want to add a project. 23 00:00:48,720 --> 00:00:51,360 So you wanna right click on your workspace 24 00:00:51,360 --> 00:00:53,763 and say New, New Project. 25 00:00:55,290 --> 00:00:57,540 Now here you've got the New Project Wizard 26 00:00:57,540 --> 00:00:59,160 and you've got different examples. 27 00:00:59,160 --> 00:01:01,950 You can create GUI applications, console applications, 28 00:01:01,950 --> 00:01:04,290 you can have user templates and so forth. 29 00:01:04,290 --> 00:01:06,330 What we want to do is, 30 00:01:06,330 --> 00:01:10,500 we want to use the simple executable g++ template 31 00:01:10,500 --> 00:01:12,630 that comes with CodeLite. 32 00:01:12,630 --> 00:01:14,040 And we want to tweak that our own way. 33 00:01:14,040 --> 00:01:15,360 And then what we want to do is we want to create 34 00:01:15,360 --> 00:01:18,000 our own template in here that we can choose. 35 00:01:18,000 --> 00:01:19,440 And we could put it in console or 36 00:01:19,440 --> 00:01:20,940 we can put it here in user templates. 37 00:01:20,940 --> 00:01:22,710 We could put it wherever we'd like. 38 00:01:22,710 --> 00:01:25,080 Okay? But before we do that, we need to create a project. 39 00:01:25,080 --> 00:01:25,913 So let's do that. 40 00:01:25,913 --> 00:01:29,100 I'm gonna select console and let's use the g++ 41 00:01:29,100 --> 00:01:31,560 simple executable console template. 42 00:01:31,560 --> 00:01:32,583 I'll press next. 43 00:01:34,080 --> 00:01:35,880 The project name, it doesn't really matter. 44 00:01:35,880 --> 00:01:39,120 I'll just say sample since we're gonna save it 45 00:01:39,120 --> 00:01:42,393 as a template anyway, and I'll select next. 46 00:01:43,230 --> 00:01:45,830 We wanna make sure our compiler is set up correctly. 47 00:01:49,500 --> 00:01:52,590 Here I'm using MinGW and the gdb debugger. 48 00:01:52,590 --> 00:01:53,673 I'll select finish. 49 00:01:54,930 --> 00:01:56,970 And that creates our project. 50 00:01:56,970 --> 00:01:58,260 You can see here's the source file 51 00:01:58,260 --> 00:01:59,580 and here's the CPP file, 52 00:01:59,580 --> 00:02:01,770 which is really C code and not c++ code. 53 00:02:01,770 --> 00:02:03,390 But we'll fix all this in a minute. 54 00:02:03,390 --> 00:02:05,070 So, first thing we wanna do is 55 00:02:05,070 --> 00:02:07,830 we wanna get rid of this and let's write 56 00:02:07,830 --> 00:02:09,570 a simple c++ program. 57 00:02:09,570 --> 00:02:11,340 So same one we've been writing all along. 58 00:02:11,340 --> 00:02:12,790 So we'll say include 59 00:02:14,100 --> 00:02:15,510 iostream, 60 00:02:15,510 --> 00:02:17,790 we'll include iostream since we're gonna probably use it 61 00:02:17,790 --> 00:02:19,690 in most of the projects that we write. 62 00:02:20,790 --> 00:02:22,340 Then we have our main function, 63 00:02:24,480 --> 00:02:27,840 and again it's int main open, close parens, 64 00:02:27,840 --> 00:02:28,830 and then an open curly 65 00:02:28,830 --> 00:02:31,323 which will be automatically closed by Codelite. 66 00:02:32,310 --> 00:02:35,130 Here we can indent in by just pressing tab 67 00:02:35,130 --> 00:02:38,763 and we could say std::cout. 68 00:02:40,200 --> 00:02:43,477 And then the insertion operator followed by the string 69 00:02:43,477 --> 00:02:44,487 "Hello world". 70 00:02:45,900 --> 00:02:48,540 And you can type anything you like here for "Hello World". 71 00:02:48,540 --> 00:02:52,500 And we'll do also an std::endl;. 72 00:02:52,500 --> 00:02:53,973 This prints a new line. 73 00:02:55,410 --> 00:02:57,690 That way when we display "Hello World", the cursor will go 74 00:02:57,690 --> 00:02:59,910 to the next line on the console. 75 00:02:59,910 --> 00:03:02,430 And then finally we'll just return zero like we always do. 76 00:03:02,430 --> 00:03:03,570 That's it. 77 00:03:03,570 --> 00:03:05,340 I'm going to save this. 78 00:03:05,340 --> 00:03:06,810 So I'm gonna press control S here. 79 00:03:06,810 --> 00:03:09,390 So I've just done that and saved it. 80 00:03:09,390 --> 00:03:11,400 Now we'll set some compiler settings and we'll do 81 00:03:11,400 --> 00:03:12,900 this the one time and then we'll save it 82 00:03:12,900 --> 00:03:14,580 as a project template. 83 00:03:14,580 --> 00:03:17,820 So let's go to the sample project, the actual project name 84 00:03:17,820 --> 00:03:21,153 and we'll right click go down to Settings, 85 00:03:22,770 --> 00:03:24,390 Global Settings. 86 00:03:24,390 --> 00:03:26,370 And we wanna make sure we've got those two compiler 87 00:03:26,370 --> 00:03:27,210 options set. 88 00:03:27,210 --> 00:03:29,100 So we're gonna right click on those three little dots 89 00:03:29,100 --> 00:03:29,933 here on the button. 90 00:03:29,933 --> 00:03:32,490 You wanna select that button and click, and we 91 00:03:32,490 --> 00:03:36,120 wanna make sure that we've got our all warnings enabled on 92 00:03:36,120 --> 00:03:38,913 and our C++ 14 standard on. 93 00:03:39,930 --> 00:03:40,763 Press okay. 94 00:03:42,390 --> 00:03:45,300 Then you wanna come to where it says code completion 95 00:03:45,300 --> 00:03:49,410 and select that and select enable C++ 14 standard. 96 00:03:49,410 --> 00:03:50,243 Apply. 97 00:03:51,690 --> 00:03:52,920 And that's it. 98 00:03:52,920 --> 00:03:54,330 Now what we can do is we can come 99 00:03:54,330 --> 00:03:57,130 to the project again, right click and say 100 00:03:58,200 --> 00:04:00,570 Save as Template. 101 00:04:00,570 --> 00:04:01,623 So I'll select that. 102 00:04:02,760 --> 00:04:04,650 And what's the project name? 103 00:04:04,650 --> 00:04:05,970 This could be anything we want. 104 00:04:05,970 --> 00:04:08,970 We could just say Frank template 105 00:04:08,970 --> 00:04:12,063 or template for course or any name you like. 106 00:04:13,140 --> 00:04:15,290 Rather than that, I'm just gonna say Frank. 107 00:04:17,040 --> 00:04:18,149 Let's see, 108 00:04:18,149 --> 00:04:21,610 g++ console 109 00:04:25,140 --> 00:04:25,973 template. 110 00:04:25,973 --> 00:04:27,240 I think it's pretty picky about spaces, 111 00:04:27,240 --> 00:04:29,670 so I'm just gonna use those dashes. 112 00:04:29,670 --> 00:04:31,590 And it is a console application. 113 00:04:31,590 --> 00:04:33,540 We could that if, if you leave it as console 114 00:04:33,540 --> 00:04:35,250 it'll be in the console group. 115 00:04:35,250 --> 00:04:38,103 I'm actually gonna change that to user template. 116 00:04:39,510 --> 00:04:41,813 And then you can give any description you want. 117 00:04:43,350 --> 00:04:45,300 I'll just say Frank's console template. 118 00:04:48,210 --> 00:04:50,550 That's it. I'll select Okay. 119 00:04:50,550 --> 00:04:52,680 And now we've got a new template that's stored. 120 00:04:52,680 --> 00:04:54,720 So, if I go back to my workspace 121 00:04:54,720 --> 00:04:55,950 and I wanna create a new project. 122 00:04:55,950 --> 00:04:58,200 Now, let me close all this up. 123 00:04:58,200 --> 00:05:01,203 I'm gonna right click and say New Project. 124 00:05:02,280 --> 00:05:03,960 And now you can go down to your templates 125 00:05:03,960 --> 00:05:06,330 and go down to your User templates. 126 00:05:06,330 --> 00:05:07,770 Right here. 127 00:05:07,770 --> 00:05:11,190 And you should see that one we just created right here. 128 00:05:11,190 --> 00:05:13,110 So we can just select that. 129 00:05:13,110 --> 00:05:17,493 Next, I'll just say project one, 130 00:05:18,420 --> 00:05:20,160 select Next. 131 00:05:20,160 --> 00:05:23,250 Keep the defaults for the compilers and finish. 132 00:05:23,250 --> 00:05:25,680 At this point, you can double click here to 133 00:05:25,680 --> 00:05:27,753 make that project the active project. 134 00:05:28,680 --> 00:05:30,900 And we'll look at the main.cpp. 135 00:05:30,900 --> 00:05:34,380 You can see it's the main CPP that we just typed. 136 00:05:34,380 --> 00:05:35,460 Also, if you right click 137 00:05:35,460 --> 00:05:38,490 on the project and you go down to the settings 138 00:05:38,490 --> 00:05:41,010 you can see a code completion is C++ 14. 139 00:05:41,010 --> 00:05:43,380 And the global settings have the appropriate 140 00:05:43,380 --> 00:05:44,793 compiler flags that we need. 141 00:05:45,810 --> 00:05:46,643 That's it. 142 00:05:46,643 --> 00:05:47,973 We'll test this real quick. 143 00:05:49,260 --> 00:05:50,790 Let's run. 144 00:05:50,790 --> 00:05:54,420 Build, and execute and Hello World. 145 00:05:54,420 --> 00:05:55,740 That's it. So now you've got a project 146 00:05:55,740 --> 00:05:56,790 you're all set up. 147 00:05:56,790 --> 00:05:58,620 You can create as many of these as you like. 148 00:05:58,620 --> 00:06:00,503 Tweak the settings as far as you like. 149 00:06:00,503 --> 00:06:03,210 It's really up to you to decide what you wanna do 150 00:06:03,210 --> 00:06:04,260 with the project templates. 151 00:06:04,260 --> 00:06:06,750 But for this course, include iostream. 152 00:06:06,750 --> 00:06:07,890 Give yourself a main. 153 00:06:07,890 --> 00:06:09,720 You may or may not want this line right here, 154 00:06:09,720 --> 00:06:10,950 since you know you're probably gonna get rid 155 00:06:10,950 --> 00:06:12,930 of it anyway when we start writing other code. 156 00:06:12,930 --> 00:06:16,560 But at a minimum, do something like that. 157 00:06:16,560 --> 00:06:17,790 When you create a new project, 158 00:06:17,790 --> 00:06:19,390 you'll be ready to start coding.