microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.53k stars 1.56k forks source link

Cannot find any include (not even standard or in the same path) #4218

Closed ProkopHapala closed 4 years ago

ProkopHapala commented 5 years ago

Type: LanguageService

InteliSense say it cannot find any #include *.h, not even those which are in the same directory or in system path. For example 'math.h' file not found 'cstdlib' file not found

I tried to add everythin to c_cpp_properties.json which looks like this

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${default}",
                "/usr/local/include",
                "/usr/include",
                "${workspaceFolder}/**",
                "${workspaceFolder}/cpp"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/g++",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

when I run whereis math.h

prokop@s2-041:~$ whereis math.h
math: /usr/include/math.h

Describe the bug

Screenshots Screenshot_2019-09-09_11-44-49

Arpafaucon commented 5 years ago

I am in this situation as well. System includes are not found anymore. Here is a minimal example. Screenshot from 2019-09-09 15-36-54

Ubuntu 18.04.3 LTS VSCode version: 1.38.0 x64 Using Remote Development feature, container is on Ubuntu 18.04.3

# bug is observed with the following active extensions
❯ code --list-extensions --show-versions
ms-vscode-remote.remote-containers@0.74.0
ms-vscode-remote.vscode-remote-extensionpack@0.17.0
ms-vscode.cpptools@0.25.1
sean-mcmanus commented 5 years ago

The "file not found" error is not from our C/C++ extension -- it's coming from another extension you have installed. You should also remove the 2 system /usr/ paths from your includePath, because they should come from the compiler (to avoid ordering problems).

@Arpafaucon Did you set your compilerPath? Can you run C/C++: Log Diagnostics?

Arpafaucon commented 5 years ago

I did a small investigation, and #include resolution is done properly on the host machine outside of the container.

diagnostic from inside the container

