须要安装的扩展 C/C++
linux
若是是远程 Linux上开发还须要安装 Remote Developmentshell
建立工做目录后,代码远程克隆... 省略..json
建立项目配置文件,主要的做用是代码智能提示,错误分析等等...
按F1,输入 C/C++ 选择 编辑配置UI或者json 这个操做会生成 .vscode/c_cpp_properties.json 配置文件ui
修改相关的参数,如头文件路径,预约义参数,编译器等spa
{ "configurations": [ { "name": "Linux", "includePath": [ "${workspaceFolder}/**" // 包含了当前工做下全部头文件,若是没有在该目录下须要引入 ], "defines": [ // 这里是项目中须要的预约义 LINUX环境一般须要加LINUX "LINUX", "ACI_TEST" ], "compilerPath": "/usr/bin/g++", // 编译器程序 "cStandard": "gnu99", "cppStandard": "gnu++14", "intelliSenseMode": "linux-gcc-x64" } ], "version": 4 }
(注意) 这个配置文件与编译和执行没有任何关系,它仅仅用于代码提示和错误提示debug
生成了2个文件3d
.vscode/launch.json调试
{ // 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}", // 须要调试的程序路径,如 ${workspaceFolder}/test "args": [], // 调试程序须要接收的参数,如 test -c => "args": ["-c"] "stopAtEntry": false, "cwd": "${workspaceFolder}", "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", // 在调试以前须要作什么, 就是当你按下f5, 首先会去不如编译程序... make 或者 gcc ,g++ 编译上面路径的程序, // "C/C++: g++ build active file" 只是一个名称,它会去 tasks.json 中找这个名称, 执行 这个任务以后开始调试 "miDebuggerPath": "/usr/bin/gdb", // 调试的gdb ,要确保环境已经安装了gdb, sudo apt install gdb "envFile": "${workspaceFolder}/.env" // 配置环境变量的文件路径,下面会继续说明用处. } ] }
.vscode/tasks.jsoncode
{ "tasks": [ { "type": "cppbuild", // shell 类型... "label": "C/C++: g++ build active file", // preLaunchTask 的名称 "command": "/usr/bin/g++", // 编译器 "args": [ "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}" ], "options": { "cwd": "${workspaceFolder}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "Task generated by Debugger." } ], "version": "2.0.0" }
这个文件就是怎么去编译你的程序,没什么可说 , make 或者 gcc g++ 编译
贴一个个人项目 tasks 用make 编译orm
{ "tasks": [ { "type": "shell", "label": "make_1", "command":"make -j6 -f makefile_local.mk 2>build_error.log", "options": { "cwd": "${workspaceFolder}/UnitTesting/" }, "problemMatcher": [] }, { "type": "shell", "label": "make_2", "command":"make -j6 -f makefile_local.mk 2>build_error.log", "options": { "cwd": "${workspaceFolder}/" }, "problemMatcher": [] }, { "type": "shell", "label": "build", "dependsOrder": "sequence", "dependsOn": [ "make_2", "make_1" ], "options": { "cwd": "${workspaceFolder}" }, "problemMatcher": [] } ], "version": "2.0.0" }
.env
LD_LIBRARY_PATH=./lib:/lib64
用途是: 若是个人程序须要依赖某个动态库,好比,工做目录下lib和lib64里面是须要的动态库,能够在这里加入环境变量,能够是相对路径,或者绝对路径.
当前你也能够在系统环境变量里面设置
以上是 C/C++ 使用VScode的方法,若是对你有帮助,请点一个支持吧 _