2013-08-10 6 views
44

내 C++ 11 프로젝트에서 syntastic을 사용하고 있습니다. vim에서 편집 할 때 syntact 플러그인을 사용하면 모든 초기화 목록 {}에 오류가 발생하고 명확한 C++ 11 기능인 각 루프에 대해 오류가 발생합니다.syntynamic Vim Plugin에 C++ 11 지원을 추가하는 방법은 무엇입니까?

나는 병원균을 사용하여 합성물을 설치했습니다.

error on initializer lists error on for each loop

+1

프로젝트에 속한 버퍼의': echo b : clang_user_options' 명령의 출력은 무엇입니까? 가정이 맞다면'-std = C++ '부분 문자열이 없을 것입니다. – xaizek

+0

': echo b : clang_user_options'의 출력은'-I/usr/include -std = C++ 11 -stdlib = libC++'입니다. 그래서 나는 초기화리스트와 관련된 에러를 얻는 이유와 각각의 루프를 이해하지 못한다. 메인 포스트에 예제 오류를 추가하겠습니다. – Carneiro

+0

이것은 ** ** clang_complete가 아닌 ** 이것은 syntastic입니다. 게시물과 답변을 업데이트 할 것입니다. – Carneiro

답변

80

는 C++ 린터 (구문을 밝혀 :

여기 (잘 컴파일 모두 C++ 11) 내가 초기화 목록에 각 루프 무엇입니까 오류의 두 가지 예 checker)에는 .vimrc에 설정할 수있는 많은 옵션이 있습니다 (불행히도, .clang_complete 솔루션과 같은 특정 프로젝트 였으면 좋겠습니다).

는 C++ 11 개 표준을 사용하고 난 다음 줄을 추가 (내 프로젝트가 사용하고있는 것입니다) 그 소리와의 libC++ 라이브러리를 사용하려면 내 ~ /의 .vimrc 지금 아름답게 작동

let g:syntastic_cpp_compiler = 'clang++' 
let g:syntastic_cpp_compiler_options = ' -std=c++11 -stdlib=libc++' 

.

+0

clang ++ 및 g ++ 옵션이 동일하므로 "clang ++"를 "g ++"로 바꿨지 만 여전히 작동하지 않습니다 – rafee

+0

g ++을 -stdlib = libC++와 함께 실행할 수 있다고 생각하지 않습니다. – Carneiro

+0

-stdlib = libC++없이 시도했지만 성공하지 못했습니다. – rafee

0

Synthetic과 함께 YouCompleteMe를 사용하는 경우 .ycm_extra_conf.py 파일을 변경해야합니다. Sepcifically '-WC++ 98-compat'을 '-WnoC++ 98-compat'으로 변경하십시오.

compile_commands.json 파일을 사용하고 있기 때문에 Synthetic 설정을 직접 변경할 필요가 없었습니다.

via here.

4

나는 똑같은 문제를 겪고 있었고 나는 C++ 98과 C++ 11을 별도로 처리해야한다고 주장했다..

하는 파일 이름 gcc.vim 그것에/syntastic/syntax_checkers/cpp11/ 번들 에서 이러한 복사 만들 : GCC 검사기를 사용할 수 있도록합니다

"============================================================================ 
"File:  cpp11.vim 
"Description: Syntax checking plugin for syntastic.vim 
"Maintainer: Gregor Uhlenheuer <kongo2002 at gmail dot com> 
"License:  This program is free software. It comes without any warranty, 
"    to the extent permitted by applicable law. You can redistribute 
"    it and/or modify it under the terms of the Do What The Fuck You 
"    Want To Public License, Version 2, as published by Sam Hocevar. 
"    See http://sam.zoy.org/wtfpl/COPYING for more details. 
" 
"============================================================================ 

if exists('g:loaded_syntastic_cpp11_gcc_checker') 
    finish 
endif 
let g:loaded_syntastic_cpp11_gcc_checker = 1 

