vscode环境配置+Linux

 001 - Linux C/C++ 开发环境搭建_linux下的c++开发_icon-default.png?t=N5K3https://blog.csdn.net/zcteo/article/details/117528089

vscode报错“Unable to start debugging”“GDB Failed with message:”_vscode调试启动不了icon-default.png?t=N5K3https://blog.csdn.net/yanchenyu365/article/details/127610971

2023.3.29更新

最新版本的vscode点击调试生成会把所有同目录下的文件一起运行,这会产生很严重的函数同名影响而不能运行

刚开始搜索问题以为是什么新版本更新带来的(确实是,但不完全是),修改了task.json一点参数,但是没改好,连生成都不行了

回头检查环境变量,才发现之前配置数据库java的时候把g++的路径改了,测试不到g++.version

改完还是i不行,于是看报错信息

D:\buildup\mingw64\bin\g++.exe -fdiagnostics-color=always -g "D:\dev c++\compile\.vscode/*.cpp" -o "D:\dev c++\compile\.vscode\a.exe"
C:\Users\DELL\AppData\Local\Temp\ccQ1b2lt.o: In function `int* std::__niter_base<int*>(int*)':
D:/dev c++/compile/.vscode/b.cpp:27: multiple definition of `solve()'
C:\Users\DELL\AppData\Local\Temp\cc3L4sfp.o:D:/dev c++/compile/.vscode/a.cpp:29: first defined here
C:\Users\DELL\AppData\Local\Temp\ccQ1b2lt.o: In function `main':
D:/dev c++/compile/.vscode/b.cpp:71: multiple definition of `main'
C:\Users\DELL\AppData\Local\Temp\cc3L4sfp.o:D:/dev c++/compile/.vscode/a.cpp:59: first defined here
C:\Users\DELL\AppData\Local\Temp\ccuIdDAo.o: In function `__gnu_cxx::__ops::__iter_less_iter()':
D:/dev c++/compile/.vscode/c.cpp:27: multiple definition of `solve()'
C:\Users\DELL\AppData\Local\Temp\cc3L4sfp.o:D:/dev c++/compile/.vscode/a.cpp:29: first defined here
C:\Users\DELL\AppData\Local\Temp\ccuIdDAo.o: In function `main':
D:/dev c++/compile/.vscode/c.cpp:69: multiple definition of `main'
C:\Users\DELL\AppData\Local\Temp\cc3L4sfp.o:D:/dev c++/compile/.vscode/a.cpp:59: first defined here
C:\Users\DELL\AppData\Local\Temp\cc3hjtF5.o: In function `solve()':
D:/dev c++/compile/.vscode/d.cpp:28: multiple definition of `solve()'
C:\Users\DELL\AppData\Local\Temp\cc3L4sfp.o:D:/dev c++/compile/.vscode/a.cpp:29: first defined here
C:\Users\DELL\AppData\Local\Temp\cc3hjtF5.o: In function `main':
D:/dev c++/compile/.vscode/d.cpp:31: multiple definition of `main'
C:\Users\DELL\AppData\Local\Temp\cc3L4sfp.o:D:/dev c++/compile/.vscode/a.cpp:59: first defined here
C:\Users\DELL\AppData\Local\Temp\ccqt8YsQ.o: In function `solve()':
D:/dev c++/compile/.vscode/interact.cpp:33: multiple definition of `solve()'
C:\Users\DELL\AppData\Local\Temp\cc3L4sfp.o:D:/dev c++/compile/.vscode/a.cpp:29: first defined here
C:\Users\DELL\AppData\Local\Temp\ccqt8YsQ.o: In function `main':
D:/dev c++/compile/.vscode/interact.cpp:50: multiple definition of `main'
C:\Users\DELL\AppData\Local\Temp\cc3L4sfp.o:D:/dev c++/compile/.vscode/a.cpp:59: first defined here
C:\Users\DELL\AppData\Local\Temp\ccLIj5C9.o: In function `main':
D:/dev c++/compile/.vscode/temp.cpp:4: multiple definition of `main'
C:\Users\DELL\AppData\Local\Temp\cc3L4sfp.o:D:/dev c++/compile/.vscode/a.cpp:59: first defined here
collect2.exe: error: ld returned 1 exit status

