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: Section22-Bonus_Section-Using_Visual_Studio_Code/readme.md
+129-21
Original file line number
Diff line number
Diff line change
@@ -7,24 +7,25 @@
7
7
8
8
## Installing Extensions
9
9
10
-
1. C/C++
11
-
p.s. This [link](https://code.visualstudio.com/docs/languages/cpp#_install-the-extension) could be more useful.
10
+
1. C/C++ --- p.s. This [link](https://code.visualstudio.com/docs/languages/cpp#_install-the-extension) could be more useful.
12
11
- Launch VSCode
13
12
- Select the Extensions view icon, bottom, on the Activity bar, on the far left
14
-
- Search for `c++`
15
-
- Select the one supported by Microsoft (purple circle) and `install`
13
+
- Search for ***c++***
14
+
- Select the one supported by Microsoft (purple circle) and **install**
16
15
2. CodeLLDB
17
-
- Search for `codelldb`
18
-
- Select the only one supported by Vadim Chugunov and `install`
16
+
- Search for ***codelldb***
17
+
- Select the only one supported by Vadim Chugunov and **install**
19
18
20
19
# Building and Running C++ Programs with VSCode on Mac OSX
21
20
22
21
## Configure json files
23
22
- Launch VSCode
24
-
- Select `Open Folder`
23
+
- Select **Open Folder**
25
24
- Select the folder where you want to edit and compile your C++ codes
26
25
- Copy below codes and save file as `main.cpp` for example
27
26
27
+
### main.cpp
28
+
28
29
```c++
29
30
#include<iostream>
30
31
usingnamespacestd;
@@ -35,36 +36,101 @@ int main() {
35
36
}
36
37
```
37
38
38
-
- Select `View` at the Mac menu Bar, then `Command Palatte...`
39
+
- Select **View** at the Mac menu Bar, then **Command Palatte...**
39
40
- Select `C/C++: Edit Configurations (UI)`
40
41
- Modify **Compiler path** by clicking on the drop down arrow and select `/usr/bin/g++`
41
42
- Modify **C++ standard** to `c++20`
42
43
- Save... Notice `.vscode` > `c_cpp_properties.json` is automatically generated on the Activity bar
43
44
45
+
### c_cpp_properties.json
46
+
47
+
```json
48
+
{
49
+
"configurations": [
50
+
{
51
+
"name": "Mac",
52
+
"includePath": [
53
+
"${workspaceFolder}/**"
54
+
],
55
+
"defines": [],
56
+
"macFrameworkPath": [],
57
+
"compilerPath": "/usr/bin/g++",
58
+
"cStandard": "gnu17",
59
+
"cppStandard": "c++20",
60
+
"intelliSenseMode": "macos-gcc-x64"
61
+
}
62
+
],
63
+
"version": 4
64
+
}
65
+
```
66
+
44
67
VSCode require the `.cpp` file to be selected prior building it
45
68
46
69
- Select the `main.cpp` just created
47
-
- Select `Terminal` at the Mac menu Bar, then `Configure Default Build Task...`
70
+
- Select **Terminal** at the Mac menu Bar, then **Configure Default Build Task...**
48
71
- Select `C/C++: g++ build active file`
49
72
- A new file, `tasks.json`, is automatically generated, which contains information on how to build C++ projects
50
73
- Modify line 8 - 13 as below:
51
74
75
+
### tasks.json
52
76
```json
53
-
"args": [
54
-
"-g",
55
-
"-Wall", // to generate all warnings
56
-
"-std=c++20", // use c++20 standard
57
-
// "${file}",
58
-
"${fileDirname}/*.cpp", // compile all c++ files
59
-
"-o",
60
-
"${fileDirname}/${fileBasenameNoExtension}"
61
-
],
77
+
{
78
+
"version": "2.0.0",
79
+
"tasks": [
80
+
{
81
+
"type": "cppbuild",
82
+
"label": "C/C++: g++ build active file",
83
+
"command": "/usr/bin/g++",
84
+
"args": [
85
+
"-g",
86
+
"-Wall",
87
+
"-std=c++20",
88
+
"${fileDirname}/*.cpp",
89
+
"-o",
90
+
"${fileDirname}/${fileBasenameNoExtension}"
91
+
],
92
+
"options": {
93
+
"cwd": "${fileDirname}"
94
+
},
95
+
"problemMatcher": [
96
+
"$gcc"
97
+
],
98
+
"group": "build",
99
+
"detail": "compiler: /usr/bin/g++"
100
+
},
101
+
{
102
+
"type": "cppbuild",
103
+
"label": "C/C++: g++ build active file",
104
+
"command": "/usr/bin/g++",
105
+
"args": [
106
+
"-g",
107
+
"-Wall", // to generate all warnings
108
+
"-std=c++20", // use c++20 standard
109
+
// "${file}",
110
+
"${fileDirname}/*.cpp", // compile all c++ files
111
+
"-o",
112
+
"${fileDirname}/${fileBasenameNoExtension}"
113
+
],
114
+
"options": {
115
+
"cwd": "${fileDirname}"
116
+
},
117
+
"problemMatcher": [
118
+
"$gcc"
119
+
],
120
+
"group": {
121
+
"kind": "build",
122
+
"isDefault": true
123
+
},
124
+
"detail": "compiler: /usr/bin/g++"
125
+
}
126
+
]
127
+
}
62
128
```
63
129
64
130
## Building C++ programs
65
131
66
132
- Select `main.cpp` and let's compile the code
67
-
- Select `Terminal` at the Mac menu bar, then `Run Build Task...`
133
+
- Select **Terminal** at the Mac menu bar, then **Run Build Task...**
68
134
- Terminal should automatically appear towards the bottom and expected output
69
135
70
136
```c++
@@ -81,7 +147,7 @@ Terminal will be reused by tasks, press any key to close it.
81
147
82
148
## Running C++ Programs
83
149
84
-
- Right click on the `main` executable file and select `Open in Integrated Terminal`
150
+
- Right click on the `main` executable file and select **Open in Integrated Terminal**
85
151
- The terminal will then open at the proper file path, and input command `ls` will list the directories under the file path. The expected output is
86
152
87
153
```
@@ -98,4 +164,46 @@ clang: error: no such file or directory: 'test2.cpp'
98
164
clang: error: no input files
99
165
```
100
166
101
-
Despite the `.cpp` file name is different, I learned that there will be buile errors if `tes1.cpp` and `test2.cpp` are in the same directory during build.
167
+
Despite the `.cpp` file name is different, I learned that there will be buile errors if `tes1.cpp` and `test2.cpp` are in the same directory during build.
168
+
169
+
# Debugging C++ Programs with VSCode on Mac OSXing
170
+
- Select `main.cpp`
171
+
- Select **Run** at the Mac menu bar, then **Add Configuration...**
172
+
- Select `C++ (GDB/LLDB)`
173
+
- Select `g++ - Build and debug active file`
174
+
- Exit out of debugger by selecting red sqaure box
175
+
- Notice `launch.json` is automatically created
176
+
- Modify `launch.json` as below
177
+
178
+
### launch.json
179
+
180
+
```json
181
+
{
182
+
// Use IntelliSense to learn about possible attributes.
183
+
// Hover to view descriptions of existing attributes.
184
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
0 commit comments