if !exists('g:syntastic_cpp11_compiler') 
    let g:syntastic_cpp11_compiler = executable('g++') ? 'g++' : 'clang++' 
endif 

if !exists('g:syntastic_cpp11_compiler_options') 
    let g:syntastic_cpp11_compiler_options = '-std=c++11' 
endif 

let s:save_cpo = &cpo 
set cpo&vim 

function! SyntaxCheckers_cpp11_gcc_IsAvailable() dict 
    return executable(expand(g:syntastic_cpp11_compiler)) 
endfunction 

function! SyntaxCheckers_cpp11_gcc_GetLocList() dict 
    return syntastic#c#GetLocList('cpp11', 'gcc', { 
     \ 'errorformat': 
     \  '%-G%f:%s:,' . 
     \  '%f:%l:%c: %trror: %m,' . 
     \  '%f:%l:%c: %tarning: %m,' . 
     \  '%f:%l:%c: %m,'. 
     \  '%f:%l: %trror: %m,'. 
     \  '%f:%l: %tarning: %m,'. 
     \  '%f:%l: %m', 
     \ 'main_flags': '-x c++ -fsyntax-only', 
     \ 'header_flags': '-x c++', 
     \ 'header_names': '\m\.\(h\|hpp\|hh\)$' }) 
endfunction 

call g:SyntasticRegistry.CreateAndRegisterChecker({ 
    \ 'filetype': 'cpp11', 
    \ 'name': 'gcc' }) 

let &cpo = s:save_cpo 
unlet s:save_cpo 

" vim: set et sts=4 sw=4: 

이 (다른 원하는 아래에있는 내 솔루션입니다 checker? & filetype == 'cpp11'인 파일의 경우 vim에서 비슷한 작업을 수행 할 수 있습니다. 파일을 vim에서 cpp11 파일 형식으로 자동 변환하는 방법은 무엇입니까? 당신은 C++ 98 표준과로 *의 .CPP 파일을 처리 할 수 ​​

au bufnewfile,bufread *.cpp11 set ft=cpp11 
au bufnewfile,bufread *.cppx set ft=cpp11 

이 방법에 의해 : 단지 ext_detect.vim 다음과 같은 내용으로 ~/.vim/ftdetect/아래라는 이름의 파일을 생성 * .cpp11 또는 * .cppx를 별도로 C++ 11 표준으로 사용할 수 있습니다. 구문 검사뿐만 아니라 구문 강조 표시도 가능합니다 (cpp11 구문 강조 표시가 필요하면 this vim plugin이 유용 할 수 있지만 완벽하지는 않음).

4

그것은 .clang_complete 솔루션

당신은 g 파일에 대한 경로를 설정할 수 있습니다와 같은 프로젝트 특정 옵션이 있습니다 syntastic_cpp_config_file와 g : syntastic_c_config_file합니다. 기본값은 C++의 .syntastic_cpp_config입니다.details

0

에 대한 그 안에 프로젝트와 컴파일러 옵션의 루트에 파일을 넣어 (각 행에 대해 하나)

당신이 YouCompleteMe를 사용하는 경우, 어쩌면 당신이 '변경해야합니다 플래그를 변경 .ycm_extra_conf.py'.only : (파일을 path ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py);

flags = [ 
'-std=c++11', 
'-O0', 
'-Werror', 
'-Weverything', 
'-Wno-documentation', 
'-Wno-deprecated-declarations', 
'-Wno-disabled-macro-expansion', 
'-Wno-float-equal', 
'-Wno-c++98-compat', 
'-Wno-c++98-compat-pedantic', 
'-Wno-global-constructors', 
'-Wno-exit-time-destructors', 
'-Wno-missing-prototypes', 
'-Wno-padded', 
'-Wno-old-style-cast', 
'-Wno-weak-vtables', 
'-x', 
'c++', 
'-I', 
'.', 
'-isystem', 
'/usr/include/', 
]