生成已完成,但出现错误。

 *  终端进程已终止,退出代码: -1。 
 *  终端将被任务重用,按任意键关闭。 

突然发现,原来还是更新的问题,不能一次调试一个了,又不会改配置,写代码重要不管了hhh

解决方法是run code 右键文件或者点击没有虫子的三角形都可以

2022.11.14更新

文件目录不能用中文 ,文件目录不能用中文 ,文件目录不能用中文 !!!

怎么说呢,只能很无语

记录一下最终处理结果

好像还变得更加好用了

 插件安装

 

 launch.json

{
    "version": "0.2.0",
    "configurations": [
      {
        "name": "g++.exe - Build and debug active file",
        "type": "cppdbg",
        "request": "launch",
        "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${fileDirname}",
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb",
        "miDebuggerPath": "D:\\buildup\\mingw64\\bin\\gdb.exe",
        "setupCommands": [
          {
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
          }
        ],
        "preLaunchTask": "C/C++: g++.exe build active file"
      }
    ]
  }

tasks.json

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe 生成活动文件",
            "command": "D:\\buildup\\mingw64\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "调试器生成的任务。"
        }
    ],
    "version": "2.0.0"
}

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "GCC",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "D:\\buildup\\mingw64\\bin\\gcc.exe",
            "cStandard": "gnu17",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "gcc-x64",
            "compilerArgs": [
                "\"D:\\buildup\\mingw64\\bin\\g++.exe\""
            ]
        }
    ],
    "version": 4
}

settings.json

{
  /*editor*/
  "editor.cursorBlinking": "smooth",//使编辑器光标的闪烁平滑,有呼吸感
  "editor.formatOnPaste": true,//在粘贴时格式化代码
  "editor.formatOnType": true,//敲完一行代码自动格式化
  "editor.smoothScrolling": true,//使编辑器滚动变平滑
  "editor.tabCompletion": "on",//启用Tab补全
  "editor.fontFamily": "'Jetbrains Mono', '思源黑体'",//字体设置,个人喜欢Jetbrains Mono作英文字体,思源黑体作中文字体
  "editor.fontLigatures": true,//启用字体连字
  "editor.detectIndentation": false,//不基于文件内容选择缩进用制表符还是空格
  /*
  因为有时候VSCode的判断是错误的
  */
  "editor.insertSpaces": true,//敲下Tab键时插入4个空格而不是制表符
  "editor.copyWithSyntaxHighlighting": false,//复制代码时复制纯文本而不是连语法高亮都复制了
  "editor.suggest.snippetsPreventQuickSuggestions": false,//这个开不开效果好像都一样,据说是因为一个bug,建议关掉
  "editor.stickyTabStops": true,//在缩进上移动光标时四个空格一组来移动,就仿佛它们是制表符(\t)一样
  "editor.wordBasedSuggestions": false,//关闭基于文件中单词来联想的功能(语言自带的联想就够了,开了这个会导致用vscode写MarkDown时的中文引号异常联想)
  "editor.linkedEditing": true,//html标签自动重命名(喜大普奔!终于不需要Auto Rename Tag插件了!)
  "editor.wordWrap": "on",//在文件内容溢出vscode显示区域时自动折行
  "editor.cursorSmoothCaretAnimation": "on",//让光标移动、插入变得平滑
  "editor.renderControlCharacters": true,//编辑器中显示不可见的控制字符
  "editor.renderWhitespace": "boundary",//除了两个单词之间用于分隔单词的一个空格,以一个小灰点的样子使空格可见
  /*terminal*/
  "terminal.integrated.defaultProfile.windows": "Command Prompt",//将终端设为cmd,个人比较喜欢cmd作为终端
  "terminal.integrated.cursorBlinking": true,//终端光标闪烁
  "terminal.integrated.rightClickBehavior": "default",//在终端中右键时显示菜单而不是粘贴(个人喜好)
  /*files*/
  "files.autoGuessEncoding": true,//让VScode自动猜源代码文件的编码格式
  "files.autoSave": "onFocusChange",//在编辑器失去焦点时自动保存,这使自动保存近乎达到“无感知”的体验
  "files.exclude": {//隐藏一些碍眼的文件夹
      "**/.git": true,
      "**/.svn": true,
      "**/.hg": true,
      "**/CVS": true,
      "**/.DS_Store": true,
      "**/tmp": true,
      "**/node_modules": true,
      "**/bower_components": true
  },
  "files.watcherExclude": {//不索引一些不必要索引的大文件夹以减少内存和CPU消耗
      "**/.git/objects/**": true,
      "**/.git/subtree-cache/**": true,
      "**/node_modules/**": true,
      "**/tmp/**": true,
      "**/bower_components/**": true,
      "**/dist/**": true
  },
  /*workbench*/
  "workbench.list.smoothScrolling": true,//使文件列表滚动变平滑
  "workbench.editor.enablePreview": false,//打开文件时不是“预览”模式,即在编辑一个文件时打开编辑另一个文件不会覆盖当前编辑的文件而是新建一个标签页
  "workbench.editor.wrapTabs": true,//编辑器标签页在空间不足时以多行显示
  "workbench.editor.untitled.hint": "hidden",//隐藏新建无标题文件时的“选择语言?”提示(个人喜好,可以删掉此行然后Ctrl+N打开无标题新文件看看不hidden的效果)
  /*explorer*/
  "explorer.confirmDelete": false,//删除文件时不弹出确认弹窗(因为很烦)
  "explorer.confirmDragAndDrop": false,//往左边文件资源管理器拖动东西来移动/复制时不显示确认窗口(因为很烦)
  /*search*/
  "search.followSymlinks": false,//据说可以减少vscode的CPU和内存占用
  /*window*/
  "window.menuBarVisibility": "visible",//在全屏模式下仍然显示窗口顶部菜单(没有菜单很难受)
  "window.dialogStyle": "custom",//使用更具有VSCode的UI风格的弹窗提示(更美观)
  /*debug*/
  "debug.internalConsoleOptions": "openOnSessionStart",//每次调试都打开调试控制台,方便调试
  "debug.showBreakpointsInOverviewRuler": true,//在滚动条标尺上显示断点的位置,便于查找断点的位置
  "debug.toolBarLocation": "docked",//固定调试时工具条的位置,防止遮挡代码内容(个人喜好)
  "debug.saveBeforeStart": "nonUntitledEditorsInActiveGroup",//在启动调试会话前保存除了无标题文档以外的文档(毕竟你创建了无标题文档就说明你根本没有想保存它的意思(至少我是这样的。))
  "debug.onTaskErrors": "showErrors",//预启动任务出错后显示错误,并不启动调试
  /*html*/
"html.format.indentHandlebars": true,
"files.associations": {
    "tuple": "cpp"
} //在写包含形如{{xxx}}的标签的html文档时,也对标签进行缩进(更美观)
}
/*
源自某用户忘记了
*/

