Ubuntu 18.0/20.0 vscode 配置 C环境
文件夹配置参考:
https://code.visualstudio.com/docs/editor/variables-reference
${workspaceFolder} - VS Code 中打开的文件夹目录 (通常是项目的位置)
${workspaceFolderBasename} - 没有任何斜杠 (/)的 VS Code 中打开的文件夹目录
${file} - 目前打开文件的绝对位置
${relativeFile} - 目前打开文件相对于 workspaceFolder 的相对位置
${fileBasename} - 目前打开文件的文件名(有拓展名,如: main.cpp)
${fileBasenameNoExtension} - 目前打开文件的出去拓展名的文件名(无拓展名, 如: main.cpp)
${cwd} - task runner的工作目录
${fileDirname} - 目前打开文件的目录位置
${fileExtname} - 目前打开文件的拓展名
${lineNumber} - 文件中目前被选择的行数
${selectedText} - 文件中目前被选择的内容
sudo apt-get update
sudo apt install gcc
sudo apt install gdb
sudo apt install clang
sudo apt install lldb
c_cpp_properties.json
{ "configurations": [ { "name": "linux-gcc-x64", "includePath": [ "${workspaceFolder}/**" ], "compilerPath": "/usr/bin/gcc", "cStandard": "${default}", "cppStandard": "${default}", "intelliSenseMode": "linux-gcc-x64", "compilerArgs": [ "" ] } ], "version": 4 }
launch.json
{ "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/${fileBasenameNoExtension}.out", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "preLaunchTask": "build", "miDebuggerArgs": "-q -ex quit; wait() { fg >/dev/null; }; /usr/bin/gdb -q --interpreter=mi", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] }, { "name": "C/C++ Runner: Debug Session", "type": "cppdbg", "request": "launch", "args": [], "stopAtEntry": false, "externalConsole": false, "cwd": "/home/geovindu/桌面/ctest", "program": "/home/geovindu/桌面/ctest/build/Debug/outDebug", "MIMode": "gdb", "miDebuggerPath": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
settings.json
{ "C_Cpp_Runner.cCompilerPath": "gcc", "C_Cpp_Runner.cppCompilerPath": "g++", "C_Cpp_Runner.debuggerPath": "gdb", "C_Cpp_Runner.cStandard": "c11", "C_Cpp_Runner.cppStandard": "c++11", "C_Cpp_Runner.msvcBatchPath": "", "C_Cpp_Runner.useMsvc": false, "C_Cpp_Runner.warnings": [ "-Wall", "-Wextra", "-Wpedantic", "-Wshadow", "-Wformat=2", "-Wcast-align", "-Wconversion", "-Wsign-conversion", "-Wnull-dereference" ], "C_Cpp_Runner.msvcWarnings": [ "/W4", "/permissive-", "/w14242", "/w14287", "/w14296", "/w14311", "/w14826", "/w44062", "/w44242", "/w14905", "/w14906", "/w14263", "/w44265", "/w14928" ], "C_Cpp_Runner.enableWarnings": true, "C_Cpp_Runner.warningsAsError": false, "C_Cpp_Runner.compilerArgs": [], "C_Cpp_Runner.linkerArgs": [], "C_Cpp_Runner.includePaths": [], "C_Cpp_Runner.includeSearch": [ "*", "**/*" ], "C_Cpp_Runner.excludeSearch": [ "**/build", "**/build/**", "**/.*", "**/.*/**", "**/.vscode", "**/.vscode/**" ], "C_Cpp_Runner.useAddressSanitizer": false, "C_Cpp_Runner.useUndefinedSanitizer": false, "C_Cpp_Runner.useLeakSanitizer": false, "C_Cpp_Runner.showCompilationTime": false, "C_Cpp_Runner.useLinkTimeOptimization": false }
tasks.json (C)
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "build", "type": "shell", "command": "gcc", //C++ using g++ "args": ["-g", "${file}", "-std=c11", "-o", "${fileBasenameNoExtension}.out"] } ] }
{ "tasks": [ { "type": "cppbuild", "label": "C/C++: gcc.exe 生成活动文件", //和preLaunchTask一致 "command": "gcc", //让g++执行 的.c文件变为.exe文件 用可以用: C:\\GC\\mingw64\\bin\\gcc.exe "args": [ "-fdiagnostics-color=always", "-g", //调试的选项 //"${file}", //当执行哪一个文件,编译器就解释那个文件。 "${workspaceFolder}/*.c", //*.c 需要当前指定的文件至.c的文件编译所有.c的文件 ${workspaceFolder}/*.c 在当前选择其他JSON文件时,它也会编译 https://stackoverflow.com/questions/71924077/configuring-task-json-and-launch-json-for-c-in-vs-code "-std=c11", "-finput-charset=UTF-8", "-fexec-charset=GBK", //解决输出中文问题 "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe" //生成exe文件 ], "options": { "cwd": "${fileDirname}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "调试器生成的任务。" } ], "version": "2.0.0" }
tasks.json (C++)
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "build", "type": "shell", "command": "g++", //g++ c++ c++11 gcc c11 "args": ["-g", "${file}", "-std=c++11", "-o", "${fileBasenameNoExtension}.out"] } ] }
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "build", "type": "shell", "command": "gcc", //g++ c++ c++11 gcc c11 "args": [ "-g", //"${file}", "*.c", "-std=c11", "-o", "${fileBasenameNoExtension}.out" ] } ] }
https://code.visualstudio.com/docs/cpp/customize-default-settings-cpp
https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference
C_Cpp.default.cStandard : c89 | c99 | c11 | c17
C_Cpp.default.cppStandard : c++98 | c++03 | c++11 | c++14 | c++17 | c++20 | c++23
sudo apt-get update
sudo apt install openssh-server
sudo apt-get install vim
vim /etc/ssh/sshd_config
PermitRootLogin yes
sudo /etc/init.d/ssh restart
sudo ps -e | grep ssh
sudo apt-get install net-tools