Ale: How do you add include directories for C++?

Created on 29 May 2018  路  7Comments  路  Source: dense-analysis/ale

I am trying to allow ale to look in /opt/ros/kinetic/include to find headers for libraries I am using. I have tried this config:

let g:ale_c_build_dir = "./build"                                                
let g:ale_c_parse_makefile = 1                                                   
let g:ale_cpp_gcc_options = ' -std=c++14 -isystem /usr/include/c++/v1 -I/usr/include/c++/v1 -I/opt/ros/kinetic/include'

to no success.

Most helpful comment

There's a way: project-specific vimrc. It goes nicely with project-specific tags, .ctagsignore and any .clang-format you have in your project.

" Add to .vimrc to enable project-specific vimrc

set exrc
set secure

" exrc allows loading local executing local rc files.
" secure disallows the use of :autocmd, shell and write commands in local .vimrc files.

Then, in a new .vimrc in your project directory (or .nvimrc for neovim), add this:

let g:ale_c_clang_options="-I/path/to/your/project"
let g:ale_cpp_clang_options="-I/path/to/your/project"

All 7 comments

I was setting the gcc option but was using clang. Now that I have set the clang options I just get the letter a in the side column. What does this mean?

Also I can't get it to detect opencv using these settings:

let g:ale_c_build_dir = "./build"                                                
let g:ale_c_parse_makefile = 1                                                   
let g:ale_cpp_gcc_options = '-std=c++14 -isystem /usr/include/c++/v1 -I/usr/include/c++/v1 -I/opt/ros/kinetic/include -I/usr/local/include -I/usr/include -I/usr/include/x86_64-linux-gnu'
let g:ale_cpp_clang_options = '-std=c++14 -isystem /usr/include/c++/v1 -I/usr/include/c++/v1 -I/opt/ros/kinetic/include -I/usr/local/include -I/usr/include -I/usr/include/x86_64-linux-gnu'      

The answer is generally "with difficulty." Because C and C++ unfortunately don't have standard project layouts, you have to manually set some options telling the compilers where to find headers and so on. Some work has been done to try and use some tools to figure out where headers are automatically.

https://github.com/w0rp/ale/pull/1242
https://github.com/w0rp/ale/pull/1496
https://github.com/w0rp/ale/pull/1434

I can't offer much help with configuring C or C++ linters, as I haven't ever created any meaningful C or C++ projects myself. Someone might fly by and give you some guidance here, and you could also try asking for help in the #vim-ale channel on Freenode.

I would like to make the C and C++ compilers work automatically for _most_ projects in the not too distant future, but it's not a problem that can be solved in general when there isn't an official standard set for how a project should look. The problem is trivial to solve for D, Rust, Go, and other modern languages.

The issue is also strongly dependent on the linter you're using, and on how you build your project (carefully curated Makefile or CMake or something else).

I've never used "raw" clang linter, so I don't think I can help a lot there, eventually I chose to not use ale at all for C++, and instead install full LSP client support and cquery as a language server, because I thought I was going to spend 3 days getting all the linting tools working for each project (with different files architectures) that I have.

The GitHub issue template now recommends asking for help with configuring ALE on Stack Exchange or Reddit instead.

Wait, so what's the resolution? Is "ALE sucks for C++, try using something else" accurate enough?

There's a way: project-specific vimrc. It goes nicely with project-specific tags, .ctagsignore and any .clang-format you have in your project.

" Add to .vimrc to enable project-specific vimrc

set exrc
set secure

" exrc allows loading local executing local rc files.
" secure disallows the use of :autocmd, shell and write commands in local .vimrc files.

Then, in a new .vimrc in your project directory (or .nvimrc for neovim), add this:

let g:ale_c_clang_options="-I/path/to/your/project"
let g:ale_cpp_clang_options="-I/path/to/your/project"
Was this page helpful?
0 / 5 - 0 ratings