Blank file after make in vim - vim

When I run :make in vim, and if I have an error in my one and only cpp file (main.cpp) vim shows me the errors and when I press enter it opens a file named
^[[H^[[Jmain.cpp
instead of
main.cpp
And I have to manually reopen my file. Any idea how to tell vim to open the right file?
I'm running
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Apr 20 2016 11:17:28)
MacOS X (unix) version
Included patches: 1-1655 Compiled by Homebrew
Error output:
main.cpp:40:2: error: unknown type name 'obvious'
obvious error
^
main.cpp:40:15: error: expected ';' at end of declaration
obvious error
^
;
2 errors generated.
rm: main: No such file or directory
make: *** [all] Error 1
Press ENTER or type command to continue
vim errorformat (as reported by :echo &errorformat)
%*[^"]"%f"%*\D%l: %m,"%f"%*\D%l: %m,%-G%f:%l: (Each undeclared identifier is reported only once,%-G%f:%l: for each function it appears in.),%-GIn file included from %f:%l:%c:,%-GIn file included from %f:%l:%c\,,%-GIn file included from %f:%l:%c,%-GIn file included from %f:%l,%-G%*[ ]from %f:%l:%c,%-G%*[ ]from %f:%l:,%-G%*[ ]from %f:%l\,,%-G%*[ ]from %f:%l,%f:%l:%c:%m,%f(%l):%m,%f:%l:%m,"%f"\, line %l%*\D%c%*[^ ] %m,%D%*\a[%*\d]:Entering directory %*[`']%f',
%X%*\a[%*\d]: Leaving directory %*[`']%f',%D%*\a: Entering directory %*[`']%f',%X%*\a: Leaving directory %*[`']%f',%DMaking %*\a in %f,%f|%l| %m

Makefile looked something like this:
all:
clear && g++ main.cpp -o main
And the clear seems to be throwing it off. Workaround is to remove the clear or add an echo after
all:
g++ main.cpp -o main
all2:
clear && echo "" && g++ main.cpp -o main

Related

vim change base of relative path to source to other dir

I have a local Makefile which simply calls make -C ... As a result I get the output from the compiler with filenames and path to the directory relative to ...
Now vim isn't able to get the correct path for quickfix.
Q: How can I set the base path for vim quickfix to .. ?
My path structure:
<bla>/base/proj1/<localMakeFile>
<bla>/base/<globalMakefile>
<bla>/src/source1.cpp
I compile inside /base/proj1/
Compiler output for a error is like:
src/source1.cpp|141 col 54| Error: ....
But I am working in
/proj1/ so vim is unable to get the file src/source1.cpp
EDIT:
I see that the problem is basically related to the output of gnu make
make[4]: Entering directory '<bla>/...'
which is not parsed correctly if I use not an English environment. Setting the shell with export LANG= all works fine.
Q: Can vim parse also the German output of gnu make?
Appending the localized version with set errorformat+=<localized version> should work.
I am not aware that VIM supports it out of the box. After looking at the output of :set errorformat, which on my machine is a scary...
errorformat=%*[^"]"%f"%*\D%l: %m,"%f"%*\D%l: %m,%-G%f:%l: (Ea
ch undeclared identifier is reported only once,%-G%f:%l: for ea
ch function it appears in.),%-GIn file included from %f:%l:%c:,
%-GIn file included from %f:%l:%c\,,%-GIn file included from %f
:%l:%c,%-GIn file included from %f:%l,%-G%*[ ]from %f:%l:%c,%-G
%*[ ]from %f:%l:,%-G%*[ ]from %f:%l\,,%-G%*[ ]from %f:%l,%f:%l:
%c:%m,%f(%l):%m,%f:%l:%m,"%f"\, line %l%*\D%c%*[^ ] %m,%D%*\a[%
*\d]: Entering directory %*[`']%f',%X%*\a[%*\d]: Leaving direct
ory %*[`']%f',%D%*\a: Entering directory %*[`']%f',%X%*\a: Leav
ing directory %*[`']%f',%DMaking %*\a in %f,%f|%l| %m
...and by changing the output of the build process from
make: Entering directory `<directory>`
to
make: Entering `<directory>`
i got it to work by extending errorformat like this:
:set errorformat+=%D%*\\a:\ Entering\ %*[`']%f'

Makefile file function demo errors

I was trying to get the result of file function in makefile for my demo with a small makefile as:
CMD = cat
OBJECTS = Makefile Makefile-filter-func
program : $(OBJECTS)
$(file >$#.in) $(foreach O,$^,$(file >>$#.in,$O))
#echo The file has been created.
all :
$(CMD) $(CMDFLAGS) #$#.in
#echo The file contents are printed.
#rm $#.in
#echo The file removed.
I want to see the file the file name using ls command but this makefile has following error:
Makefile-file-func:7: *** recipe commences before first target. Stop.
where am I getting wrong.
A pointer to the answer can be found in the source code of make (version 3.82), in the file read.c:
989 /* This line starts with a tab but was not caught above because there
990 was no preceding target, and the line might have been usable as a
991 variable definition. But now we know it is definitely lossage. */
992 if (line[0] == cmd_prefix)
993 O (fatal, fstart, _("recipe commences before first target"));
With this information, it is possible to reproduce your issue by inserting spaces at the right spot. In the code below, ~ denotes a space and <TAB> denotes a TAB:
program : $(OBJECTS)
~~~~~~~~$(file >$#.in) $(foreach O,$^,$(file >>$#.in,$O))
<TAB> #echo The file has been created.
Since the spaces and tabs get lost in your question, it is a bit hard to see if this is exactly your case as well though.
Note that recipes are normally supposed to start with a TAB.

Latest linux kernel installation issue(rm: invalid option -- '0')

I have clone the latest linux source from git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
And compile this kernel using (make O=/usr/local/kernel).
But when i install the kernel the following error getting,
# make O=/usr/local/kernel modules_install install
make[1]: Entering directory `/usr/local/kernel'
rm: invalid option -- '0'
Try 'rm --help' for more information.
make[1]: *** [_modinst_] Error 1
make: *** [sub-make] Error 2
I faced the same issue today (24/1/20) and after a bit of searching, I decided to remove the # in front of each line in modinst target in Makefile. The problem was immediately visible to me. If you add space in extra version, the space will appear in your folder name. So, if you write extra version as
EXTRAVERSION= -test[un-noticed-space-here]
Your module folder name will also have that space. To avoid it, I tried the following
Made sure that there are no spaces at the end of version lines in Makefile
Did "make kernelversion" and made sure that it is devoid of any space character
Did a
echo -n `make kernelversion`| wc
and reconfirmed above point by comparing wc output and the count of characters from previous step

Linux: no such file or directory

I am new in Linux, can anyone tell me which directory the computer search for "ansinist.h"? Below is the syntax:
USER#USER-PC /cygdrive/f/Dataset_extract/500ppi-Legacy/SRC/BIN/TXT2NIST
$ make -f makefile.mak
gcc -ansi -O2 -I/include -L/lib -c txt2nist.c
txt2nist.c:15:22: fatal error: ansinist.h: No such file or directory
#include <ansinist.h>
^
compilation terminated.
makefile.mak:53: recipe for target 'txt2nist.o' failed
make: *** [txt2nist.o] Error 1
This answer could help you. In general case, be sure that you have installed the libraries that you're going to use in your project.
To find the file ansinist.h
sudo find / -name ansinist.h
And please paste your output here but you should be sure you installed all the required libraries first..
1)if your header file is in current directory then use #include "ansinist.h"
because this syntax search directly into current directory.
2)if your header file is in /usr/include/ then #include< ansinist.h>
because this syntax first search into /usr/include/ then current directory.
3)also you can use #include < /path/ansinist.h>
where path=path where is header file.
4)if above things will not work then please give value of #echo $PATH for next i can help you.

<command line>:1:1: error: macro names must be identifiers

I am new to Linux and makefiles. I have a makefile which generates .a files.
When I run the makefile, I get the following error. I have no idea from which part of the code, the error occurs.
[oracle#dyl02703app004 erm]# make -f erm_make_ida all
.... Compiling /home/wholesale/children/dev5/comps/erm/obj/ermparseyac.c
cc -g -DANSI -D -DTRACE_ON -DIDA_VERSION='"ISP-RG-V5.10.7GEN2A"' -DNO_MCP -DBUILDING_ERP -I/home/wholesale/children/dev5/comps/erm/include -I/home/wholesale/children/dev5/comps/erm/src -I/home/wholesale/children/dev5/comps/erm/module_test -I/home/wholesale/children/dev5/comps/erm/include -I/home/wholesale/children/dev5/comps/cfm/include -c /home/wholesale/children/dev5/comps/erm/src/ermparseyac.c -o /home/wholesale/children/dev5/comps/erm/obj/ermparseyac.o
<command line>:1:1: error: macro names must be identifiers
make: *** [/home/wholesale/children/dev5/comps/erm/obj/ermparseyac.o] Error 1
Any suggestions...?
You have a -D flag with no name. Look in your makefile to see what is causing it.

Resources