Quickfix in VIM

Quickfix in VIM

One of the most fascinating things with the VIM editor is that you find new features every day, even after many years of heavy usage.

Quickfix is one of those features.

Quickfix parse your compiler-output and let you easy navigate to the concerned lines with errors and/or warnings. Great hue?

How does it work?

The builtin command is (surprisingly) make.
Just do
:make (without bang character!)

make will do whatever the makeprg variable is set to. By default makeprg is set to … make (as in GNU Make, not the builtin command).

For example, if you are programming ruby, you may set makeprg to "ruby -c %".

I compile the Linux kernel a few times a day, so I usually set the the variable like this:

set makeprg=make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- uImage

Ok, the stuff is compiling, now what?

Typical commands you use is::
:copen – opens quick fix window as a new buffer
:cnext – or :cn, jump to next error
:cprevious – or :cp, jump to previous error
:cclose – close the quick fix window

And the best of all:

:cwindow - or :cw, open quickfix window if there are errors and close it if there are not.

LDD without LDD

LDD without LDD

I often meet colleges at work who gets frustrated when they try to print the shared libraries dependencies for an ELF or library, and the ldd command is simply stripped out from target. (I do often strip targets 🙂 )

As if that would be a big problem.

The ldd command is not a binary executable, but a script that simple calls the runtime dynamic linker with a few environment variables set, and you may do the same!
The essential environment variable in this case is LD_TRACE_LOADED_OBJECTS, that should be set to something != 0.

In short, you may do:

LD_TRACE_LOADED_OBJECTS=1 /lib/ld-linux.so.2 ./my_application.

Even the –list option may be used, but does not work on all targets.:

/lib/ld-linux.so.2 --list ./my_application.

Example outputs with ldd:

[11:16:58]marcus@tuxie:/tmp/a$ ldd ./main linux-vdso.so.1 =>  (0x00007fffc8bff000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f564e254000) /lib64/ld-linux-x86-64.so.2 (0x00007f564e647000)

Example output without ldd:

[11:17:23]marcus@tuxie:/tmp/a$ LD_TRACE_LOADED_OBJECTS=1 /lib64/ld-linux-x86-64.so.2 ./main linux-vdso.so.1 =>  (0x00007fffeecbc000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fcce7700000) /lib64/ld-linux-x86-64.so.2 (0x00007fcce7af3000)

So, do not get frustrated, be happy.