clang_complete icon indicating copy to clipboard operation
clang_complete copied to clipboard

clang_complete is ignoring compiler flags in compile_commands.json

Open gunslingerfry opened this issue 7 years ago • 5 comments

An example of my compile_commands.json file generated by using cmake/clang

[
{
  directory: build-dir,
  command: /usr/bin/clang++  -Dnz_shared_EXPORTS -I/home/matthew/nz/include -isystem /home/matthew/nz/include/zip  -g -fPIC   -Wall -Werror -DOS_LINUX -O0 -I/usr/lib/clang/3.8/include -std=gnu++14 -o CMakeFiles/nz_shared.dir/src/boost_error_code.cpp.o -c /home/matthew/nz/src/boost_error_code.cpp,
  file: /home/matthew/nz/src/boost_error_code.cpp
},
... etc.
]

clang_complete ignores the -std=gnu++14 and the -DOS_LINUX and generates errors because of them. Setting g:clang_user_options='-std=gnu++14 -DOS_LINUX' in my .vimrc fixes the issue.

gunslingerfry avatar Sep 13 '18 23:09 gunslingerfry

Does your g:clang_auto_user_options include compile_commands.json as per documentation?

xaizek avatar Sep 14 '18 08:09 xaizek

It was not. let g:clang_auto_user_options='compile_commands.json, path' however, makes no difference.

gunslingerfry avatar Sep 14 '18 15:09 gunslingerfry

The rest of my configuration:

let g:clang_library_path='/usr/lib/llvm-3.8/lib/libclang.so.1'
let g:clang_complete_auto=1
let g:clang_user_options='-std=gnu++14 -DOS_LINUX'
let g:clang_hl_errors=1
let g:clang_use_library=1
let g:clang_compilation_database=GetCompileDatabase()
let g:clang_complete_copen=1
let g:clang_close_preview=1
set completeopt=longest,menuone
function! GetCompileDatabase()
    let l:curPathVar = '%:p'
    let l:curPath = expand(l:curPathVar)
    let l:allPaths = l:curPath
    while l:curPath !=# '/'
        let l:allPaths .= ',' . l:curPath
        let l:curPathVar .= ':h'
        let l:curPath = expand(l:curPathVar)
    endwhile
    return fnamemodify(globpath(l:allPaths, 'compile_commands.json'), ':h')
endfunction

Function just gets the path of the compile_commands.json file. It's at the root of the project but I was getting errors when I opened source files in subdirectories.

gunslingerfry avatar Sep 14 '18 16:09 gunslingerfry

I've never tried using compilation database, maybe see #165, there was some discussion about absolute vs. relative paths.

xaizek avatar Sep 14 '18 16:09 xaizek

FWIW, I don't know if the compile database support is in the clang_complete plugin or the clang library, but I gave up on this. I just switched to the .clang_complete file. It's simple enough as long as you are writing the code and giving paths relative to the main include directory i.e. #include "mylib/myheader.h" then my .clang_complete file becomes

-Iinclude
-DOS_LINUX
--std=c++14

which is plenty simple.

gunslingerfry avatar May 29 '19 21:05 gunslingerfry