Visual Studio 代码:C/C++:显示了 header/include 文件的多个定义;怎么修?
Visual Studio Code: C/C++: Multiple definitions for a header/include file shown; how to fix?
我在 Windows 上使用 VSCode 1.37.1 和 mingw64-5.4.0。我已按照 https://code.visualstudio.com/docs/cpp/config-mingw 上的 VSCode C++ 配置教程进行操作,但在解析头文件位置时遇到问题。在代码编辑器中,如果我将光标放在“”上,然后按 F12,我将转到该文件。但是,如果我将光标放在“”上并按 F12,我会看到一个小弹出窗口,显示三种不同的可能分辨率。请参阅下面的屏幕截图。
我可以选择手动选择正确的文件并打开它,但下次我通过 F12 打开同一个文件时它会再次询问。
VSCode 已经检测到正确的包含路径(见下文),正确的文件只存在于其中一个路径中,因此它应该已经具有所有必需的信息。
我的问题是:如何告诉 VSCode 自动打开由包含路径确定的正确文件,而不是像这样提示我?
截图:
通过使用 "C/C++: Log Diagnostics" 调色板命令,我发现 VSCode 已检测到正确的包含路径(与在命令提示符下的 "g++ -v empty.c" 相比)。完整的诊断是:
-------- Diagnostics - 8/28/2019, 10:32:51 PM
Version: 0.25.0
Current Configuration:
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.15063.0",
"compilerPath": "D:/opt/mingw64-5.4.0/bin/g++.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64",
"compilerArgs": [
"-m64"
],
"browse": {
"path": [
"${workspaceFolder}/**"
],
"limitSymbolsToIncludedHeaders": true
}
}
Translation Unit Mappings:
[D:\wrk\learn\vscode\cpphello\helloworld.cpp]:
D:\WRK\LEARN\VSCODE\CPPHELLO\HELLOWORLD.CPP
[D:\opt\mingw64-5.4.0\x86_64-w64-mingw32\include\c++\debug\vector]:
D:\OPT\MINGW64-5.4.0\X86_64-W64-MINGW32\INCLUDE\C++\DEBUG\VECTOR
Translation Unit Configurations:
[D:\wrk\learn\vscode\cpphello\helloworld.cpp]:
Process ID: 9088
Memory Usage: 19 MB
Compiler Path: D:/opt/mingw64-5.4.0/bin/g++.exe
Includes:
D:\OPT\MINGW64-5.4.0\LIB\GCC\X86_64-W64-MINGW32.4.0\INCLUDE
D:\OPT\MINGW64-5.4.0\LIB\GCC\X86_64-W64-MINGW32.4.0\INCLUDE-FIXED
D:\OPT\MINGW64-5.4.0\X86_64-W64-MINGW32\INCLUDE
D:\OPT\MINGW64-5.4.0\X86_64-W64-MINGW32\INCLUDE\C++
D:\OPT\MINGW64-5.4.0\X86_64-W64-MINGW32\INCLUDE\C++\X86_64-W64-MINGW32
D:\OPT\MINGW64-5.4.0\X86_64-W64-MINGW32\INCLUDE\C++\BACKWARD
Defines:
_DEBUG
UNICODE
_UNICODE
Standard Version: c++17
IntelliSense Mode: gcc-x64
Other Flags:
--g++
--gnu_version=50400
[D:\opt\mingw64-5.4.0\x86_64-w64-mingw32\include\c++\debug\vector]:
Process ID: 10728
Memory Usage: 33 MB
Compiler Path: D:/opt/mingw64-5.4.0/bin/g++.exe
Includes:
D:\OPT\MINGW64-5.4.0\LIB\GCC\X86_64-W64-MINGW32.4.0\INCLUDE
D:\OPT\MINGW64-5.4.0\LIB\GCC\X86_64-W64-MINGW32.4.0\INCLUDE-FIXED
D:\OPT\MINGW64-5.4.0\X86_64-W64-MINGW32\INCLUDE
D:\OPT\MINGW64-5.4.0\X86_64-W64-MINGW32\INCLUDE\C++
D:\OPT\MINGW64-5.4.0\X86_64-W64-MINGW32\INCLUDE\C++\X86_64-W64-MINGW32
D:\OPT\MINGW64-5.4.0\X86_64-W64-MINGW32\INCLUDE\C++\BACKWARD
Defines:
_DEBUG
UNICODE
_UNICODE
Standard Version: c++17
IntelliSense Mode: gcc-x64
Other Flags:
--g++
--gnu_version=50400
--header_only_fallback
Total Memory Usage: 52 MB
我提交了 CppTools Issue 4186: Multiple definitions shown for header/include file but only one is on includePath for this, which was closed as a duplicate of Issue 2564: Go to Definition on a #include path doesn't use the IntelliSense info。
看来这只是一个已知错误,没有已知的解决方法。
我在 Windows 上使用 VSCode 1.37.1 和 mingw64-5.4.0。我已按照 https://code.visualstudio.com/docs/cpp/config-mingw 上的 VSCode C++ 配置教程进行操作,但在解析头文件位置时遇到问题。在代码编辑器中,如果我将光标放在“
我可以选择手动选择正确的文件并打开它,但下次我通过 F12 打开同一个文件时它会再次询问。
VSCode 已经检测到正确的包含路径(见下文),正确的文件只存在于其中一个路径中,因此它应该已经具有所有必需的信息。
我的问题是:如何告诉 VSCode 自动打开由包含路径确定的正确文件,而不是像这样提示我?
截图:
通过使用 "C/C++: Log Diagnostics" 调色板命令,我发现 VSCode 已检测到正确的包含路径(与在命令提示符下的 "g++ -v empty.c" 相比)。完整的诊断是:
-------- Diagnostics - 8/28/2019, 10:32:51 PM
Version: 0.25.0
Current Configuration:
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.15063.0",
"compilerPath": "D:/opt/mingw64-5.4.0/bin/g++.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64",
"compilerArgs": [
"-m64"
],
"browse": {
"path": [
"${workspaceFolder}/**"
],
"limitSymbolsToIncludedHeaders": true
}
}
Translation Unit Mappings:
[D:\wrk\learn\vscode\cpphello\helloworld.cpp]:
D:\WRK\LEARN\VSCODE\CPPHELLO\HELLOWORLD.CPP
[D:\opt\mingw64-5.4.0\x86_64-w64-mingw32\include\c++\debug\vector]:
D:\OPT\MINGW64-5.4.0\X86_64-W64-MINGW32\INCLUDE\C++\DEBUG\VECTOR
Translation Unit Configurations:
[D:\wrk\learn\vscode\cpphello\helloworld.cpp]:
Process ID: 9088
Memory Usage: 19 MB
Compiler Path: D:/opt/mingw64-5.4.0/bin/g++.exe
Includes:
D:\OPT\MINGW64-5.4.0\LIB\GCC\X86_64-W64-MINGW32.4.0\INCLUDE
D:\OPT\MINGW64-5.4.0\LIB\GCC\X86_64-W64-MINGW32.4.0\INCLUDE-FIXED
D:\OPT\MINGW64-5.4.0\X86_64-W64-MINGW32\INCLUDE
D:\OPT\MINGW64-5.4.0\X86_64-W64-MINGW32\INCLUDE\C++
D:\OPT\MINGW64-5.4.0\X86_64-W64-MINGW32\INCLUDE\C++\X86_64-W64-MINGW32
D:\OPT\MINGW64-5.4.0\X86_64-W64-MINGW32\INCLUDE\C++\BACKWARD
Defines:
_DEBUG
UNICODE
_UNICODE
Standard Version: c++17
IntelliSense Mode: gcc-x64
Other Flags:
--g++
--gnu_version=50400
[D:\opt\mingw64-5.4.0\x86_64-w64-mingw32\include\c++\debug\vector]:
Process ID: 10728
Memory Usage: 33 MB
Compiler Path: D:/opt/mingw64-5.4.0/bin/g++.exe
Includes:
D:\OPT\MINGW64-5.4.0\LIB\GCC\X86_64-W64-MINGW32.4.0\INCLUDE
D:\OPT\MINGW64-5.4.0\LIB\GCC\X86_64-W64-MINGW32.4.0\INCLUDE-FIXED
D:\OPT\MINGW64-5.4.0\X86_64-W64-MINGW32\INCLUDE
D:\OPT\MINGW64-5.4.0\X86_64-W64-MINGW32\INCLUDE\C++
D:\OPT\MINGW64-5.4.0\X86_64-W64-MINGW32\INCLUDE\C++\X86_64-W64-MINGW32
D:\OPT\MINGW64-5.4.0\X86_64-W64-MINGW32\INCLUDE\C++\BACKWARD
Defines:
_DEBUG
UNICODE
_UNICODE
Standard Version: c++17
IntelliSense Mode: gcc-x64
Other Flags:
--g++
--gnu_version=50400
--header_only_fallback
Total Memory Usage: 52 MB
我提交了 CppTools Issue 4186: Multiple definitions shown for header/include file but only one is on includePath for this, which was closed as a duplicate of Issue 2564: Go to Definition on a #include path doesn't use the IntelliSense info。
看来这只是一个已知错误,没有已知的解决方法。