Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang_complete is ignoring compiler flags in compile_commands.json #564

Open
gunslingerfry opened this issue Sep 13, 2018 · 5 comments
Open

Comments

@gunslingerfry
Copy link

gunslingerfry commented Sep 13, 2018

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.

@xaizek
Copy link
Collaborator

xaizek commented Sep 14, 2018

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

@gunslingerfry
Copy link
Author

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

@gunslingerfry
Copy link
Author

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.

@xaizek
Copy link
Collaborator

xaizek commented Sep 14, 2018

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

@gunslingerfry
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants