dense-analysis / ale

Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support
BSD 2-Clause "Simplified" License
13.57k stars 1.44k forks source link

How do you add include directories for C++? #1616

Closed half-potato closed 5 years ago

half-potato commented 6 years ago

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.

half-potato commented 6 years ago

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?

half-potato commented 6 years ago

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'      
w0rp commented 6 years ago

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.

gagbo commented 6 years ago

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.

w0rp commented 5 years ago

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

xtsm commented 4 years ago

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

afjoseph commented 4 years ago

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"
praiskup commented 1 year ago

I got here in the year 2023 searching for "the" topic. Ended up with something like this in global vimrc file:

if getcwd() == "/home/user/my-project-dir"
    " per-project config
    let g:ale_cpp_cc_options = '-std=c++17 -Wall -I/home/user/my-project-dir/include/ -DSOME=\"define\"'
endif