2

In an attempt to add the include paths to Syntastic (3.6.0-106; Vim 7.3), to stop it from giving a fatal error at the first include it can't find, I tried creating a .syntastic_c_config file. There's not a lot of information on how this is supposed to work, but there are references out there and I followed their example:

-I/path/to/include
-I/you/get/the/idea
-L/some/library
-lfoo
-lbar
-DHAVE_SOME_FLAG
-pedantic
-Wall
-std=c99

That is, one compiler argument per line.

This has had the effect of removing virtually all error checking, unless I force it with :SynasticCheck -- at which point, it seems to work a little bit better, but not exactly how I'd expect. However, either way, if I :echo g:syntastic_c_config_file (or any other option that I'm expecting to be set), Vim just gives me an undefined variable warning.

I'm clearly doing something fundamentally wrong, but I'm not really sure what!

Xophmeister
  • 8,884
  • 4
  • 44
  • 87
  • Why do you expect `g:syntastic_c_config_file` to be set if you didn't set it? Have you tried enabling debugging to see what's going on? Did you read the wiki page for the gcc checker? – Sato Katsura Aug 12 '15 at 16:31
  • I have read https://github.com/scrooloose/syntastic/wiki/C%3A---gcc where it suggests that `g:syntastic_c_config_file` defaults to `.syntastic_c_config`. Indeed, when this file exists the behaviour is different, so it's definitely doing something regardless of me explicitly setting the variable... I wasn't aware of a debugging mode; I'll try that. – Xophmeister Aug 12 '15 at 16:52
  • With `let syntastic_debug=63`, it appears as though Syntastic *is* correctly opening the `.syntastic_c_config` file (regardless of it being unset) and passes those options into the call to `gcc` (without setting the `g:syntastic_c_*` options explicitly). The output was complaining that my `-L` and `-l` flags were useless: when I removed them from the config, it all started working. – Xophmeister Aug 13 '15 at 11:09
  • 1
    According to the maintainer, syntastic doesn't use the `g:syntastic_*` variables to keep state. It uses them to update its internal states _at the right moment_. They are still taken into account if you set them. As for the contents of the config file, you'd typically take the incantation to compile files from the `Makefile`, and keep only the compilation flags (`-l` and `-L` are linker flags). Some checkers can use compilation databases, but you need to configure them for that. This is described in the wiki. – Sato Katsura Aug 13 '15 at 18:07

2 Answers2

3

This is an old post, but I stumbled upon here searching for an answer to the same problem. Looks like Syntastic has changed quite a bit. Documentation listed above by OP is not valid anymore. Current (as of 18 July 2020) documentation is at: https://github.com/vim-syntastic/syntastic/blob/master/doc/syntastic-checkers.txt

To add include paths to 'gcc' checker, you would need to create a file with your include dirs, one per line, preceded by '-I'. For example, in /home/user/.syntastic_c_config_file add:

-I/usr/include/glib-2.0/include
-I/usr/include/boost

Then in your {vimrc} file (usually, ~/.vimrc), add one line:

let g:syntastic_c_config_file='/home/user/.syntastic_c_config_file'

Syntastic has become more powerful now and contains many options in the above linked documentation.

BReddy
  • 407
  • 3
  • 13
2

It turns out that Syntastic will source the configuration file without explicitly setting the respective variable. Moreover, the contents of the configuration file are not passed into any syntastic_c_* variables, but nonetheless passed into the call to gcc. Syntastic is also clever enough to backtrace to look for the configuration file (e.g., it will go up levels until it finds it, so you can keep the .syntastic_c_config in your project root).

As to why it was failing, the debug log was showing that my compiler was ignoring the library flags (-L/some/path and -lfoo) and that was blocking Syntastic from any further syntax checking. Removing those lines from my config file solved the problem.

Xophmeister
  • 8,884
  • 4
  • 44
  • 87