Skip to content

Cannot properly set Include and Defines with third-party compilers #4269

@gentooise

Description

@gentooise

Type: LanguageService

Describe the bug

  • OS and Version: Windows 10 (Windows_NT x64 10.0.17763)
  • VS Code Version: 1.38.1
  • C/C++ Extension Version: 0.25.1
  • It does not seem possible to use compileCommands plus other global includes/defines taken from includePath and defines properties respectively.

I'm using a third-party compiler (ARM) which has its own includes and defines, but I also need to use project-related include/defines taken from compile_commands.json (generated via CMake).
I'm trying to set compiler-specific includes/defines manually, and then use compileCommands property for project-specific includes/defines.

This is a minimal version of my c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "ARM",
            "compilerPath": "",
            "cStandard": "c99",
            "cppStandard": "c++03",
            "intelliSenseMode": "gcc-x86",
            "compileCommands": "${workspaceFolder:Project}/.vscode/compile_commands.json",
            "defines": [
                "__ARM__"
            ],
            "includePath": [
                "\"C:\\Program Files (x86)\\ARM_Compiler_5.06u4\\include\""
            ]
        }
    ],
    "version": 4
}

Also I would like to set something like "intelliSenseMode": null, because neither MSVC, GCC nor CLang are correct choices for my case. Why does IntelliSense need this info?

This is the full Log Diagnostics output (except sensitive paths):

-------- Diagnostics - 18/9/2019, 17:30:29
Version: 0.25.1
Current Configuration:
{
    "name": "ARM",
    "compilerPath": "",
    "cStandard": "c99",
    "cppStandard": "c++03",
    "intelliSenseMode": "gcc-x86",
    "compileCommands": "d:\\path/.vscode/compile_commands.json",
    "defines": [
        "__ARM__"
    ],
    "includePath": [
        "\"C:\\Program Files (x86)\\ARM_Compiler_5.06u4\\include\""
    ],
    "compilerArgs": [],
    "browse": {
        "path": [
            "\"C:\\Program Files (x86)\\ARM_Compiler_5.06u4\\include\"",
            "${workspaceFolder}"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
Translation Unit Mappings:
[ D:\path\myfile.cpp ]:
    D:\PATH\MYFILE.CPP
Translation Unit Configurations:
[ D:\path\myfile.cpp ]:
    Process ID: 3332
    Memory Usage: 21 MB
    Includes:
        D:\PATH\INCLUDE1
        D:\PATH\INCLUDE2
        D:\...
        ...
    Defines:
        __ARM__
    Standard Version: c++03
    IntelliSense Mode: gcc-x64
    Other Flags:
        --g++
        --gnu_version=80100
Total Memory Usage: 21 MB

This is a screenshot to show the problems encountered:
image

I see 3 main problems:

  • Include paths: the include path list (inside Log Diagnostics) does not contain the includePath specified in c_cpp_properties.json, but only the paths found in compile_commands.json; Since my includePath is not present, the compiler headers are not recognized (e.g. string.h is not found as you can see from the screen);
  • Defines: viceversa, the defines list contains only the ones specified manually into c_cpp_properties.json but does not contain the ones from compile_commands.json; moreover, even if the macro is present in the list (e.g. __ARM__), the editor does not recognizes it and the wrong preprocessor branch is greyed out!
  • IntelliSense Mode: it seems that there is no suitable intelliSenseMode for my use case; I put gcc-x86, but CPPTools seems to ignore it anyway (you can see gcc-x64 in the Log Diagnostics); I would also like to avoid the section "Other Flags" which seems to contain gcc-related stuff.

Expected behavior
In the Log Diagnostics I expect to see the union of includes/defines from both c_cpp_properties.json and compile_commands.json, and I expect them to work in the editor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions