weird behavior of nmake under gsh.exe on windows10 - shell

Please help me troubleshoot the following problem I am facing with my app.
I have written my own shell for windows, named gsh, which currently implements most of the CMD.EXE functionality. So far all activities I perform under GSH are identical to CMD, except for this issue I have with the NMAKE program.
Here's the test scenario. I have several c++ projects built using 'nmake all' on command prompt. Under CMD, nmake runs smoothly (meaning it builds all the targets that need to be built). Under GSH, however, namke builds the first set of targets ( i.e. all *.obj for *.cpp) but not the *.exe that depend on the newly bult *.obj. I have to run 'nmake all' a second time to built the *.exe.
If I run 'nmake clean' before 'nmake all' then all targets are built fine.
I am 100% sure makefile is correct. I have checked all environment variables between GSH and CMD and they are the same. I have also checked the dates on the produced files and they look fine(meaning dates on produced files are newer, and date of *.exe is older than the date of the depending *.obj). I can also confirm that while 'nmake all' is running, it does not invoke another copy of the shell (to do its tasks, which might caused a problem to nmake). Note: On a complex makefile, I can see nmake issuing system(...) function which invokes the shell pointed by ComSpec env var, which I can direct it to either GSH or CMD, without any apparent change in behavior.
Thank you all for any ideas you might have on the root cause of the above.
cheers!, gt

Related

Windows makefile - invalid switch and and unrecognized environmental variables

So I recently overtook an old project and the person originally responsible for the project left the company, so sadly there is no one to ask. Basically, the project is an environment generator, originally written in a bunch of batch files and then reworked as a python project. Sadly, there is also very limited documentation and I do not have a lot of developing experience on windows.
So yeah the OS is Windows 10, python version 3.8.
My issue is as follows:
At some point the env-generator calls a makefile generator (originally developed by another company and again the person responsible is no longer there). The generated makefile contains the following lines (and a lot more similar ones):
.PHONY: pycharm
pycharm:
cmd /c start /B $(PKG_pyCharm_ce_2019_1)/bin/pycharm64.exe .
And it works fine if the environment is generated using the original bat-file based generator. However, with the "new" env-generator, I can no longer run the makefile, although I am using the same version of make (GNU Make 4.1 - Built for Windows32).
Basically, I have two issues. First I get the error Invalid switch - "/bin". and secondly it does not resolve the environmental variable (i.e. I end up with \bin\pycharm64.exe instead of C:\devapp\ipm\p\pyCharm_ce_2019_1\0.0.2\data\bin\pycharm64.exe).
If I change the line by hand to:
.PHONY: pycharm
pycharm:
cmd /c start /B %PKG_pyCharm_ce_2019_1%\bin\pycharm64.exe .
it works fine. What could be the reason that it works differently?
I have checked that the PATH and other used environmental variables are the same.
If I run the commands directly from the shell
cmd /c start /B C:\devapp\ipm\p\pyCharm_ce_2019_1\0.0.2\data/bin/pycharm64.exe .
and
cmd /c start /B %PKG_pyCharm_ce_2019_1%/bin/pycharm64.exe .
work fine,
cmd /c start /B $(ISC_IPM_PKG_pyCharm_ce_2019_1)/bin/pycharm64.exe .
doesn't (Windows cannot find $(ISC_IPM_PKG_pyCharm_ce_2019_1)/bin/pycharm64.exe).
Why is this? And what do can I change in my environment to make the first lines work?
Sadly, I cannot change the makefile generator, and changing the lines manually (or via script) does not really scale to the usage scenario.

Makefile.mak giving error [duplicate]

