Vscode-cpptools: C++ am I missing something or the property "includePath" is broken in c_cpp_properties.json

Created on 27 Apr 2018  Â·  4Comments  Â·  Source: microsoft/vscode-cpptools


Hello,
I am using the vs code Version 1.22.2
The plugin I am using is ms-vscode.cpptools.

I tried to build a simple project. The main file includes a header file (The last path in the property "includePath") from a directory not in the project directory {$workspaceFolder}.
Hence I put the absolute path into the c_cpp_properties.json, hoping the compiler is able to find the header file.
The following code is the configuration I am using in the c_cpp_proerties.json

"name": "Ubuntu-clang++",
"includePath": [
                "${workspaceFolder}",
                "/usr/include/c++/5",
                "/usr/include/x86_64-linux-gnu/c++/5",
                "/usr/include/c++/5/backward",
                "/usr/lib/gcc/x86_64-linux-gnu/5/include",
                "/usr/local/include",
                "/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed",
                "/usr/include/x86_64-linux-gnu",
                "/usr/include",
                "/home/rong/projects/SGX/code/sgxdb_workspace/sgxdb/sgx/enclave_sgxdb/untrusted/components/spdlog/include"
            ],
            "defines": [],
            "intelliSenseMode": "clang-x64",
            "browse": {
                "path": [
                    "${workspaceFolder}",
                    "/usr/include/c++/5",
                    "/usr/include/x86_64-linux-gnu/c++/5",
                    "/usr/include/c++/5/backward",
                    "/usr/lib/gcc/x86_64-linux-gnu/5/include",
                    "/usr/local/include",
                    "/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed",
                    "/usr/include/x86_64-linux-gnu",
                    "/usr/include",
                    "/home/rong/projects/SGX/code/sgxdb_workspace/sgxdb/sgx/enclave_sgxdb/untrusted/components/spdlog/include"

                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            },
            "compilerPath": "~/bin/clang++",
            "cStandard": "c11",
            "cppStandard": "c++11"
        },

The task.json is :

"version": "2.0.0",
    "tasks": [
        {
            "label": "ServerAlpha",
            "type": "shell",
            "command": "clang++ -g main.cpp -o test.exe -std=c++11",
            "args": [],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher":"$gcc"
        }
    ]

When I compile the file main.cpp, I got error:

main.cpp:3:10: fatal error: 'spdlog/fmt/fmt.h' file not found
#include "spdlog/fmt/fmt.h"
         ^~~~~~~~~~~~~~~~~~

But after I changed the task.json property by adding "-I/the/same/header/file/path", the project compiles just fine.

The task.json :

"version": "2.0.0",
    "tasks": [
        {
            "label": "ServerAlpha",
            "type": "shell",
            "command": "clang++ -g main.cpp -o test.exe -std=c++11 -I/home/rong/projects/SGX/code/sgxdb_workspace/sgxdb/sgx/enclave_sgxdb/untrusted/components/spdlog/include",
            "args": [],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher":"$gcc"
        }
    ]

Am I missing something? Or the "includePath" is broken?

Thanks,

Rong

Most helpful comment

The includePath in c_cpp_properties.json is not used for compiling code in tasks. It's used for IntelliSense parsing. Does that make sense?

All 4 comments

The includePath in c_cpp_properties.json is not used for compiling code in tasks. It's used for IntelliSense parsing. Does that make sense?

I see. Thanks for your fast reply. so I should just put the include path in task's args, is that right?

Yes.

A better approach would be to use .sh/.cmd files (where you can organize your compiler invocation with environment variables). They work with problem matchers, and keep your build process clean.

Was this page helpful?
0 / 5 - 0 ratings