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
Copy file name to clipboardExpand all lines: part_one/01_running.md
+30-36Lines changed: 30 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,41 +10,22 @@ Whereas Python is mostly fairly simple to get working with straight away, especi
10
10
11
11
There are a variety of platforms which will allow you to run small one file C & C++ programs or code snippets directly from your browser. A (non-exhaustive) list of examples includes:
12
12
-[Replit](https://replit.com/languages/cpp)
13
-
-[Codepad](https://codepad.org/)
13
+
-[Codepad](https://codepad.app/)
14
14
-[Ideone](https://ideone.com/)
15
15
16
16

17
17
18
18
On each of these platforms you can cut & paste code from the examples in this primer, and then run the code to generate output, usually with a single click of the mouse on the button labelled `Run`. Note that not all platforms will let you interact with your code while it runs (Replit will, as well as linking to your GitHub account if you'd like to save your work).
19
19
20
-
## Visual Studio Code & Devcontainers
21
-
```{index} compiling: via docker
22
-
```
23
-
24
-
A more local option is to take advantage of the combined power of Docker and Visual Studio Code to provide files which again you can often compile with one click.
25
-
26
-

27
-
28
-
To begin, fork the accompanying [examples repository](https://github.com/ese-msc/c-examples) and download it, then with Docker desktop running, open your local repository in VS code. You will be presented with a query banner "Folder contains a Dev Container configuration file. Reopen folder to develop in a container (learn more).". Select "Reopen in Container". This will restart the VS Code editor window, while connecting to a Docker container build from the repository [C examples Dockerfile](https://ese-msc/c-examples/.devcontainer/Dockerfile). This container has `git` and `Python` installed, together a working linux C++ compiler (the GNU compiler) and some useful VS Code extensions installed.
29
-
30
-
For simple, non-interactive C++ programmes contained in a single file, you can now build & run them with the Run Code button (ctrl+alt+N). For interactive files, you will need to run the program yourself using (for a file `hello.cpp` in the current directory) a command like:
31
-
32
-
```
33
-
g++ -o hello hello.cpp
34
-
./hello
35
-
```
36
-
37
-
Here `g++` is the name of the linux GNU C++ compiler, the `-o` option specifies the name of the output executable file (the default is `a.out`) and we must list the `.cpp` source file to compile into it. The second line then runs our new executable.
38
-
39
20
## Compiling natively
21
+
A more long-term solution, and what you will be using during the Advanced Programming module, is to use a local compiler on your computer. There are many options out there, which depend on which operating system you are using. The following are some popular options available to you.
40
22
41
-
### Windows: Visual Studio
42
-
```{index} compiling:windows native
43
-
```
44
-
45
-
For Windows users only, you can obtain the Microsoft C/C++ compiler by downloading the Visual Studio community package [here](https://visualstudio.microsoft.com/vs/community/). Visual Studio is a sister package to Visual Studio Code, which combines build tools for several programming languages along with an Integrating Development Environment (IDE) to code them in.
23
+
```{important} In the **Advanced Programming** module in 2025-26, we will be using the following IDE and compiler combination:
24
+
- VS Code
25
+
- `gcc` version 15
46
26
47
-
To compile a file, we must create a matching Visual Studio solution file. For a one line program, the easiest way to do this is to start from the `console application` template project, and modify the default file appropriately. We can then compile and run our source using the `Local Windows Debugger` play button, or the `Debug>Start Debugging (F5)` menu option.
27
+
Please see below for how to install this combination on the relevant operating system for your laptop.
28
+
```
48
29
49
30
### Apple Macs: `gcc` or `clang`
50
31
```{index} compiling:mac
@@ -62,29 +43,29 @@ Most Mac users on the course will already have Homebrew installed, but for those
62
43
brew install gcc
63
44
```
64
45
65
-
will install a recent version of `gcc` (version 14 as of early December 2024) as well as placing it in your standard path. Once installed, (and having opened a new terminal) you can confirm that things work by running the following command in a terminal
46
+
will install a recent version of `gcc` (version 15 as of early December 2025) as well as placing it in your standard path. Once installed, (and having opened a new terminal) you can confirm that things work by running the following command in a terminal
66
47
67
48
```
68
-
gcc-14 --version
49
+
gcc-15 --version
69
50
```
70
51
71
52
You should see a response something like
72
53
73
54
```
74
-
gcc-14 (Homebrew GCC 14.2.0) 13.4.0
75
-
Copyright (C) 2024 Free Software Foundation, Inc.
55
+
gcc-15 (Homebrew GCC 15.2.0) 15.2.0
56
+
Copyright (C) 2025 Free Software Foundation, Inc.
76
57
This is free software; see the source for copying conditions. There is NO
77
58
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
78
59
```
79
60
80
61
To compile a C++ file called `hello.cpp` into an exectuable called `hello`, then run it, use a command like
81
62
82
63
```
83
-
g++-14 -o hello hello.cpp
64
+
g++-15 -o hello hello.cpp
84
65
./hello
85
66
```
86
67
87
-
Here `g++-14` is the name of your new GNU C++ compiler (specifically, version number 14), the `-o` option specifies the name of the output file (the default is `a.out`) and we must list the `.cpp` source file to compile into it. The second line then runs our new executable file which we have just compiled.
68
+
Here `g++-15` is the name of your new GNU C++ compiler (specifically, version number 14), the `-o` option specifies the name of the output file (the default is `a.out`) and we must list the `.cpp` source file to compile into it. The second line then runs our new executable file which we have just compiled.
88
69
89
70
Remember, we only need to compile once, and then we can run the executable as many times as we like. If we make any changes to the source code, we must recompile before we can run the new version and see the results.
This is free software; see the source for copying conditions. There is NO
143
124
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
144
125
```
@@ -152,6 +133,19 @@ g++ -o hello hello.cpp
152
133
153
134
Here `g++` is the name of your new GNU C++ compiler, the `-o` option specifies the name of the output file (the default is `a.out`) and we must list the `.cpp` source file to compile into it. The second line then runs our new executable.
154
135
136
+
137
+
### Windows: Visual Studio
138
+
```{index} compiling:windows native
139
+
```
140
+
141
+
For Windows users only, you can also obtain the Microsoft C/C++ compiler (MSVC) by downloading the Visual Studio community package [here](https://visualstudio.microsoft.com/vs/community/). Visual Studio is a sister package to Visual Studio Code, which combines build tools for several programming languages along with an Integrating Development Environment (IDE) to code them in.
142
+
143
+
To compile a file, we must create a matching Visual Studio solution file. For a one line program, the easiest way to do this is to start from the `console application` template project, and modify the default file appropriately. We can then compile and run our source using the `Local Windows Debugger` play button, or the `Debug>Start Debugging (F5)` menu option.
144
+
145
+
```{note}
146
+
While MSVC and Visual Studio are a powerful combo, we will not be using them much in the Advanced Programming module. For those of you who go on to study Patterns for Parallel Programming (ACSE), you will likely see this IDE/compiler combination in more detail.
147
+
```
148
+
155
149
## Summary
156
150
157
151
You should now have found a method to compile C/C++ programs which works for you. It is fine to use either of the first two options for the duration of this primer, but you will find a local compiler much more use during the actual Advanced Programming course.
0 commit comments