Добавление C++11 в Syntastic правильно

Мне известен вопрос, который уже существует здесь по этому поводу, но я не мог расследовать, комментируя, потому что у меня недостаточно репутации.

Поэтому я использую синтетику в vim и хочу скомпилировать материал на С ++.

Мой vimrc выглядит так:

 72 set statusline+=%#warningmsg#
 73 set statusline+=%{SyntasticStatuslineFlag()}
 74 set statusline+=%*
 75 
 76 " let g:syntastic_cpp_compiler = 'g++'
 77 let g:syntastic_cpp_compiler_options = ' -std=c++11'
 78 
 79 let g:syntastic_always_populate_loc_list = 1
 80 let g:syntastic_auto_loc_list = 1
 81 let g:syntastic_check_on_open = 1
 82 let g:syntastic_check_on_wq = 0

Моя программа выглядит так:

    1 #include <functional>
    2 
    3 using namespace std;
    4 
    5 int f(int x){
    6         return x;
    7 }
    8 
    9 void f2(function<int(int)> f){
   10 
   11 }
   12 
   13 int main(){
   14         return 0;
   15 }

Если я заменю строку 76 "clang++" вместо "g++" в моем vimrc, я получаю следующие ошибки:

  1 diff.cpp|11 col 6 error| variable has incomplete type 'void'                                        
  2 diff.cpp|11 col 11 error| use of undeclared identifier 'function'
  3 diff.cpp|11 col 33 error| expected '(' for function-style cast or type construction
  4 diff.cpp|11 col 46 error| expected '(' for function-style cast or type construction
  5 diff.cpp|11 col 48 error| expected ';' after top level declarator

Если я просто удалю строку 77 и скомпилирую с g ++, я получу:

  1 test.cpp|9 col 9 error| variable or field ‘f2’ declared void                                        
  2 test.cpp|9 col 9 error| ‘function’ was not declared in this scope
  3 test.cpp|9 col 18 error| expected primary-expression before ‘int’

Наконец, если я скомпилирую программу, как она выглядит здесь, я не получу никаких проверок синтаксиса. Если я потом скомпилирую, то получу:

test.cpp:9:9: error: variable or field ‘f2’ declared void
 void f2(function<int(int)> f){
         ^
test.cpp:9:9: error: ‘function’ was not declared in this scope
test.cpp:9:18: error: expected primary-expression before ‘int’
 void f2(function<int(int)> f){

Почему это и какие шашки нужно добавить для простой компиляции файлов C++11? это действительно расстраивает

1 ответ

let g:syntastic_cpp_compiler_options = ' -std= C++11'

В строке 77 вашего vimrc есть небольшая ошибка. Так должно быть

let g:syntastic_cpp_compiler_options = ' --std=c++11'

Обратите внимание на две черты перед std=c++11

Другие вопросы по тегам