I've got a setup with Vim where I can compile my C/C++ code using :make
and compilation errors are automatically shown in a quickfix window using the following lines (from the Vim wiki) in my ./vimrc
:
" Automatically open, but do not go to (if there are errors) the quickfix /
" location list window, or close it when is has become empty.
"
" Note: Must allow nesting of autocmds to enable any customizations for quickfix
" buffers.
" Note: Normally, :cwindow jumps to the quickfix window if the command opens it
" (but not if it's already open). However, as part of the autocmd, this doesn't
" seem to happen.
autocmd QuickFixCmdPost [^l]* nested cwindow
autocmd QuickFixCmdPost l* nested lwindow
Now this setup works well if there is an error in a .cpp file, as the output from make is correctly parsed:
$ make
g++ -c -o IsingMain.o IsingMain.cpp
g++ -c -o LatticeModel.o LatticeModel.cpp
LatticeModel.cpp: In member function ‘void LatticeModel::initialiseSystem()’:
LatticeModel.cpp:18:25: error: ‘sirand’ was not declared in this scope
i.e. vim correctly switches to LatticeModel.cpp
.
However if the error is in the header file, the make output is misinterpreted, and vim switches/creates a new buffer (for the following example make
output) with name "In file included from IsingMain.cpp
", clearly erroneously assuming that this is the file with the error (in fact the error is in LatticeModel.h):
$ make
g++ -c -o IsingMain.o IsingMain.cpp
In file included from IsingMain.cpp:2:0:
LatticeModel.h:31:5: error: ‘Zvoid’ does not name a type
Running make from the commandline works perfectly well, it's just an issue with quickfix misreading it's output. Any help greatly appreciated, let me know if any part of this is confusing. Thanks
EDIT: It seems to be something to do with with an incorrect errorformat (as described in this thread.)
EDIT 2: Temporary fix found by ignoring the make output line that starts with "In file included from" using this technique.
While I have still not found a proper solution, the workaround suggested here: http://groups.google.com/group/vim_dev/msg/ed4f258f5b4b9749 seems to work for the time being.
set errorformat^=%-GIn\ file\ included\ %.%#
EDIT: see also Vim tries to jump to nonexistent file after :make
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With