Search code examples
c++anacondacondasconsclangd

How to make SCons export compile commands including flags pointing to a conda virtual environment?


I'm working on a C++ project that is built with SCons. I installed SCons using my system's package manager. The project has some dependencies that I installed into a virtual environment using conda. I followed the SCons documentation to export a compile_commands.json.

When I activate the project's conda environment, then run scons, everything compiles fine and a compile_commands.json is created. However, the exported compile commands are missing -I or -isystem flags that point to the include/ directory of the conda environment.

My editor (vim/Ycm) relies on clangd for linting and semantic completion, clangd relies on the exported compile commands and is not aware of the conda virtual environment. How can I make SCons export the required flags so that clangd can find the dependencies headers?

(For comparison, a different project that is set up the exact same way but using CMake exports compile commands with -isystem flags to the conda environment.)


Solution

  • I got SCons to export the correct compile commands by adding the line

    env.Append(CPPPATH= ['/path/to/my/conda/env/include'])
    

    to the SConstruct file. I assume the reason for the compilation working even without this line is that the compiler is installed in the same conda environment.