是否可以在VScode中解决此问题? #pragma一次进入主文件[-Wpragma-once-outside-header]

问题描述 投票:2回答:1

使用VScode,如何解决此错误?

#pragma once in main file [-Wpragma-once-outside-header]

更新:以VScode显示:

enter image description here

再次更新:这是我在c_cpp_properties.json

中当前的VScode设置
{
  "configurations": [
    {
      "name": "Mac",
      "includePath": ["${workspaceFolder}/**"],
      "defines": [],
      "macFrameworkPath": [
        "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks"
      ],
      "compilerPath": "/usr/bin/clang",
      "cStandard": "c11",
      "cppStandard": "c++17",
      "intelliSenseMode": "clang-x64"
    }
  ],
  "version": 4
}
c++ visual-studio-code vscode-settings
1个回答
1
投票
在Visual Studio Code中,编译设置默认在

tasks.json中构建(

终端>配置默认的构建任务> g ++。exe())。在VS Code 2020中是这样的:

{ "version": "2.0.0", "tasks": [ { "type": "shell", "label": "g++.exe build active file", "command": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\g++.exe", "args": [ "-g", "${workspaceFolder}\\*.cpp", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe" ], "options": { "cwd": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true } } ] }
((我正在使用mingw-64来支持

gcc

编译器,所以根据您使用的编译器,

“ command”和“ cwd”可能具有不同的路径。]

key
部分是这个:

“ $ {file}”,是编辑器中活动文件的名称(活动选项卡)。

"args": [ "-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe" ], 如果使用多个文件,至少一个头文件(.h或.hpp)和一个主文件(.cpp),VS Code将把该活动文件(.h或.hpp)作为主文件(.cpp)。因此,您需要使用以下命令进行更改:
“ $ {workspaceFolder} \ *。cpp”

"args": [ "-g", "${workspaceFolder}\\*.cpp", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe" ],

© www.soinside.com 2019 - 2024. All rights reserved.