$ /usr/bin/gcc --version
gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-------- Diagnostics - 9/10/2019, 8:00:01 AM
Version: 0.25.1
Current Configuration:
{
    "name": "Linux",
    "defines": [],
    "compilerPath": "/usr/bin/gcc",
    "knownCompilers": [
        {
            "path": "/usr/bin/gcc",
            "isC": true
        },
        {
            "path": "/usr/bin/g++",
            "isC": false
        },
        {
            "path": "/usr/bin/cpp",
            "isC": false
        },
        {
            "path": "/usr/bin/gcc-7",
            "isC": true
        },
        {
            "path": "/usr/bin/g++-7",
            "isC": false
        },
        {
            "path": "/usr/bin/gcc",
            "isC": false
        }
    ],
    "cStandard": "c11",
    "includePath": [
        "/include"
    ],
    "compilerArgs": [],
    "cppStandard": "c++14",
    "intelliSenseMode": "gcc-x64",
    "browse": {
        "path": [
            "/include",
            "${workspaceFolder}"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
Translation Unit Mappings:
[ /home/builder/wdc_workspace/pdev/temp/test.c ]:
    /home/builder/wdc_workspace/pdev/temp/test.c
Translation Unit Configurations:
[ /home/builder/wdc_workspace/pdev/temp/test.c ]:
    Process ID: 254
    Memory Usage: 11 MB
    Compiler Path: /usr/bin/gcc
    Includes:
        /install/include
        /build/gtest_EXTERNAL-prefix/src/gtest_EXTERNAL
        /build/gtest_EXTERNAL-prefix/src/gtest_EXTERNAL/googlemock
        /build/gtest_EXTERNAL-prefix/src/gtest_EXTERNAL/googlemock/include
        /build/gtest_EXTERNAL-prefix/src/gtest_EXTERNAL/googlemock/include/gmock
        /build/gtest_EXTERNAL-prefix/src/gtest_EXTERNAL/googlemock/include/gmock/internal
        /build/gtest_EXTERNAL-prefix/src/gtest_EXTERNAL/googlemock/include/gmock/internal/custom
        /build/gtest_EXTERNAL-prefix/src/gtest_EXTERNAL/googlemock/make
        /build/gtest_EXTERNAL-prefix/src/gtest_EXTERNAL/googlemock/test
        /build/gtest_EXTERNAL-prefix/src/gtest_EXTERNAL/googlemock/scripts
        /build/gtest_EXTERNAL-prefix/src/gtest_EXTERNAL/googlemock/scripts/generator
        /build/gtest_EXTERNAL-prefix/src/gtest_EXTERNAL/googletest
        /build/gtest_EXTERNAL-prefix/src/gtest_EXTERNAL/googletest/src
        /build/gtest_EXTERNAL-prefix/src/gtest_EXTERNAL/googletest/include
        /build/gtest_EXTERNAL-prefix/src/gtest_EXTERNAL/googletest/include/gtest
        /build/gtest_EXTERNAL-prefix/src/gtest_EXTERNAL/googletest/include/gtest/internal
        /build/gtest_EXTERNAL-prefix/src/gtest_EXTERNAL/googletest/include/gtest/internal/custom
        /build/gtest_EXTERNAL-prefix/src/gtest_EXTERNAL/googletest/xcode
        /build/gtest_EXTERNAL-prefix/src/gtest_EXTERNAL/googletest/xcode/Samples
        /build/gtest_EXTERNAL-prefix/src/gtest_EXTERNAL/googletest/xcode/Samples/FrameworkSample
        /build/gtest_EXTERNAL-prefix/src/gtest_EXTERNAL/googletest/make
        /build/gtest_EXTERNAL-prefix/src/gtest_EXTERNAL/googletest/test
        /build/gtest_EXTERNAL-prefix/src/gtest_EXTERNAL/googletest/scripts
        /build/gtest_EXTERNAL-prefix/src/gtest_EXTERNAL/googletest/scripts/test
        /build/gtest_EXTERNAL-prefix/src/gtest_EXTERNAL/googletest/samples
    Standard Version: c11
    IntelliSense Mode: gcc-x64
    Other Flags:
        --gcc
        --gnu_version=70400
Total Memory Usage: 11 MB
sean-mcmanus commented 5 years ago

Our querying of /usr/bin/gcc is failing to add the system includes for some reason. Is your Linux gcc generate non-English output? If you enable debug logging (https://code.visualstudio.com/docs/cpp/enable-logging-cpp) do you see any errors when it tries to query the compiler for includes?

matt-rayner1 commented 5 years ago

I have also been having exactly the same issue. The only extensions I am running are 'C/C++', 'C/C++ intellisense', and 'CodeRunner'.

I have used a quick workaround by adding the "../MinGW/include" to the includePath. I also copied the header from "../MinGW/lib/gcc/mingw32/8.2.0/include" to "../MinGW/include" as it would throw up another error that stddef.h could not be found otherwise.

Unusually, my code is now throwing up new errors regarding "FILE *file_name" initialisation, but the code still runs fine...

EDIT: OS and Version: Windows 10 x64 VS Code Version: 1.38.0 C/C++ Extension Version: 0.25.1

sean-mcmanus commented 5 years ago

@matt-rayner1 What does "exactly the same issue" mean, i.e. what is the exact text of the error message? This thread has 2 different bug reports in it.

Our C/C++ extension is not compatible with the "C/C++ IntelliSense" extension...or you need to somehow configure that other extension correctly.

Arpafaucon commented 5 years ago

Hi @sean-mcmanus my /usr/bin/gcc seem to output english:

$ /usr/bin/gcc -v
Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.4.0-1ubuntu1~18.04.1' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)

$ gcc -print-search-dirs
install: /usr/lib/gcc/x86_64-linux-gnu/7/
programs: =/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/bin/
libraries: =/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../lib/:/lib/x86_64-linux-gnu/7/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/7/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/lib/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../:/lib/:/usr/lib/

You'll find attached the debug log of the extension when opening my test.c file. I believe this snippet is of interest, the extension signals a failed search for files in /include

Attempting to get defaults from compiler in "compilerPath" property: '/usr/bin/gcc'
terminating child process: 201
  Unable to retrieve file system information for /include. error = -1
  Folder: /install/include/ will be indexed
  Folder: /opt/install/pc/include/ will be indexed
  Folder: /build/gtest_EXTERNAL-prefix/src/gtest_EXTERNAL/ will be indexed
  Folder: /home/builder/wdc_workspace/pdev/temp/ will be indexed
textDocument/didOpen
Populate include completion cache.
Discovering files...
textDocument/documentSymbol: 2
Unable to resolve include path: /include
  Processing folder (recursive): /install/include/
  Processing folder (recursive): /opt/install/pc/include/

When opening the file, I noticed that the #include <stdio.h> line first gets blue squiggles, then red ones - if that is of any relevance.

I'm able to compile the file into a working program with

/usr/bin/gcc test.c

debug_log.txt

joel-felcana commented 5 years ago

I'll add my issue here, as I think it might be related.

In my case, from time to time, VS Code won't be able to find some of the includes. A restart normally fixes the issue. I can't determine what causes it to start appearing. I recorded a gif showing the behaviour.

I opened my project, which is a workspace with 4 folders, each of them with its own settings. In this case, for example, "unity.h", my unit test framework main library, is not found, together with the list of includes starting with mock_*, which are generated by my unit test framework too. All these files exist and are included in the search paths.

I control+click on unity to show that VS Code knows how to reach it, as you can see how it opens. After that, I close the app and reopen it again. The issue is gone, and all the headers are found.

Ordered list


This is my diagnostics log

-------- Diagnostics - 16/09/2019, 10:52:54
Version: 0.25.1
Current Configuration:
{
    "name": "Win32",
    "intelliSenseMode": "gcc-x64",
    "includePath": [
        "c:\\Users\\Joel\\Workspace\\Helix\\src\\HelixV2",
        "${workspaceFolder}/vendor/ceedling/vendor/unity/src",
        "${workspaceFolder}/build/test/mocks",
        "${workspaceFolder}/vendor/ceedling/vendor/cmock/src",
        "c:\\Users\\Joel\\Workspace\\Helix\\src\\HelixV2/../../lib/littleFS"
    ],
    "defines": [
        "__NO_SYSTEM_INIT=1",
        "EFR32BG1P233F256GM48=1",
        "SILABS_AF_USE_HWCONF=1",
        "HAL_CONFIG=1",
        "TEST=1"
    ],
    "compilerPath": "C:/msys64/mingw64/bin/gcc.exe",
    "cStandard": "c99",
    "browse": {
        "path": [
            "${workspaceFolder}/vendor/ceedling/vendor/unity/src",
            "${workspaceFolder}/vendor/ceedling/vendor/cmock/src",
            "${workspaceFolder}/build/test/mocks",
            "c:\\Users\\Joel\\Workspace\\Helix\\src\\HelixV2",
            "c:\\Users\\Joel\\Workspace\\Helix\\src\\HelixV2/../../lib/littleFS",
            "C:/SiliconLabs/SimplicityStudio/v4/developer/sdks/gecko_sdk_suite/v1.1/protocol/bluetooth_2.4/ble_stack/inc",
            "C:/SiliconLabs/SimplicityStudio/v4/developer/sdks/gecko_sdk_suite/v1.1/platform/emdrv",
            "C:/SiliconLabs/SimplicityStudio/v4/developer/sdks/gecko_sdk_suite/v1.1/platform/emlib",
            "C:/SiliconLabs/SimplicityStudio/v4/developer/sdks/gecko_sdk_suite/v1.1/platform/Device/SiliconLabs/EFR32BG1P/Include",
            "C:/SiliconLabs/SimplicityStudio/v4/developer/sdks/gecko_sdk_suite/v1.1/platform/CMSIS/Include",
            "C:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/8.3.0/include/ssp"
        ],
        "limitSymbolsToIncludedHeaders": true
    },
    "compilerArgs": [
        "-x",
        "c"
    ]
}
Translation Unit Mappings:
[ C:\Users\Joel\Workspace\Helix\test\test\states\test_collecting.c ]:
    C:\USERS\JOEL\WORKSPACE\HELIX\TEST\TEST\STATES\TEST_COLLECTING.C
[ C:\Users\Joel\Workspace\Helix\test\test\support\accelerometer_stubs.h ]:
    C:\USERS\JOEL\WORKSPACE\HELIX\TEST\TEST\SUPPORT\ACCELEROMETER_STUBS.H
[ C:\Users\Joel\Workspace\Helix\test\test\support\accelerometer_stubs.c ]:
    C:\USERS\JOEL\WORKSPACE\HELIX\TEST\TEST\SUPPORT\ACCELEROMETER_STUBS.C
Translation Unit Configurations:
[ C:\Users\Joel\Workspace\Helix\test\test\states\test_collecting.c ]:
    Process ID: 18944
    Memory Usage: 21 MB
    Compiler Path: C:/msys64/mingw64/bin/gcc.exe
    Includes:
        C:\USERS\JOEL\WORKSPACE\HELIX\SRC\HELIXV2
        C:\USERS\JOEL\WORKSPACE\HELIX\TEST\VENDOR\CEEDLING\VENDOR\UNITY\SRC
        C:\USERS\JOEL\WORKSPACE\HELIX\TEST\BUILD\TEST\MOCKS
        C:\USERS\JOEL\WORKSPACE\HELIX\TEST\VENDOR\CEEDLING\VENDOR\CMOCK\SRC
        C:\USERS\JOEL\WORKSPACE\HELIX\LIB\LITTLEFS
        C:\MSYS64\MINGW64\LIB\GCC\X86_64-W64-MINGW32\9.2.0\INCLUDE
        C:\MSYS64\MINGW64\INCLUDE
        C:\MSYS64\MINGW64\LIB\GCC\X86_64-W64-MINGW32\9.2.0\INCLUDE-FIXED
        C:\MSYS64\MINGW64\X86_64-W64-MINGW32\INCLUDE
    Defines:
        __NO_SYSTEM_INIT=1
        EFR32BG1P233F256GM48=1
        SILABS_AF_USE_HWCONF=1
        HAL_CONFIG=1
        TEST=1
    Standard Version: c99
    IntelliSense Mode: gcc-x64
    Other Flags:
        --gcc
        --gnu_version=90200
[ C:\Users\Joel\Workspace\Helix\test\test\support\accelerometer_stubs.h ]:
    Process ID: 21160
    Memory Usage: 12 MB
    Compiler Path: C:/msys64/mingw64/bin/gcc.exe
    Includes:
        C:\USERS\JOEL\WORKSPACE\HELIX\SRC\HELIXV2
        C:\USERS\JOEL\WORKSPACE\HELIX\TEST\VENDOR\CEEDLING\VENDOR\UNITY\SRC
        C:\USERS\JOEL\WORKSPACE\HELIX\TEST\BUILD\TEST\MOCKS
        C:\USERS\JOEL\WORKSPACE\HELIX\TEST\VENDOR\CEEDLING\VENDOR\CMOCK\SRC
        C:\USERS\JOEL\WORKSPACE\HELIX\LIB\LITTLEFS
        C:\MSYS64\MINGW64\LIB\GCC\X86_64-W64-MINGW32\9.2.0\INCLUDE
        C:\MSYS64\MINGW64\INCLUDE
        C:\MSYS64\MINGW64\LIB\GCC\X86_64-W64-MINGW32\9.2.0\INCLUDE-FIXED
        C:\MSYS64\MINGW64\X86_64-W64-MINGW32\INCLUDE
    Defines:
        __NO_SYSTEM_INIT=1
        EFR32BG1P233F256GM48=1
        SILABS_AF_USE_HWCONF=1
        HAL_CONFIG=1
        TEST=1
    Standard Version: c99
    IntelliSense Mode: gcc-x64
    Other Flags:
        --gcc
        --gnu_version=90200
        --header_only_fallback
[ C:\Users\Joel\Workspace\Helix\test\test\support\accelerometer_stubs.c ]:
    Process ID: 8860
    Memory Usage: 12 MB
    Compiler Path: C:/msys64/mingw64/bin/gcc.exe
    Includes:
        C:\USERS\JOEL\WORKSPACE\HELIX\SRC\HELIXV2
        C:\USERS\JOEL\WORKSPACE\HELIX\TEST\VENDOR\CEEDLING\VENDOR\UNITY\SRC
        C:\USERS\JOEL\WORKSPACE\HELIX\TEST\BUILD\TEST\MOCKS
        C:\USERS\JOEL\WORKSPACE\HELIX\TEST\VENDOR\CEEDLING\VENDOR\CMOCK\SRC
        C:\USERS\JOEL\WORKSPACE\HELIX\LIB\LITTLEFS
        C:\MSYS64\MINGW64\LIB\GCC\X86_64-W64-MINGW32\9.2.0\INCLUDE
        C:\MSYS64\MINGW64\INCLUDE
        C:\MSYS64\MINGW64\LIB\GCC\X86_64-W64-MINGW32\9.2.0\INCLUDE-FIXED
        C:\MSYS64\MINGW64\X86_64-W64-MINGW32\INCLUDE
    Defines:
        __NO_SYSTEM_INIT=1
        EFR32BG1P233F256GM48=1
        SILABS_AF_USE_HWCONF=1
        HAL_CONFIG=1
        TEST=1
    Standard Version: c99
    IntelliSense Mode: gcc-x64
    Other Flags:
        --gcc
        --gnu_version=90200
Total Memory Usage: 45 MB
sean-mcmanus commented 5 years ago

@joel-felcana Ctrl+Click uses a different system to locate the header that isn't tied into IntelliSense paths (we have another bug tracking that).

In the logs, the "Includes" sections are what you want to make sure are correct. Your logs don't seem to match your screenshot though. It sounds like the IntelliSense process is getting into some bad state.

You may also want to try running the C/C++: Rescan workspace as another potential workaround.

bobbrow commented 4 years ago

The original issue is caused by installing an incompatible extension "C++ IntelliSense". If you are still having configuration issues with other files in your workspace, please open a new issue with details about your configuration and we can troubleshoot from there. Thanks!