i'm trying to make the make utility work on windows through MinGW, but i keep getting error 2 while trying to make the make utility perform a task that isn't a command from MinGW.
test: test.cpp
g++ -o test test.cpp
clean:
rm ./*.exe
compiling works fine, but when i try to run clean, i get an error.
PS D:\Programs\C++\Test> make clean
rm ./*.exe
process_begin: CreateProcess(NULL, rm ./*.exe, ...) failed.
make (e=2): Impossibile trovare il file specificato.
makefile:5: recipe for target 'clean' failed
make: *** [clean] Error 2
but typing rm ./.exe directly into the windows powershell works just fine.
all the examples i could find online were about people calling programs that weren't linked in the windows PATH, but here it's not the problem, since make is linked to the PATH and rm ./.exe works on the powershell. any ideas?
thank you in advance.
The commands you use in Powershell aren't avaliable that way. The ones that are available are from the cmd (cmd.exe) command prompt. The command that removes files in the cmd prompt is erase.
All of this is because programs run as if they were launched in cmd.
For more commands, you should run help on the cmd prompt.
Also rm is just an alias for the legacy erase.
I installed Doxygen on a Debian VM on Virtualbox, hosted by a Windows 10 pc. It runs smoothly as creates all the basic documentations, but when I enter into a latex documentation directory and try to run make it gives me the following bash report (roughly translated from italian):
rm -f *.ps *.dvi *.aux *.toc *.idx *.ind *.ilg *.log *.out *.brf *.blg *.bbl refman.pdf
pdflatex refman
make: pdflatex: command not found
Makefile:8: instruction set for target "refman.pdf" failed
make: *** [refman.pdf] Error 127
I searched for this error but I couldn't find anything about. Both the doxyfile and the latex makefile aren't modifed.
Results form generating with doxygen generated Makefile indicates that the pdflatex cannot be found.
Problem appears to be that the installation of TexLive didn't add the directory with e.g. pdflatex to the path.
I have a very simple makefile that I ported from Linux to Windows
it only goes inside subfolders and calls other makefiles
all:
$(MAKE) clean
#(cd apps; $(MAKE))
clean:
cd apps; $(MAKE) clean;
the problem is that I don't understand how the #(command1; command2; command3;) syntax works and I'm unable to make it work even with the simplest of commands
For instance
all:
dir
works fine and it outputs the contents of the directory (and I'm in the right one)
all:
cd apps; dir
Does not work, it outputs
cd apps; dir The system cannot find the path specified.
Even worse if I keep the parentheses:
all:
#(dir)
outputs
process_begin: CreateProcess(NULL, (dir), ...) failed. make (e=2): The
system cannot find the file specified.
Can somebody please point me to the proper documentation? I know it must be very simple but all the guesswork so far failed and the documentation is too huge to read it all. I tried but I couldn't find what I'm looking for
Thanks
I am using a makefile in windows to push some files on a Unix server (here a text file "blob.txt" in the same folder of my makefile).
My makefile script is:
setup:
pscp blob.txt username#hostname:/folder/
I start a command prompt, go in the folder where blob.txt and the makefile are present and type:
make setup
Which results in:
pscp blob.txt username#hostname:/folder/
process_begin: CreateProcess(NULL, pscp blob.txt username#hostname:/folder/, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [setup] Error 2
In a #fail ... whereas if I enter directly the command in the command prompt:
pscp blob.txt username#hostname:/folder/
It works ... I really wonder why.
The error
process_begin: CreateProcess(NULL, pscp blob.txt username#hostname:/folder/, ...) failed.
make (e=2): The system cannot find the file specified.
is almost certainly complaining that Windows cannot find pscp.
This is almost certainly because the value of %PATH% (or whatever) is different when make spawns a shell/console then when you have it open manually.
Compare the values to confirm that. Then either use the full path to pscp in the makefile recipe or ensure that the value of PATH is set correctly for make's usage.
I didn't want to remove GIT's bin folder from the PATH variable (I am using a Windows machine), as I use it quite often. So I looked for a workaround, and here it is:
Add the <git-installation-directory>/usr/bin directory to your PATH variable too. This basically adds the rest of the linux-like commands that come with the "GIT bash" to your environment. After applying this, my makefiles ran normally again. :)
If you are curious about what shell is being invoked by make, just add $(info $(SHELL)) at the beginning of your makefile. The path/name of the shell being invoked is printed to the console as soon as you run make.
I know this is an old question that has been answered, but thought I'd and my experiences for anyone still running into this. I was getting the same cryptic error Colonel Beauvel (though with the windows MOVE command, not pscp):
process_begin: CreateProcess(NULL, move /y foo\bar.c .\baz.c, ...) failed.
make (e=2): The system cannot find the file specified.
Our CI was running the same Makefile and working perfectly. Turns out CI was using mingw32-make and I was using GNU make. Uninstalling GNU make (which got installed as part of an unrelated bulk package) and aliasing mingw32-make to 'make' works perfectly.
#user3869623's solution works for me. I'd like to share some details of mine to complete the picture.
My makefile contains below target:
clean:
#echo '$(OS)'
ifeq ($(OS),Windows_NT)
del /s *.o *.d *.elf *.map *.log
endif
When I run make clean, I see this error:
Since it says something went wrong with echo, so I change my makefile target to below:
clean:
ifeq ($(OS),Windows_NT)
del /s *.o *.d *.elf *.map *.log
endif
This time, make clean gives me this error:
I am surprised to see bash here since I am working in Windows command line.
Then I checked my %PATH%, I see this entry:
C:\DevTools\Git\bin
There's a bash.exe and sh.exe in that path. So I removed this entry, and it works fine now.
BUT I STILL DON'T KNOW WHY BASH GET INTO THIS???
ADD 1
As to why the C:\DevTools\Git\bin shows up in my %PATH%, because I am using Sublime and it always asks me for the Git binaries:
In my case, I had git\bin in my %PATH% which contains bash.exe and sh.exe.
Removing %GIT_HOME%\bin from the PATH worked for me.
To build on user3869623's response.
In my case i had git\bin in my %PATH% which contains bash.exe and sh.exe.. Removing %GIT_HOME%\bin from the PATH worked for me
While this recommendation may allow make to run, it will likely cause issues for git, especially if the makefile is installing software from a git repository.
A better solution is to simply change %GIT_HOME%\bin to %GIT_HOME%\cmd
For those who tried removing the git bin folder from PATH and it didn't work for them, search your PATH variables for any paths containing bash.exe.
In my case I found a variable linking to cygwin bin folder C:\cygwin64\bin, removed it and it worked.
I had the same issue, and this thread really helped me solve it. In my case, it was a conflict between make and the sh.exe that was visible through my path, due to both git and mingw64. To fix my issue, without breaking Git, I added these lines to the top of my batch file that calls make:
set path=%path:git\bin=;%
set path=%path:mingw64\bin=;%
set path=%path:usr\bin=;%
This hides the extra sh.exe instances from make for that instance only.
I ran into this problem recently and this question was one of the top hits for my searches.
None of the other answers here helped me. The fix, for me, was to put the binary name in quotes:
setup:
"pscp" blob.txt username#hostname:/folder/
-"pscp" blob.txt username#hostname:/folder/ # Failure is OK, `-` in front
I'm on windows.
By explicitly setting my compiler to gcc (instead of cl?) it solved my problem.
CC = gcc
I hope some people more knowledgeable than me could explain why changing the compiler would impact the makefile parsing.
It does not appear to be possible to call Windows system commands (e.g. del, move, etc) using GNU Make. I'm trying to create a makefile that doesn't rely on the user having extra tools (e.g. rm.exe from Cygwin) installed.
When the following rule is run, an error is reported del: command not found:
clean:
del *.o
This is presumably because there is no such execuatable as "del". I've also tried running it as an option to cmd but with this only seems to open a new prompt:
clean:
cmd /C del *.o
I'm using Windows XP (5.1.2600) with GNU Make 3.79.1 that is bundled as part of MSys.
It seems the /C switch needs to be escaped because a / is interpreted as a path in GNU Make. The following works as expected:
clean:
cmd //C del *.o
Because DOS-based systems have two different commands for removing files and directories, I find that having two different defines works the best:
ifeq ($(OS),Windows_NT)
RM = cmd //C del //Q //F
RRM = cmd //C rmdir //Q //S
else
RM = rm -f
RRM = rm -f -r
endif
clean:
$(RM) $(TARGET).elf $(TARGET).map
$(RRM) $(BUILD_DIR)
Happened to me too. At the top of your makefile add:
SHELL=cmd
Since you are compiling on windows, select 'cmd' as the default shell. This
is important because GNU make will search the path for a linux/unix like shell and if it finds one it will use it instead. This is the case when cygwin is installed. The side effect of this behavior is that commands like 'del' and 'echo' are not found. If we tell GNU make to use 'cmd' as its shell, then 'del' and such will be available.
del is a builtin command of cmd.exe (as well as previously command.com). Your command cmd /C del *.o should work, if it starts a new command prompt I suspect that cmd maybe might be a wrapper. Have you tried to call cmd with its full path (e.g. c:/WINDOWS/system32/cmd.exe)?
Tom Longridge's answer was close to the truth for me, but the escaping needed to be done using a backslash before the forward slash on the Windows Vista Business machine I was needing this for:
RM=cmd \/C del
Another solution is to create a del.bat file containing:
#echo off
del %*
then the makefile can simply contain
clean:
del *.o
this cleans up the makefile, but may clutter your build directory slightly.
I just completed this. I am not sure if things have changed in DOS/Windows but this was how it had to be formatted with current versions.
OBJ=o
BIN=bin
clean:
cmd /C del $(OBJ)\\*.o
cmd /C del $(BIN)\\*.exe