linux下vscode配置C/C++环境的.json文件

linux下vscode配置C/C++环境的.json文件

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": "available launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

task.json

{
    // 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",        // 编译任务的类型,通常为shell/process类型
            "command": "g++",       // 编译命令
            "args":[
                "-g",               // 该参数使编译器在编译的时候产生调试信息
                "${workspaceFolder}/${fileBasename}",    // 被编译文件,通常为.cpp/.c/.cc文件等
                "-I",                                    // include path指令
                "/usr/include",                          
                "-L",                                    // lib路径
                "/usr/lib/x86_64-linux-gnu",             
                "-l",                                    // 链接库文件1
                "opencv_core",                           
                "-l",                                    // 链接库文件2
                "opencv_highgui",                        
                "-o",                                    // 生成指定名称的可执行文件
                "${workspaceFolder}/${fileBasenameNoExtension}.out"  
          /* -g hello.cpp -I/usr/include -L/usr/lib/x86_64-linux-gnu -lopencv_core -o hello.out */
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "label": "cmakebuild",      
            "type": "shell", 
            "command": "cd build && cmake ../ && make",    // shell 编译命令,做并运算,即前一命令执行失败,则后一命令也不执行
            "args": []
        }
    ] 

}

setting.json

{

    "C_Cpp.default.configurationProvider": "vector-of-bool.cmake-tools",
  
    "cmake.configureSettings": {"CMAKE_TOOLCHAIN_FILE": "toolchain.cmake",
  
    },
  
  }

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "gnu11",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "linux-gcc-x64",
            "configurationProvider": "vector-of-bool.cmake-tools"
        }
    ],
    "version": 4
}
  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Linux配置C/C++环境,可以按照以下步骤进行操作: 1. 首先,确保系统已经安装了gcc、g++和gdb这些必要的工具。可以使用以下命令在终端中检查它们的版本: ``` gcc -v g++ -v gdb -v ``` 如果没有安装,可以使用包管理器安装它们。在Ubuntu上,可以使用如下命令安装: ``` sudo apt-get install build-essential gdb ``` 2. 接下来,打开VS Code编辑器,并安装C/C++扩展。可以在扩展菜单中搜索"C/C++"并安装它。 3. 创建一个C/C++项目文件,在项目文件中编写C/C++代码。可以在项目中创建一个test.cpp文件,并添加以下代码: ```cpp #include <iostream> using namespace std; int main() { cout << "hello world" << endl; return 0; } ``` 4. 打开VS Code的设置(Preferences->Settings),并在用户设置或工作区设置中添加以下配置来指定编译器和调试器: ```json "C_Cpp.default.compilerPath": "gcc", "C_Cpp.default.includePath": ["${workspaceFolder}/**"], "C_Cpp.default.debuggerPath": "gdb", ``` 5. 现在,可以使用VS Code的编译和调试功能。在VS Code中打开test.cpp文件,并按下F5键开始调试。在调试控制台中,应该可以看到"hello world"的输出。 这样就完成了Linux上在VS Code中配置C/C++环境的步骤。通过这样的配置,你可以在VS Code中编写、编译和调试C/C++代码。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Linux系统VsCode 配置C/C++环境](https://blog.csdn.net/qq_42911863/article/details/125619397)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [Linux系统VS Code配置C/C++环境](https://blog.csdn.net/qq_42007287/article/details/124691279)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值