MinGW32-make path variable issue - c

I am trying to build a C project on Win10 and i am using MinGW32-make. Prior to build the build directories should be created, and this is where build breaks with following output:
mkdir build\f2803x
process_begin: CreateProcess(NULL, mkdir build\f2803x, ...) failed.
make (e=2): The system cannot find the file specified.
Makefile:64: recipe for target 'build\f2803x' failed
mingw32-make: *** [build\f2803x] Error 2
I've tried running the mkdir command from the command line and it runs successfuly, however when i try running mingw32-make it fails. I've been searcing the web and one answer to the similar question pointed out that PATH in for the Mingw32-make and PATH for the windows may not be the same, so i added echo path to the makefile and compared the output to echo %PATH% from the cmd. It appears that they are not the same. Mingw32-make has
/mingw64/bin:/usr/bin:/c/Users/user123/bin that is not stated anywhere in any of the windows environment variables. I've also searched the registry as a last resort, however this is not in registry either. Where can these additional paths come from, and is it even the issue of the path?

mkdir is not a program, it's a built-in command interpreted by cmd.exe.
You want:
cmd.exe /c mkdir build\f2803x

I've been chasing a similar problem. For me the error was due to a missing command (I didn't have a date command available). Check your path and make sure that your make can find the mkdir command. Also, make sure you are executing a *nix style mkdir, not the dos/windows mkdir.

Related

Using Git in Windows Subsystem for Linux through IntelliJ

