You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Then you can travel back to 1980 when things were actually good[^reagan].
32
+
Then you can travel back to 1980 when things were actually good.[^reagan]
33
33
34
34
### Takeaways
35
35
36
-
- Gain experience with Integrated Development Environments (IDEs)
37
-
- Explore editor features
38
-
- Try build (compilation) features
39
-
- Experiment with built-in debugging tools
36
+
- Explore editor features
37
+
- Try build (compilation) features
38
+
- Experiment with built-in debugging tools
40
39
41
40
## Walkthrough
42
41
43
42
Usually when we connect to a remote Linux machine, all we need is a shell, and PuTTY does everything we need.
44
43
For this lab, we're going to need to setup X-forwarding as well.
45
-
If you haven't already, be sure to reference the appendix on [X-forwarding].
44
+
If you haven't already, be sure to reference the appendix on X-forwarding.
45
+
Make sure you start Xming before you try to forward any X11 windows!
46
+
You won't be able to use bash within the shell that's running `codeblocks`.
47
+
You may find it useful to keep a couple of PuTTY windows open while you work.
46
48
49
+
We'll be using the Code::Blocks IDE.
50
+
To open this IDE, run the `codeblocks` command in a shell.
51
+
Hopefully, after a while of thinking about it, the system will deign to display a window somewhat like the following:
52
+
53
+

54
+
55
+
Look! Buttons! Windows! Tabs!
56
+
57
+
### Getting started
58
+
59
+
Code::Blocks organizes your code into projects.
60
+
It's best to make one project per program.
61
+
Each project has an associated project file that ends in `.cbp`; this file keeps track of the code files in your project, how to build them, and various other
62
+
sundries.
63
+
64
+
To create a new project, click any of the numerous "new project" buttons.
65
+
Code::Blocks knows how to make a bunch of different kinds of software, but if you want to make a plain 'ol terminal application in C++, you'll want
Code::Blocks will ask you for a name and a location to store the project in.
71
+
It will also ask you about compilers and targets --- the default values are fine; we'll talk about them later.
72
+
73
+
Once you've created a project, you can add new files to it via any of the "new" buttons.
74
+
Or, you may have some files that you'd like to add to your project --- maybe you have some starter code for an assignment,
75
+
or you're making a project for something you were already working on.
76
+
To do this, first put your files where you want them (usually in the project directory --- or you can make the project directory be the location of your files),
77
+
then right-click the project and click "Add files":
78
+
79
+
{width=50%}
80
+
81
+
### Building
82
+
83
+
Once you've created a project and put some files in it, you'll probably want to compile your code!
84
+
Below you can see the various compilation options Code::Blocks offers --- you can build your code and run it in one step!
When you click "build", Code::Blocks only compiles the files that have changed since you last built the project.
89
+
Typically this works fine, but sometimes you'll want to recompile everything; for this task, the "rebuild" button is what you want.
90
+
91
+
Projects have one or more "build targets" --- by default, a "debug" target and a "release" target.
92
+
These targets primarily change the flags passed to the compiler; the debug target usually builds faster and includes debugging symbols,
93
+
but the code produced by the release target is more efficient.
94
+
If you are planning to use a debugger or Valgrind, you should use the "debug" target.
95
+
96
+
You can see your project's target configurations in the project build options (right-click on the project and choose "Build options").
97
+
For now, the options Code::Blocks chooses for you should be sufficient; later on in this book we'll discuss some additional flags that you might want to add.
98
+
99
+
<!-- {width=80%} -->
100
+
101
+
### Navigation and Editing
102
+
103
+
One big draw of using an IDE is the out-of-the-box editing and navigation features.
104
+
Since Code::Blocks is primarily designed for writing C++ programs, it offers special features for editing C++ code.
105
+
106
+
If you type a class instance name followed by a `.`, Code::Blocks will show a list of potential member functions and variables you may want:
107
+
108
+
{width=80%}
109
+
110
+
You can type the first few letters of the desired method or variable to narrow the list down,
111
+
then press \keys{\tab} to have Code::Blocks complete the name for you.
112
+
113
+
Once you've typed out a complete function name, Code::Blocks will show you the type signature, so you know what parameters it takes:
You can also access the "Open Declaration" and "Open Implementation" features of the tab completion window by right-clicking on any function or variable name:
118
+
119
+
{width=70%}
120
+
121
+
In the same menu, under the "Code refactoring" submenu, you can rename a variable or function across all files in your project:
122
+
123
+
{width=80%}
124
+
125
+
If you are navigating through a large file, you can jump to function implementations with the "Code Completion" toolbar.
126
+
First, select the scope your function is declared in (typically either `<global>` or the name of the class your function is a member of):
127
+
128
+

