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
During your lab session, you'll be exploring some of the features of each of these IDEs.
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.
58
63
59
-
\newpage
60
-
## Questions
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
66
+
to choose the "Console application" option:
61
67
62
-
1. Click the "Build" drop-down menu in Geany. What are the sub-menu options?
Note that we want to include the grayed-out options, too.
65
-
Hint: there are seven of them.
66
-
\vspace{10em}
70
+
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.
67
72
68
-
2. Click the "Help" drop-down menu in Code::Blocks. What are the sub-menu options?
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":
69
78
70
-
Don't worry about sub-menus.
71
-
Hint: there are three of them.
72
-
\vspace{10em}
73
-
\newpage
79
+
{width=50%}
74
80
81
+
### Building
75
82
76
-
## Quick Reference
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%}
77
120
78
-
### General Tips
121
+
In the same menu, under the "Code refactoring" submenu, you can rename a variable or function across all files in your project:
79
122
80
-
- Make sure you start Xming before you try to forward any X11 windows!
81
-
- You won't be able to use bash within the shell that's running `geany` or `codeblocks`.
82
-
You may find it useful to keep a couple of PuTTY windows open while you work.
123
+
{width=80%}
83
124
84
-
### Geany
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):
85
127
86
-
#### Troubleshooting
128
+

87
129
88
-
- If geany complains that it’s unable to open its shell...
89
-
1. Go to \menu{Edit > Preferences > Tools}
90
-
2. Change Terminal from `x-terminal-emulator -e "/bin/sh %c"` to `xterm -e "/bin/sh %c"`
91
-
3. Save your changes
130
+
Then select your function from the next drop-down, and Code::Blocks will jump you to that point in the file!
92
131
93
-
#### Geany Features
132
+
{width=80%}
94
133
95
-
- \keys{F9} Builds the project
96
-
- \keys{F5} Runs the project
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.
97
136
98
-
#### Building with Geany
137
+
{width=80%}
99
138
100
-
It doesn't work so well for multi-file projects.
139
+
### Debugging
101
140
102
-
After you create a project...
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.
103
143
104
-
- Go to \menu{Project > Properties > Build}
105
-
- Find the "Build" command (`g++ -Wall -o "%e" "%f"`)
106
-
- Change it to `g++ -Wall -o "%e" *.cpp`
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:
107
147
108
-
#### Writing code with Geany
148
+
{width=60%}
109
149
110
-
- \keys{\ctrl + t} -- Go to function implementation
111
-
- \keys{\ctrl + space} -- Show completions.
112
-
- Set space preference to "Spaces" in \menu{Edit > Preferences > Editor > Indentation}
113
-
- You can auto-close brackets and parentheses as well.
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%}
168
+
169
+
\newpage
170
+
## Questions
171
+
Name: `______________________________`
172
+
173
+
1. In your own words, list three features of an IDE.
174
+
\vspace{10em}
175
+
176
+
2. Think back to chapter 1. How do IDEs and text editors differ?
177
+
\newpage
178
+
179
+
180
+
## Quick Reference
181
+
182
+
### Troubleshooting
118
183
119
184
- Don't start Code::Blocks if your `pwd` is in your `SDRIVE`.
120
185
Try changing to your linuxhome directory (i.e., `cd ~`).
121
186
Otherwise you’ll be waiting *all day* for Code::Blocks to open up.
122
187
- If Code::Blocks doesn't let you navigate to your cloned repository, you can find it by going the long way.
123
188
You can find your SDRIVE by going to its absolute path: `/nethome/users/<username>/cs1001/lab06/` (or whatever you call your repository.)
124
189
125
-
####Building with Code::Blocks
190
+
### Building with Code::Blocks
126
191
127
192
- \keys{F9} -- Build and run
128
193
- \keys{\ctrl + F9} -- Build
129
194
- \keys{\ctrl + F10} -- Run
130
195
- Enable `-Wall` in \menu{Project > Build Options}
131
196
132
-
####Writing code with Code::Blocks
197
+
### Writing code with Code::Blocks
133
198
134
199
- \keys{\ctrl + .} -- Go to function implementation.
135
200
- \keys{\ctrl + \shift + .} -- Go to function declaration.
@@ -138,21 +203,14 @@ After you create a project...
- Tutorial from cplusplus.com: [http://www.cplusplus.com/doc/tutorial/introduction/codeblocks/](http://www.cplusplus.com/doc/tutorial/introduction/codeblocks/)
150
208
151
209
### Other IDEs
152
210
153
211
There are a bunch of other IDEs out there.
154
212
Some are free; some are not.
155
-
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.
156
214
157
215
- Visual Studio Code: [https://code.visualstudio.com/](https://code.visualstudio.com/)
0 commit comments