I'm trying to set Git executable in IntelliJ to be the git installed in Windows Subsystem for Linux, I tried a few different ways, but always got some sort of error. Today I installed to Creators Update (Version 1703), reinstalled WSL and tried again, here's what I did:
I created a .bat script:
#echo off
C:\Windows\System32\bash.exe -c "git %*"
So when running it:
C:\Users\Limon\Desktop>bash.bat --version
git version 2.7.4
So then I tried to set this bat at the git executable in IntelliJ:
And it worked! But everything else fails, for example when I try to pull or branch in IntelliJ, I get:
Couldn't check the working tree for unmerged files because of an error.
'C:\Windows\System32\bash.exe' is not recognized as an internal or external command,
operable program or batch file.
Any ideas on how fix this? I don't really know anything about batch scripting. It works perfectly off command line.
I was looking for a way to use git on WSL Windows Subsystem for Linux through Webstorm or an IntelliJ idea software.
I tried KatoPue's solution, but I got the following error:
fatal: could not read log file 'C:/Program Files/Git/mnt/c/Users/Elies/AppData/Local/Temp/git-commit-msg-.txt': No such file or directory
I solved it by replacing the path when sending the command to WSL's git
Settings > Version Control > Git > Path to Git executable : path_to_wslgit.bat
wslgit.bat :
#echo off
setlocal enabledelayedexpansion
set command=%*
set find=C:\Users\%USERNAME%\AppData\Local\Temp\git-commit-msg-.txt
set replace=/mnt/c/Users/%USERNAME%/AppData/Local/Temp/git-commit-msg-.txt
call set command=%%command:!find!=!replace!%%
echo | C:\Windows\Sysnative\bash.exe -c 'git %command%'
Since WebStorm 2020.2 EAP it is possible.
Just add \\wsl$\YOUR-WSL-VERSION\usr\bin\git to the Path to Git executable:
To get your WSL VERSION type in a console wsl -l
In PyCharm 2018.1 I got various errors, when trying to settled up Git. I've to combine different approaches to make it run. Next code works for me:
#echo off
setlocal enabledelayedexpansion
set command=%*
If %PROCESSOR_ARCHITECTURE% == x86 (
echo | C:\Windows\sysnative\bash.exe -c 'git %command%'
) Else (
echo | bash.exe -c 'git %command%'
)
UPD:
Now is available integration with Git inside WSL through WSLGit wrapper. I've checket it out with PyCharm and it's work like a charm. Here is a link https://github.com/andy-5/wslgit
Change the double to single quotes.
You can log, what arguments are fed to your bat file
#echo off
#echo %*>> %~dp0log.txt
bash.exe -c 'git %*'
With that, i discovered i had some escaping problems.
FYI: With the Win10 creators update piping bash and spawning it from Windows programs works fine.
In PhpStorm (2017.2 EAP) I get error
Caused by: com.intellij.openapi.vcs.VcsException: 'bash.exe' is not recognized as an internal or external command, operable program or batch file.
For solution i change last line to
If %PROCESSOR_ARCHITECTURE% == x86 (
C:\Windows\sysnative\bash.exe -c 'git %command%'
) Else (
bash.exe -c 'git %command%'
)
For me this solution works:
File: git.bat
#echo off
setlocal enabledelayedexpansion
set command=%*
If %PROCESSOR_ARCHITECTURE% == x86 (
C:\Windows\sysnative\bash.exe -c 'git %command%'
) Else (
bash.exe -c 'git %command%'
)
As Gabrielizalo answered earlier, you need to use version 2020.2 and higher.
Go to Settings | Version Control | Git
Add \\wsl$\YOUR-WSL-VERSION\usr\bin\git to the Path to Git executable
Press Test
Please note, if you are using the WLinux distribution, you need to use the name Pengwin.
Even though the wsl -l command outputs the name as WLinux. Perhaps It will be fixed in future versions.
This is how it works for me \\wsl$\Pengwin\usr\bin\git.
If you are still having problems with Pengwin (WLinux). You need to reimport it as Pengwin.
Follow this instruction:
Restart your system.
Open PowerShell as administrator.
wsl --list. You will see a list of distributions, including WLinux (Default).
Make a backup with command wsl --export distro_name file_name.tar.
For example, wsl --export WLinux E:\backup.tar. It will take some time, as the distribution can reach several gigabytes.
Make sure the backup is complete, then remove the distribution from WSL with the command wsl --unregister WLinux.
Next, reimport the distribution with name Pengwin
wsl --import distro_name install_location file_name.tar, e.g.,
wsl --import Pengwin C:\Users\<USERNAME>\pengwin E:\backup.tar
Set the distribution as default wsl --setdefault Pengwin
To run default WSL distro as the specified user use wsl --user <Username>
Add \\wsl$\Pengwin\usr\bin\git to the Path to Git executable to your IDE, and press Test
Note, now when using pengwin in cmd, or from the Start menu, a new Pengwin instance will be installed. You can check this with the wsl --list command. The new instance will show up as WLinux. If you accidentally create a new instance, you can delete it with the command wsl --unregister WLinux.
For the convenience of using your distro, I strongly recommend installing a custom terminal. You can follow this guide How to setup a nice looking terminal with WSL in Windows 10.
Worked till PHPSTORM 2018.3 (or maybe a Windows Update changed some behavior regarding bash.exe). I am using Ubuntu 18.04 LTS. However, the path of my bash.exe changed - it is no longer in C:\Windows\Sysnative\bash.exe.
To get things working again I modified Elies Lou's wslgit.bat and set new path for bash.exe:
#echo off
setlocal enabledelayedexpansion
set command=%*
set find=C:\Users\%USERNAME%\AppData\Local\Temp\git-commit-msg-.txt
set replace=/mnt/c/Users/%USERNAME%/AppData/Local/Temp/git-commit-msg-.txt
call set command=%%command:!find!=!replace!%%
echo | C:\Windows\System32\bash.exe -c 'git %command%'
I updated the soultion to work with WSL2 with a network drive and PhpStorm 2019.2.
wsl_git.bat:
#echo off
setlocal enabledelayedexpansion
set command=%*
set find=C:\Users\%USERNAME%\AppData\Local\Temp\git-commit-msg-.txt
set replace=/mnt/c/Users/%USERNAME%/AppData/Local/Temp/git-commit-msg-.txt
call set command=%%command:!find!=!replace!%%
echo | wsl CURDIR="%cd%"; STR2=${CURDIR//\\//}; STR3=${STR2/U:/}; cd $STR3; git %command%
It replaces the path in command for git-commit-msg-.txt to be able to commit as it was mentioned in other answers.
With WSL2 I use the network drive: \\wsl$\<distro_name> -> U:\. My project has path on Windows: U:\home\roman\projects\experiments, but on Linux it is /home/roman/projects/experiments. PhpStorm uses path from Windows to work with git, so it is needed to change path which can be reachable in the Linux subsystem. To achieve this I replace slashes \ -> / (STR2) and remove drive name U: -> `` (STR3) then change current dir to this modified path.
Install your project file in the wsl file system , any way you'll need this iff you go docker ;p
Open your project from \wsl$
(if needed) Go to Settings > Version Control > Git > and simply clear the Path to Git executable
and this work so fine !

Can't run program after set path as environment variable

I have set a new environment variable pointing to msbuild.exe folder.
C:\temp\Test>echo %DOT_NET4%
C:\Windows\Microsoft.NET\Framework\v4.0.30319
Now, if I start a new cmd and run "msbuild.exe", the programs runs ok, but after running this simple bat, the program is not found anymore:
"C:\Program Files\TortoiseSVN\bin\svn.exe" checkout %CHECKOUT% %PATH%
cd %PATH%
nuget restore OpenText.sln
msbuild.exe OpenText.sln
msbuild not recognized as an internal or external command.
Thanks in advance
I am seeing the same thing as Joey in his comment. Your use of CD %PATH% is a red flag that indicates a problem.
PATH is a critical environment variable that contains a delimited list of folder paths where important executables are located. The command processor uses that list to locate programs when an external command is issued without the full path to the command.
If PATH is set correctly, then your command CD %PATH% cannot work. But I suspect you have some script that defines PATH to a specific folder, perhaps where nuget is located. In this case, your CD %PATH% command works, but now cmd.exe has no idea where msbuild.exe is located.
Moral of the story - don't ever use PATH for your own purposes. Pick some other variable name that is not reserved.
First things first, where are you setting the msbuild path? To resolve your issues, please check if you have followed this process:
Open your system control panel, check for advanced system settings.
Click on Environment variables and edit PATH
Add a semicolon followed by the msbuild path.
Open a new command prompt and check if it is working or not.
Please note if you set msbuild in one command prompt, it will not be available in another command prompt.
Another issue which I see when I look at your logic is, you are trying to cd to %PATH% which should be avoided, you are either resetting the Environment variable path to a new path and trying to cd to it or you will land up file name longer issues, please use another variable instead.
In the bat which you are invoking, add a condition at the root level, such that if msbuild is not found, basing on %ERRORLEVEL%, try adding msbuild to path again at batch level, so that you build will proceed.

wget not recognized as internal or external command

I am working on a program to auto update my game as I make new developments and add new patches. When I go to run the patch update it doesn't recognize wget as a internal or external command.
Game:
:Checkforupdates
cls
cd C:\AirlineSim\
echo Checking for Updates
wget "http://interversesoftware.weebly.com/uploads/4/8/5/8/48585729/aspatcher.bat"
if /i not exist "ASpatcher.bat" (echo Could not retrieve update file.) && pause
if exist "ASpatcher.bat" call "ASpatcher.bat"
if exist "ASpatcher.bat" del "ASpatcher.bat"
goto menu
More code above in the updater
Updater:
cd C:\Airlinesim
echo Updating...
echo.
if /i exist Airline_Simulator.bat" del Airline_Simulator.bat
wget "http://interversesoftware.weebly.com/uploads/4/8/5/8/48585729/airline_simulator.bat")
set version=2.0
wget is a third-party program that doesn't come bundled with Windows, so you need to explicitly install it in order to use it.
You can find (one of) the Windows versions here: http://gnuwin32.sourceforge.net/packages/wget.htm
You will need to add the path of the wget.exe file to your PATH environment variable in order to call the executable as in the batch file above without explicitly specifying the path.
For Windows 10: A good link is available here: https://builtvisible.com/download-your-website-with-wget/
I followed this tutorial-> (https://builtvisible.com/download-your-website-with-wget/) and it worked for me. Still, I will give an overview of that,
credit: Richard Baxter
for 64bit version download wget from here
move your wget.exe to the Windows directory, which is generally c:\Windows\System32.if you don't know then you can find that either using the $PATH command or by opening your cmd as an administrator and in which path it will open that will be your Windows directory. like this one ->
2.1. Check that you have copied that in a proper place or not, to do that restart your cmd/terminal then type wget -h. if it gives some output related to some commands and their utilities(basically what a help command does) then you are good to gođź‘Ť.
If you pass the above check, then go to your c:/ directory using cd .., then make a directory called wgetdown using md wgetdown. Now you are all set. use get how ever you want.
What this simply means is, wget isn’t installed in your windows machine or it is, but hasn’t been added to Windows environmental path.
If you don’t have wget installed, download it from here (32-bit) and here (64-bit).
Extract the files to a folder say C:\wget and then add the folder to Windows environmental path.
Go to C:\Program Files (x86)\GnuWin32\bin folder and check the .exe file name.
For me it was sid.exe so I'm using sid instead of Wget command
download wget.exe here after downloading, go to command prompt by typing 'cmd' in the search menu, open the cmd type 'path' then enter in the command prompt, you're going to move the downloaded wget.exe to C:\Windows\System32 folder. if its successful, close and open the command prompt and type 'wget -h' then enter you should see different available commands. You can now use 'md wgetdown' to create directory for your downloads
first you have to install wget
pip install wget
than in Jupiter notebook locally on Windows 10
!python -m wget
example
!python -m wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=1InzR1qylS3Air4IvpS9CoamqJ0r9bqQg' -O inception.py
You simply need to install wget from https://anaconda.org/menpo/wget here. I found my solution by installing it.
I had a similar issue, and I resolved it by using Windows PowerShell instead of Command Prompt
The answers about it not being available by default are absolutely correct. A few other notes related to installing wget - if you use a package manager, they may have it for you to install with.. e.g.:
$ choco install wget
$ composer require fawno/wget

Cygwin ssh - Identity file not accessible

I've been trying to make ssh connection using Cygwin, but it doesn't recognize my id_rsa public key file.
My command lines are as follows:
$ssh XXX#XXX -i /home/XXX/.ssh/id_rsa
Warning: Identity file /home/XXX/.ssh/id_rsa not accessible: No such file or directory.
Permission denied (publickey,XXX).
(Sorry, I used XXX for the private information.)
I copied my .pub file to C:\cygwin\home\XXX.ssh folder. But it still spits out the same error message.
Thank you so much in advance.
Background
Most cygwin executables, map Unix path /home/XXX/.ssh/id_rsa to Windows path C:\cygwin64\home\XXX\.ssh\id_rsa. Except that ssh.exe maps the same Unix path to Windows path C:\home\XXX\.ssh\id_rsa.
That is if you do cat ~/.ssh/id_rsa, it will print out the contents of C:\cygwin64\home\XXX\.ssh\id_rsa, but if you do ssh XXX#XXX -i /home/XXX/.ssh/id_rsa it will try to read the key from C:\home\XXX\.ssh\id_rsa.
I assume this is bug in Cygwin. In any event, this is a workaround that worked for me (on Windows 10 and the latest version of Cygwin as of October 2020).
Solution
Open Administrator command prompt. Go to C:\ and issue the command mklink /D home c:\cygwin64\home
That's it.
But for me tat least, once I solved the above problem, I started getting the problem described in this Superuser question https://superuser.com/questions/1296024/windows-ssh-permissions-for-private-key-are-too-open. I used the solution from the most upvoted answer and ssh finally worked for me.
From your post it looks like SSH is looking for /home/XXX/.ssh/id_rsa and is not finding it. Ensure that the .pub file you copied is named correctly and has the right permissions.
Try putting the option before the hostname...

Logging into Cygwin and executing commands using bat file in windows

I am using windows XP operating system and cygwin is installed in my C drive.
I need to login to cygwin directly to my directory path which contains a makefile and also a bash script called build.sh in the same directory. So i modified the original cygwin.bat file and added the line as shown below.
#echo off
C:
chdir C:\cygwin\bin
bash --login "/cygdrive/E/scheme_31july/build/build.sh"
When i double click on this bat file i could see my script executing but not on cygwin shell but on windows cmd shell as a result I get errors for "make" command like "No rule to make target" as make comes bundled with cygwin.
And when I explicitly login to cygwin using default cygwin.bat file and execute my script by giving following commands in cygwin shell the script executes without errors.
Basically I want to write a bat file so that I can keep it anywhere in my PC and instead of manually openeing the cygwin prompt and typing commands like:
$ cd /cygdrive/E/scheme_31july/build/
$ sh build.sh
it should happen automatically. I sit possible to do so.
Regards,
Harshit
No rule to make target sounds more like make being executed in the wrong directory. make itself seems to be available and running as intended.
Try this:
bash --login -c "cd /cygdrive/E/scheme_31july/build/ && sh build.sh"
This should start a --login session (which should give you access to all the settings and tools you'd expect in a cygwin prompt environment), then execute the given shell command, which is the cd and sh you asked for. You could also write those two lines to a separate script file, and pass the name of that to bash instead of the full path to build.sh.
You could also try to cd into C:\scheme_31july\build in the bat file and then execute bash from there. Not sure whether bash will try to change path upon entering the login session. You can try whether things work without the --login, both for this approach and the one above.
#echo off
C:
cd C:\scheme_31july\build
C:\cygwin\bin\bash.exe ./build.sh
I'm not sure whether you want the session to turn interactive after that or not. In the above case, bash will terminate after the script completed, and might even close the window. You might have to add a read into build.sh to avoid that. If you want bash to turn interactive after executing some command, you can try using the --rcfile option of bash to execute some commands and then turn interactive.

Resources