Skip to content

Basic gcc header parsing seems to be broken in Linux #4733

@omercsp

Description

@omercsp

Type: LanguageService

Describe the bug

  • OS and Version: Linux, Fedora 31
  • VS Code Version: 1.40.2
  • C/C++ Extension Version: 0.26.2

I might got something wrong here, but it looks like the very basic headers parsing is broken.
A simple gcc based "Hello, world!" code written in C shows multiple, some incorrect, references to "stdio.h" (for example). Trying to go to definition of the stdio.h file shows 3 options:

  1. /usr/include/bits/stdio.h - a file that should never be included directly (as commented in the header itself), and isn't in gcc's default include path.
  2. /usr/include/c++/9/tr1/stdio.h - again, shouldn't be listed here. This should be shown only the included header is <tr1/stdio.h> and the compiler is g++, not gcc.
  3. The correct header

Here's a snippet of gcc's output for it's default search path:

$ echo | gcc -xc -E -Wp,-v -
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/9/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/9/../../../../x86_64-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-redhat-linux/9/include
 /usr/local/include
 /usr/include
End of search list.

The properties used are just just the default:

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

It looks like the addon doesn't query gcc for it's include path at all. Indeed, removing the "/usr/bin/gcc" value from the "compilerPath" property didn't change anything about the list of header candidates.

To Reproduce
Create a simple "Hello, world!" C application, with a single <stdio.h> #include

Expected behavior
By default, go to definition of stdio.h should go directly to /usr/include/stdio.h

Screenshots

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Feature: ConfigurationAn issue related to configuring the extension or IntelliSenseLanguage Servicemore info neededThe issue report is not actionable in its current state

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions