I am using VSCode 1.37.1 on Windows with mingw64-5.4.0. I have followed the VSCode C++ configuration tutorial at https://code.visualstudio.com/docs/cpp/config-mingw but I have a problem resolving header file locations. In the code editor, if I put the cursor on "<iostream>", then press F12, I go to that file. But if I put the cursor on "<vector>" and press F12, I get a little pop-up showing three different possible resolutions. See screenshot below.
I have the option of manually choosing the correct file and opening it, but the next time I open the same file via F12 it asks again.
VSCode has already detected the correct include paths (see below), and the correct file only exists in one of them, so it should already have all of the required information.
My question is: how can I tell VSCode to automatically open the correct file, as determined by the include paths, rather than prompting me like this?
Screenshot:
By using the "C/C++: Log Diagnostics" palette command, I see that VSCode has detected the proper include paths (comparing to "g++ -v empty.c" at a command prompt). The complete diagnostics are:
-------- 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\5.4.0\INCLUDE
D:\OPT\MINGW64-5.4.0\LIB\GCC\X86_64-W64-MINGW32\5.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\5.4.0\INCLUDE
D:\OPT\MINGW64-5.4.0\LIB\GCC\X86_64-W64-MINGW32\5.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
I filed 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.
So it appears this is simply a known bug with no known workaround.