下次遇到这种情况复制粘贴吧,暂时没有更好的办法

看了一下午小白教程

大聪明编译器

  • 6
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要配置VS Code环境以支持C++编程,你可以按照以下步骤进行设置: 1. 首先,确保你已经在系统上安装了C++编译器。对于Windows系统,你可以安装MinGW或者Microsoft Visual Studio;对于MacOS,你可以安装Xcode Command Line Tools;对于Linux系统,你可以安装gcc或者clang。 2. 安装VS Code插件"C/C++"。在VS Code的扩展面板中搜索并安装"C/C++"插件。 3. 打开你的C++项目文件夹,然后在VS Code中打开终端(可以使用快捷键Ctrl+`或者通过"View"菜单中的"Terminal"选项)。 4. 在终端中输入以下命令来生成一个基本的c_cpp_properties.json文件: ``` cd your_project_folder cp .vscode/c_cpp_properties.json . ``` 5. 打开生成的c_cpp_properties.json文件,并根据你的编译器路径进行编辑。例如,对于MinGW,你需要将`"compilerPath"`字段设置为MinGW的bin目录下的g++.exe路径。 6. 在VS Code中按下快捷键Ctrl+Shift+P来打开命令面板,然后输入"C/C++: Edit Configurations (JSON)"并选择它。 7. 在打开的launch.json文件中,将以下配置添加到"configurations"数组中: ``` { "name": "C++ Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/your_program_name", "args": [], "stopAtEntry": true, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false } ``` 将"program"字段设置为你的C++程序的路径,例如`${workspaceFolder}/main.cpp`。 8. 保存launch.json文件。 现在你已经配置好了VS Code环境以支持C++编程。你可以在VS Code中编写、调试和运行C++代码了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值