build-essential 包含了 GNU 编辑器集合、GNU 调试器、其他编译软件所必需的开发库和工具,简单来说,安装了 build-essential 就相当于安装了 gcc、g++、make 等工具。
1
sudo apt install build-essential
查看 gcc 版本:
1 2 3 4 5
# gcc --version gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0 Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
查看 g++ 版本:
1 2 3 4 5
# g++ --version g++ (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0 Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
查看 make 版本:
1 2 3 4 5 6 7
# make --version GNU Make 4.2.1 Built for x86_64-pc-linux-gnu Copyright (C) 1988-2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version3orlater <http://gnu.org/licenses/gpl.html> This is free software: you are free tochangeand redistribute it. There is NO WARRANTY, to the extent permitted by law.
安装 gdb
安装命令
1
sudo apt install gdb
查看 gdb 版本:
1 2 3 4 5 6
# gdb --version GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2 Copyright (C) 2020 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
安装 cmake
安装命令
1
sudo apt install cmake
查看 cmake 版本:
1 2 3 4
# cmake --version cmake version 3.16.3
CMake suite maintained and supported by Kitware (kitware.com/cmake).
VS Code 环境配置
VS Code 安装
安装 VS Code
在 VS Code 中安装 C/C++ Extension Pack 扩展组件,其他插件会附带安装
我同时也安装了 C/C++,Code Runner, C/C++ Compile Run 扩展
环境配置
VS Code 与 Visual Studio或其他的大型IDE的工作机制类似,一般都是每个project有一个单独的工作空间(也就是目录),可以为每个工作空间配置定制的环境,也可以配置默认的环境。在配置C/C++开发环境时,基本会配置3个文件,tasks.json、launch.json及c_cpp_properties.json,三个文件都在 .vscode目录下。
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version":"0.2.0", "configurations":[
{ "name":"g++ - Build and debug active file", "type":"cppdbg", "request":"launch", "program":"${fileDirname}/${fileBasenameNoExtension}", "args":[], "stopAtEntry":false, "cwd":"${fileDirname}", "environment":[], "externalConsole":false, "MIMode":"gdb", "setupCommands":[ { "description":"Enable pretty-printing for gdb", "text":"-enable-pretty-printing", "ignoreFailures":true } ], "preLaunchTask":"C/C++: g++ build active file", "miDebuggerPath":"/usr/bin/gdb" } ] }