129
+
130
+
Then select your function from the next drop-down, and Code::Blocks will jump you to that point in the file!
131
+
132
+
{width=80%}
133
+
134
+
You can collapse (or 'fold') code between braces by clicking the `-` button in the margin by the line number.
135
+
This is particularly handy when working with long functions that are hard to fit all on one screen.
136
+
137
+
{width=80%}
138
+
139
+
### Debugging
140
+
141
+
Code::Blocks integrates with the GNU debugger (`gdb`) to make debugging code easier for you.
142
+
We'll talk more about `gdb` in a future chapter, but for now we'll introduce the features Code::Blocks integrates with.
143
+
144
+
In short, a debugger allows you to pause the execution of your program, inspect variables, and step through your code line-by-line.
145
+
You can tell the debugger to stop execution at a specific line by setting a breakpoint on that line: click to the right of the line number,
146
+
and a little stop sign will appear:
147
+
148
+
{width=60%}
149
+
150
+
Once you've set one or more breakpoints, you can click the red arrow on the debugger toolbar to run your program and have it stop at that breakpoint.
Other buttons on the toolbar allow you to step your code by line, or by CPU instruction.
155
+
156
+
When you are running a program in the debugger, you can right-click on variables and "watch" them---this will open a new window that displays that variable
157
+
and its value, along with function argument values and local variable values.
158
+
Once you're watching a variable, you can edit its value while the program is running!
159
+
160
+
{width=45%}
Code::Blocks also opens a tab at the bottom of the window that allows you to send commands to `gdb`, just as you would when using `gdb` from the command line.
165
+
While Code::Blocks doesn't add any new functionality to `gdb`, it does make some common debugging tasks a lot easier!
166
+
167
+
{width=90%}
47
168
48
169
\newpage
49
170
## Questions
171
+
Name: `______________________________`
50
172
173
+
1. In your own words, list three features of an IDE.
51
174
\vspace{10em}
175
+
176
+
2. Think back to chapter 1. How do IDEs and text editors differ?
52
177
\newpage
53
178
54
179
55
180
## Quick Reference
56
181
57
-
### General Tips
58
-
59
-
- Make sure you start Xming before you try to forward any X11 windows!
60
-
- You won't be able to use bash within the shell that's running `codeblocks`.
61
-
You may find it useful to keep a couple of PuTTY windows open while you work.
62
-
63
-
### Code::Blocks
64
-
65
-
#### Troubleshooting
182
+
### Troubleshooting
66
183
67
184
- Don't start Code::Blocks if your `pwd` is in your `SDRIVE`.
68
185
Try changing to your linuxhome directory (i.e., `cd ~`).
69
186
Otherwise you’ll be waiting *all day* for Code::Blocks to open up.
70
187
- If Code::Blocks doesn't let you navigate to your cloned repository, you can find it by going the long way.
71
188
You can find your SDRIVE by going to its absolute path: `/nethome/users/<username>/cs1001/lab06/` (or whatever you call your repository.)
72
189
73
-
####Building with Code::Blocks
190
+
### Building with Code::Blocks
74
191
75
192
- \keys{F9} -- Build and run
76
193
- \keys{\ctrl + F9} -- Build
77
194
- \keys{\ctrl + F10} -- Run
78
195
- Enable `-Wall` in \menu{Project > Build Options}
79
196
80
-
####Writing code with Code::Blocks
197
+
### Writing code with Code::Blocks
81
198
82
199
- \keys{\ctrl + .} -- Go to function implementation.
83
200
- \keys{\ctrl + \shift + .} -- Go to function declaration.
@@ -86,16 +203,14 @@ If you haven't already, be sure to reference the appendix on [X-forwarding].
- Tutorial from cplusplus.com: [http://www.cplusplus.com/doc/tutorial/introduction/codeblocks/](http://www.cplusplus.com/doc/tutorial/introduction/codeblocks/)
93
208
94
209
### Other IDEs
95
210
96
211
There are a bunch of other IDEs out there.
97
212
Some are free; some are not.
98
-
If you like the IDEa of an IDE, but you don't like Geany or Code::Blocks, you may give one of these guys a try.
213
+
If you like the IDEa of an IDE, but you don't like Code::Blocks, you may give one of these guys a try.
99
214
100
215
- Visual Studio Code: [https://code.visualstudio.com/](https://code.visualstudio.com/)
0 commit comments