How to add c++11 support to syntastic vim plugin?

 

i.gif?e=eyJhdiI6NDE0LCJhdCI6NCwiYnQiOjAsImNtIjo0NzE0OTMsImNoIjoxMTc4LCJjayI6e30sImNyIjoxNjM4OTg1LCJkaSI6ImE3NWU0NDg3Y2Y2MjQ1N2M4Y2Y2YTA5ZmI3NzgzM2FmIiwiZG0iOjEsImZjIjoxOTQzNDM2LCJmbCI6MjE0MjMxMiwiaXAiOiIxODAuMTczLjI0Ny4xNDciLCJrdyI6InZpbSxjKysxMSxzeW50YXN0aWMiLCJudyI6MjIsInBjIjowLCJlYyI6MCwicHIiOjE2MDQsInJ0IjoxLCJyZiI6Imh0dHBzOi8vd3d3LmJhaWR1LmNvbS9saW5rP3VybD1qVVRBcjlJc2JBTnJRLXQtZTNLM3BUWkdKQ2dCSU0yWVdzSXZNMkxsbDFkU1RjTG5VUUVKZDU3ZGZCTkNPM1JMV3QxZWtMTlBaRUlIdVY4SkxVZVpQMUp4bVZOU3dnUjNsSXRST2ZaTDFOQlN2YW5YU29aVEhUa1VyMUVuZnY4RzQ0WDQtTnVsYkZVdGsyX2hmY05yQ2Emd2Q9JmVxaWQ9ODE5ZDkyMzgwMDAwN2MwZDAwMDAwMDAyNTg5YjA5NjAiLCJzdCI6ODI3NywidWsiOiJ1ZTEtYjJjNGI2MjY1ZjBjNDc0M2FmNzkzNGE0M2UxNDE3YWYiLCJ6biI6NDMsInRzIjoxNDg2NTU1NjAyNjQ3LCJiZiI6dHJ1ZSwicG4iOiJhZHplcmszNzMzNjI5MTUiLCJmcSI6MH0&s=bq3T-6mm8kT1XWDiEkqb5ZA-ktY

up vote 38 down vote favorite

13

I am using syntastic in my c++11 project. When I am editing in vim, and save (:w) the syntastic plugin gives me errors on every initializer list {} and for each loops which are clearly c++11 features that it's missing.

I installed syntastic using pathogen.

Here are two examples of the error I am getting on initializer lists and for each loops (both c++11 that compile fine):

error on initializer listserror on for each loop

vim c++11 syntastic

shareimprove this question

edited Aug 14 '13 at 14:13

asked Aug 10 '13 at 5:00

Carneiro

1,88411529

 
1 

What is the output of :echo b:clang_user_options command from a buffer belonging to the project? If your assumption is correct, there will be no -std=c++ substring. – xaizek Aug 11 '13 at 10:32

   

The output of :echo b:clang_user_options is -I/usr/include -std=c++11 -stdlib=libc++. So I don't understand why I'm getting the errors related to initializer lists and for each loops. I'll add an example error to the main post. – Carneiro Aug 12 '13 at 14:15

   

Turns out this is not clang_complete, this is syntastic. I will update the post and the answer. – Carneiro Aug 14 '13 at 14:11

add a comment

5 Answers

active oldest votes

 

up vote 68 down vote accepted

Turns out the C++ linter (syntax checker) of syntastic has many options that can be set on your .vimrc (unfortunate, I wish it was project specific, like the .clang_complete solution).

To enable c++11 standards and use the libc++ library with clang (which is what my project is using) I added the following lines to my ~/.vimrc

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

it now works beautifully.

shareimprove this answer

answered Aug 14 '13 at 14:15

Carneiro

1,88411529

 
   

As I checked clang++ and g++ options are identical, I replaced "clang++" with "g++", but it still not working – rafee Oct 19 '13 at 8:11

   

I don't think you can run g++ with -stdlib=libc++ though. – Carneiro Oct 20 '13 at 15:29

   

I tried without -stdlib=libc++ too, but that wasn't successful either – rafee Oct 20 '13 at 15:41

   

Actually I compiled without -stdlib, but put -stdlib in .vimrc, when normal settings weren't successful – rafee Oct 20 '13 at 15:44

1 

This seems to work for g++ now as well. – Alex May 20 '16 at 3:22

show 2 more comments

 

up vote 4 down vote

I was facing the same problem and I insist to process c++98 and c++11 separately. below is my solution:

create file named gcc.vim under bundle/syntastic/syntax_checkers/cpp11/ and copy these to it:

"============================================================================
"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:

that will make gcc checker available (want other checker? you can do the similar things i did for yourself) for files with &filetype == 'cpp11' in vim. how to make your files automatically recongnized as cpp11 filetype in vim? just create file named ext_detect.vim under ~/.vim/ftdetect/ with the following content:

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

by this way, you can process your *.cpp files as c++98 standard and *.cpp11 or *.cppx as c++11 standard separately, not only syntax checking, but also syntax highlighting (if you need cpp11 syntax highlighting support, this vim plugin will be useful, although not perfect).

shareimprove this answer

answered Apr 3 '14 at 3:38

luochen1990

46939

 

add a comment

 

up vote 4 down vote

It has project specific options, like the .clang_complete solution

You can set path to files g:syntastic_cpp_config_file and g:syntastic_c_config_file. The default is .syntastic_cpp_config for C++. Put file in root of the project and compiler options inside it (one for each line)

for details

shareimprove this answer

answered May 23 '14 at 7:28

The_Ham

875

 

add a comment

 

up vote 0 down vote

If your using YouCompleteMe in addition to Syntastic you need to change your .ycm_extra_conf.py file. Sepcifically change '-Wc++98-compat' to '-Wnoc++98-compat'.

I didn't have to change the Syntastic settings myself, although that might be because I'm using a compile_commands.json file.

via here.

shareimprove this answer

answered Feb 26 '14 at 2:04

David C. Bishop

3,9462022

 

add a comment

 

up vote 0 down vote

If you use YouCompleteMe,maybe you should change '.ycm_extra_conf.py'.only change flags:(file 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/',
 ]

转载于:https://my.oschina.net/chaenomeles/blog/834289

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值