I have Windows 7 and tried to use the 'make' command but 'make' is not recognized as an internal or external command.
I did Start -> cmd -> run -> make, which outputs:
'make' is not recognized as an internal or external command,operable program or batch file.
Then I typed 'mingw32-make' instead of 'make' (Start -> cmd -> run -> mingw32-make) and I get the same output:
'mingw32-make' is not recognized as an internal or external command,operable program or batch file.
What shall I do next in order to fix this problem?
In Windows10, I solved this issue by adding C:\MinGW\bin to Path and then called it using MinGW32-make not make.
Your problem is most likely that the shell does not know where to find your make program. If you want to use it from "anywhere", then you must do this, or else you will need to add the full path each time you want to call it, which is quite cumbersome. For instance:
"c:\program files\gnuwin32\bin\make.exe" option1=thisvalue option2=thatvalue
This is to be taken as an example, it used to look like something like this on XP, I can't say on W7. But gnuwin32 used to provide useful "linux-world" packages for Windows. Check details on your provider for make.
So to avoid entering the path, you can add the path to your PATH environment variable. You will find this easily.
To make sure it is registered by the OS, open a console (run cmd.exe) and entering $PATH should give you a list of default pathes. Check that the location of your make program is there.
This is an old question, but none of the answers here provide enough context for a beginner to choose which one to pick.
What is make?
make is a traditional Unix utility which reads a Makefile to decide what programs to run to reach a particular goal. Typically, that goal is to build a piece of software from a set of source files and libraries; but make is general enough to be used for various other tasks, too, like assembling a PDF from a collection of TeX source files, or retrieving the newest versions of each of a list of web pages.
Besides encapsulating the steps to reach an individual target, make reduces processing time by avoiding to re-execute steps which are already complete. It does this by comparing time stamps between dependencies; if A depends on B but A already exists and is newer than B, there is no need to make A. Of course, in order for this to work properly, the Makefile needs to document all such dependencies.
A: B
commands to produce A from B
Notice that the indentation needs to consist of a literal tab character. This is a common beginner mistake.
Common Versions of make
The original make was rather pedestrian. Its lineage continues to this day into BSD make, from which nmake is derived. Roughly speaking, this version provides the make functionality defined by POSIX, with a few minor enhancements and variations.
GNU make, by contrast, significantly extends the formalism, to the point where a GNU Makefile is unlikely to work with other versions (or occasionally even older versions of GNU make). There is a convention to call such files GNUmakefile instead of Makefile, but this convention is widely ignored, especially on platforms like Linux where GNU make is the de facto standard make.
Telltale signs that a Makefile uses GNU make conventions are the use of := instead of = for variable assignments (though this is not exclusively a GNU feature) and a plethora of functions like $(shell ...), $(foreach ...), $(patsubst ...) etc.
So Which Do I Need?
Well, it really depends on what you are hoping to accomplish.
If the software you are hoping to build has a vcproj file or similar, you probably want to use that instead, and not try to use make at all.
In the general case, MinGW make is a Windows port of GNU make for Windows, It should generally cope with any Makefile you throw at it.
If you know the software was written to use nmake and you already have it installed, or it is easy for you to obtain, maybe go with that.
You should understand that if the software was not written for, or explicitly ported to, Windows, it is unlikely to compile without significant modifications. In this scenario, getting make to run is the least of your problems, and you will need a good understanding of the differences between the original platform and Windows to have a chance of pulling it off yourself.
In some more detail, if the Makefile contains Unix commands like grep or curl or yacc then your system needs to have those commands installed, too. But quite apart from that, C or C++ (or more generally, source code in any language) which was written for a different platform might simply not work - at all, or as expected (which is often worse) - on Windows.
First make sure you have MinGW installed.
From MinGW installation manager check if you have the mingw32-make package installed.
Check if you have added the MinGW bin folder to your PATH. type PATH in your command line and look for the folder. Or on windows 10 go to Control Panel\System and Security\System --> Advanced system settings --> Environment Variables --> System Variables find Path variable, select, Edit and check if it is there. If not just add it!
As explained here, create a new file in any of your PATH folders. For example create mingwstartup.bat in the MinGW bin folder. write the line doskey make=mingw32-make.exe inside, save and close it.
open Registry Editor by running regedit. As explained here in HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER go to \Software\Microsoft\Command Processor right click on the right panel New --> Expandable String Value and name it AutoRun. double click and enter the path to your .bat file as the Value data (e.g. "C:\MinGW\bin\mingwstartup.bat") the result should look like this:
now every time you open a new terminal make command will run the mingw32-make.exe. I hope it helps.
P.S. If you don't want to see the commands of the .bat file to be printed out to the terminal put #echo off at the top of the batch file.
If you already have MinGW installed in Windows 7, just simply do the following:
Make another copy of C:\MinGW\bin\mingw32-make.exe file in the same folder.
Rename the file name from mingw32-make.exe to make.exe.
Run make command again.
Tested working in my laptop for above steps.
For window-10 resolved error- make' is not recognized as an internal or external command.
Download MinGW - Minimalist GNU for Windows from here https://sourceforge.net/projects/mingw/
install it
While installation mark all basic setup packages like shown in image
Apply changes
After completion of installation
copy C:\MinGW\bin
paste in system variable
Open MyComputer properties and follow as shown in image
You may also need to install this
https://sourceforge.net/projects/gnuwin32/
As other answers already suggested, you must have MinGW installed. The additional part is to add the following two folders to the PATH environment variable.
C:\MinGW\bin
C:\MinGW\msys\1.0\bin
Obviously, adjust the path based on where you installed MinGW. Also, dont forget to open a new command line terminal.
'make' is a command for UNIX/Linux. Instead of it, use 'nmake' command in MS Windows. Or you'd better use an emulator like CYGWIN.
Search for make.exe using the search feature, when found, note down the absolute path to the file. You can do that by right-clicking on the filename in the search result and then properties, or open location folder (not sure of the exact wording, I'm not using an English locale).
When you open the command line console (cmd) instead of typing make, type the whole path and name, e.g. C:\Windows\System32\java (this is for java...).
Alternatively, if you don't want to provide the full path each time, then you have to possibilities:
make C:\Windows\System32\ the current working directory, using cd at cmd level.
add C:\Windows\System32\ to you PATH environment variable.
Refs:
use full path: http://technet.microsoft.com/en-us/magazine/ff678296.aspx
cd: http://technet.microsoft.com/en-us/library/cc731237.aspx
PATH: http://technet.microsoft.com/en-us/library/bb490963.aspx
I am using windows 8. I had the same problem. I added the path "C:\MinGW\bin" to system environment variable named 'path' then it worked. May be, you can try the same. Hope it'll help!
try download & run my bat code
======run 'cmd' as admin 2 use 'setx'=====
setx scoop "C:\Users%username%\scoop" /M
echo %scoop%
setx scoopApps "%scoop%\apps" /M
echo %scoopApps%
scoop install make
=======Phase 3: Create the makePath environment variable===
setx makePath "%scoopApps%/make" /M
echo %makePath%
setx makeBin "%makePath%/Bin" /M
echo %makeBin%
setx Path "%Path%;%makeBin%" /M
echo %Path%
use mingw32-make instead of cmake in windows

CMake-generated Makefile: "make <a target>" opens shell inside shell repeatedly

I open a cmd console, go to where the Makefile is and run "make help", for instance. Instead of listing the available targets, make seems to just run cmd inside cmd again and again for each target. I can go back by typing "exit", "exit", "exit", etc. until I'm back to my original cmd prompt. All other targets are rendered the same way.
I configured (using Cmake GUI) CMake to use MinGW tools, indicated the correct source and build dirs. Everything regarding environment seems ok per the tests performed by CMake.
Please, help, I have no clue of what is going on. That's very odd.
Here is the "help" target from the Makefile generated by Cmake (I edited out some #echoes during investigation). In this case, make opens three cmd prompts in tandem instead of printing the information in the #echo commands.
# Help Target
help:
#echo The following are some of the valid targets for this Makefile:
#echo ... all (the default if no target is provided)
#echo ... clean
.PHONY : help
Please ask any information you want. I didn't paste the entire Makefile or CMakeCache.txt because they are quite large. If you need them, please ask.
This is my CMakeLists.txt, it is quite simple:
#
cmake_minimum_required (VERSION 2.6)
project (HELLO)
add_library (mylib MainLibClass.cpp)
add_executable(myprogram main.cpp)
target_link_libraries(myprogram mylib)

Can't execute a batch file on post-build

I've read this discussion but despite different attempts, I get an error (it varies depending on my approach).
The compilation itself works fine. Double-clicking on the "publish.bat" files executes it just fine too. It's the combo in VS10 that breaks.
This is what I've tested.
$(OutDir)\publish.bat
"$(OutDir)\publish.bat"
$(OutDir)publish.bat
"$(OutDir)publish.bat"
call $(OutDir)\publish.bat
call "$(OutDir)\publish.bat"
call $(OutDir)publish.bat
call "$(OutDir)publish.bat"
What am I missing?
I had a similar problem that I was just able to fix. For me the simple call "$(SolutionDir)\Setup\CreateInstaller.bat" worked, but I kept getting a The command "call {solution directory}\Setup\CreateInstaller.bat" exited with code {code}. Turns out my batch file was expecting to be run from the directory in which it lived. So, check that all the commands in the batch file are not using relative directories or commands as these may break.
Also, are you sure the $(OutDir) macro is what you want? In VS2010 at least, that is just equal to bin\Debug or bin\Release depending on which version you're building in. It seems unlikely that you really want that directory. I expect what you want is $(SolutionDir) or perhaps even $(TargetDir).

Cygwin GCC + WinXP cmd.exe does nothing

My basic problem is that if I run GCC from the windows command line (cmd.exe in Windows XP) and it does nothing: no .o files are created, no error messages, nothing. It will only throw an error message if I use DOS-style paths, but nothing else. When I run from the Cygwin shell then it will throws error messages as appropriate for the errors in the source and produces the .o files as it needs. Using 'make' from the DOS command line doesn't work either. Has anyone encountered this behavior before?
I've actually made some progress on this. Background:
I have WinAVR installed and its bin directories set in my PATH. WinAVR is GCC and associated development utilities but for the AVR 8-bit microcontroller. It shares many utility names with regular GCC.
In the past I remember Cygwin putting its bin directories in the PATH. It didn't seem to do this this time, so I put 'C:\cygwin\bin' into the PATH and then later 'C:\cygwin\usr\bin' there as well.
The latest release of Cygwin has issues with the way it handles files. Basically, gcc.exe is not an executable, but a type of symlink to the actual executable (which is either gcc-3.exe or gcc-4.exe depending on what you have installed). In the BASH shell these symlinks are easily resolved, in cmd.exe they are not. This means that if you attempt to enter 'gcc' into cmd.exe as a command it will respond 'Access is denied'. The solution for that is to call the actual GCC file name (gcc-4) instead of the symlink.
The solution seems to have come by rearranging my PATH. To edit the PATH environment variable, right click on 'My Computer' and go to properties, then Advanced and then Environment Variables. Under 'System Variables' find 'Path' and double click it to edit. Remove all entries that have C:\cygwin in them and then go to the FRONT of the PATH and enter them there. For me it was C:\cygwin\bin and C:\cygwin\usr\bin. The important part for me was making sure that the Cygwin entries were before the WinAVR entries. I noticed that when I tried to call 'make' in cmd.exe it was calling the WinAVR version instead of the Cygwin version. This lead me to rearrange my path and after some fooling around it became clear that using gcc-4 from the cmd.exe shell was working. It then worked in Code::Blocks as well and I was off.
Alternatively, it might have just fixed itself from something else entirely. Computers have a way of doing that.
Alternatively you can delete file: gcc.exe which is a file link and rename
the actual gcc executable file: gcc-3.exe (or gcc-4.exe depends on your version) to gcc.exe

Resources