Vscode-cpptools: Using vcpkg libraries on a project

Created on 11 Nov 2018  Â·  6Comments  Â·  Source: microsoft/vscode-cpptools

Type: LanguageService

Describe the bug

  • OS and Version: 10.0.17134.345
  • VS Code Version: 1.28.2
  • C/C++ Extension Version: 0.20.1
  • Other extensions you installed (and if the issue persists after disabling them):
  • A clear and concise description of what the bug is.

I'm not sure whether it's a bug or not but when I try to use libraries installed by the compiler gives:

 fatal error: xxx/yyy.hpp: No such file or directory
 #include <yyy/yyy.hpp>

To Reproduce

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "${.vcpkg-root}/installed/x86-windows/include/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.17134.0",
            "compilerPath": "C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/g++.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "msvc-x64"
        }
    ],
    "version": 4
}

tasks.json* -->

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "hello label",
            "type": "shell",
            "command": "C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/g++.exe",
            "args": [
                "-Wall",
                "-I${.vcpkg-root}/installed/x86-windows/include",
                "hello.cpp"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

Expected behavior
I expected compilation without issues.

Screenshots
capture

Thank you all kindly 😄 😃

Language Service question

Most helpful comment

For who comes here from google:

After you install vcpkg, please delete .vscode/c_cpp_properties.json and let it regenerate by cmd + shift + P then >c++ then C/C++ Edit Configuration (UI)

Then a new config file with correct includePath will be generated, for example:

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**",
                "${vcpkgRoot}/x64-osx/include"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "intelliSenseMode": "${default}",
            "cStandard": "c11",
            "cppStandard": "c++17"
        }
    ],
    "version": 4
}

Then all the xxx file not found Clang will just go, after a second.

All 6 comments

What is ${.vcpkg-root}? c_cpp_properties.json is not involved in compilation, only IntelliSense. That said, c_cpp_properties.json understands a special variable, ${vcpkgRoot}, so I would expect you to use that instead.

Parsing of tasks.json is done by VS Code itself, so it is only able to understand config and environment variables using the official syntax ${env:.vcpkg-root} (if that's a variable you've defined)

I suppose the .vcpkg-root defined when I install the vcpkg, then realize it doesn't, so I defined it manually. I didn't know about the official syntax, It solved my problem 😃 ,

My final tasks.json looks like this:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "hello label",
            "type": "shell",
            "command": "g++.exe",
            "args": [
                "main.cpp",
                "-Wall",
                "-I",
               "${env:.vcpkg-root}\\installed\\x86-windows\\include",
               // "C:/vcpkg/installed/x86-windows/include"
            ],

            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

For who comes here from google:

After you install vcpkg, please delete .vscode/c_cpp_properties.json and let it regenerate by cmd + shift + P then >c++ then C/C++ Edit Configuration (UI)

Then a new config file with correct includePath will be generated, for example:

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**",
                "${vcpkgRoot}/x64-osx/include"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "intelliSenseMode": "${default}",
            "cStandard": "c11",
            "cppStandard": "c++17"
        }
    ],
    "version": 4
}

Then all the xxx file not found Clang will just go, after a second.

No, still not working:

'boost/mpi.hpp' file not found [Lexical or Preprocessor Issue]Clang

https://github.com/microsoft/vcpkg/issues/6640

@linonetwo You're not describing a bug with our extension, right? If so, can you file a new issue?

Good news: when I creating a new issue, I saw - Other extensions you installed (and if the issue persists after disabling them):

And I disabled the C++ advanced lint and error just gone.

So the config I posted actually work with C/C++ extension.

Was this page helpful?
0 / 5 - 0 ratings