14

I'm currently using Conan on a C++ project using sqlite_orm as a dependency.

When using my personal include (like myClass.hpp for example) Visual Studio Code is able to provide auto-completion but with Conan's include, no auto-completion is possible.

I'm looking for a way to link the include path of Conan to my VSCode, any idea?

1
  • Can you provide an example of your CMake files to show what you have tried so far? Commented Sep 24, 2019 at 11:07

7 Answers 7

29

Add the following line in your project's .vscode/c_cpp_properties.json file

For older versions:

"includePath": ["${workspaceFolder}/**", "~/.conan/data/**"]

For conan v2:

"includePath": ["${workspaceFolder}/**", "~/.conan2/**"]

Sign up to request clarification or add additional context in comments.

9 Comments

Works but requires a restart of VSCode.
For me it worked with vscode 1.48.0 without restarting. Thanks for this
for windows in JSON config file for all cpp projects "C_Cpp.default.includePath": ["${workspaceFolder}/**","${env:USERPROFILE}/.conan/data/**"]
With the new conan2: ~/.conan2/** this works.
@divyanshu-kalra this is the most updated and helpful answer. I think the answer should be edited to amend with conan 2's new path.
|
17

Add set(CMAKE_EXPORT_COMPILE_COMMANDS ON) to your CMakeLists.txt (or add to cmake: cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..) so a build/compile_commands.json will be generated.

VS Code (clion, etc) can utilize this file to support auto complete:

$ cat .vscode/c_cpp_properties.json
{
    "configurations": [
    {
        "name": "Linux",
            "defines": [],
            "compilerPath": "/usr/bin/g++",
            "cStandard": "c11",
            "cppStandard": "c++14",
            "intelliSenseMode": "clang-x64",
            "compileCommands": "${workspaceFolder}/build/compile_commands.json"
    }
    ],
    "version": 4
}

1 Comment

Thanks a lot for this, also for anyone trying this I think you should be aware that some versions may differ, so please check down your build folder for the compile_commands.json file an then specify the correct path :)
3

Conan doesn't provide an extension for vscode yet, but you can try:

https://github.com/FIREFOXCYBER/conan-tools-vs-code

It's available on marketplace.

Otherwise, you can add manually the package folder path (e.g. ~/.conan/data/package/version/package/package_id/include) in your settings.

Comments

3

A combination of dvorak4tzx's and spanishgum's answers, combined with VS Code's option for Customizing default settings is the following option:

Generate a build/compile_commands.json eiter by adding to CMakeLists.txt:

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

or on the command line:

cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

And then insert into .vscode/settings.json:

"C_Cpp.default.compileCommands": "${workspaceFolder}/build/compile_commands.json",

Note: I experienced trouble if

"configurationProvider": "ms-vscode.cmake-tools"

was part of the c_cpp_properties.json. Without it, the IntelliSense works as expected.

I would argue that "includePath": ["${workspaceFolder}/**", "~/.conan/data/**"] is not desired, as you may have many versions of each library beneath ~/.conan/data.


Sources:

Comments

2

After searching in the settings of VSCode, I found that you can change the path of your include in c_cpp_properties.json file that you can find in your .vscode folder

Adding the path you want in the includePath field allow you to choose your own include path

Comments

2

I want to add that you can also use the .vscode/settings.json file as an alternative to .vscode/c_cpp_properties.json.

For example, I just set up a project with this:

{
  "C_Cpp.clang_format_path": "/usr/lib/llvm-10/bin/clang-format",
  "C_Cpp.default.includePath": [
    "~/.conan/data/**"
  ],
}

Comments

0

VS Code integration with Conan is limited, but the CMake plugin is highly configurable.

In a project directory, my_project,

This is the incantation that works for me currently. The UI and plugins change often, but this works in VS Code 1.92, with CMake plugin 0.0.17. I assume you're using CMake to model your artifacts.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.