Invoking MSYS bash from Windows cmd - c++

I'm using GCC on Windows 7 (using the TDM's build). I installed MSYS to be able to execute Make and compile using makefiles. However, it is tedious to every time start up the MSYS Bash shell, navigate to the directory of the project and run make.
What I want is to automate this process. I prefer to have a batch file in Windows, or something similar, from which I then invoke the MSYS Bash shell. It should navigate to the directory the batch file resides in and call make.
Is this possible? Can I send commands to MSYS Bash from cmd (like navigation/invoking make)? Or can I let the MSYS Bash run a "Bash script", which sets the commands to be executed much like batch scripts?
PS: This is something similar to Stack Overflow question Executing MSYS from cmd.exe with arguments.

Not an MSYS expert, but does something like this work for you:
rem Call this something like compile-project.bat
c:
cd \src\project
bash -c "make"

You don't have to use bash to execute make, or any of the other MSYS programs. If you put the MSYS bin directory on your path, you can execute them from a Windows command shell. Alternatively, the bash shell has an enormously powerful scripting language built in. But I'm not clear if that's what you are asking about - you should clarify your question with an actual example of what you want to do, spelling out the steps you want automated.
My own setup is to have a Windows Explorer context menu called "Bash here" which opens a bash shell in the directory I select. This is done via the following registry entries:
[HKEY_CLASSES_ROOT\Directory\shell\mybash]
#="Bash Here"
[HKEY_CLASSES_ROOT\Directory\shell\mybash\command]
#="cmd /c c:\\bash.cmd %1"
And the following bash.cmd file in c::
#echo off
title bash
cd %1%
bash
Note that the MSYS bin directory is on my path. And of course, any registry hacking is at your own risk.

Just add executables to your Windows PATH:
C:\msys64\mingw64\bin
C:\msys64\usr\bin
Keep in mind, this adds a lot of executables to your path which might conflict with other applications. The ..\usr\bin directory contains all installed MSYS2 packages. There is a lot of unnecessary stuff. ..mingw64\bin directory has a smaller list.
Source

On my MSYS-1.0.11 with the MSYS developers packages, I can call a bash script (CurrentScript.sh) with a cmd/bat file in the current folder with this command:
R:\MinGW\MSYS-1.0.11\bin\sh "%cd%\CurrentScript.sh"

Related

How to make project from github [duplicate]

This question already has answers here:
How to install and use "make" in Windows?
(14 answers)
Closed 2 years ago.
I am downloading a library from the github
/////////////////////
https://github.com/ossrs/srs
///////////////////////////
The steps which i follow are
Create a folder
Run power shell and point to the folder
Git clone the source
The issue i am facing is the Make command in the step 2 of installation
The power shell does not accept the make command , so how do i make the source.
Make is an UNIX command for the UNIX make utility. To compile it on Windows, you can use Visual Studio, by running the Developer Command Prompt for VS, and using Microsoft's version of this tool - nmake: nmake -f Makefile
However, it looks like the configure script in /src of the package can only run on UNIX, so if you want to build this package yourself, it will be easier to use the Windows Subsystem for Linux, which will let you run a Linux environment that supports the commands in the configure file as well as the Make set up.
Method 1:
You can try git clone using the https address of your repository
git clone https://github.com/ossrs/srs.git
This will add a folder to the directory where you did git clone
Method 2:
Download Zip from git repository as shown in the image above
Unzip the files and add it to your project.
You can simply click on the green Code button, then Download ZIP instead of using powershell and git.

Test a shell (.sh) file in CLion

I am using Clion and I am unsure how to run a .sh file with my code. It is for an assignment, and I have to run an automatic test to test my code.
This is how it is described to be called: $ ./test_p2.sh 2
I have the shell file in the folder with my code, But I cannot see it in executable or working directory.
Any help is appreciated! Thanks
You can't directly run Linux shell scripts on Windows. You do have a few options, however:
Run your script through Cygwin
Run your script in mintty (this is the shell included with Git for Windows, is called Git Bash in the context menu)
Run your script under WSL (Windows Subsystem for Linux)
Port the script to another language you can run on Windows
For 1 and 2, it'll be on you to make sure any dependencies for the script are available in either Cygwin or mintty.
For 3, after making sure WSL is set up you can run a single command under WSL: wsl script.sh arg1 arg2 argX.
I would recommend option 3 or 4. 3 may offer the best experience in terms of compatibility and ease of set up (without porting the script) as Cygwin and mintty can be a pain to set up dependencies in. Option 4 would be best though as long as you are well-versed in both PowerShell and shell scripts and can transpose the equivalent calls from one to the other.

guide to mingw make files mingw32-make

I'm a C++ programmer and have experience with GCC on Linux. I want to develop an application in Windows , so i need a full guide to mingw make files, variables and mingw32-make. Is there anybody who can introduce a resource for this?
mingw32-make is just a pre-built version of GNU make, so
http://www.gnu.org/software/make/manual/ should have all of the
information you need.
The main difference I came across is that mingw32-make will use windows PATH. So if you try to run it from git bash it won't behave quite like you expect it to (namely, it will invoke bat scripts when you don't expect it to, and shims also don't quite work).
Setting SHELL := /bin/bash or anything similar won't have any effect (which you can debug by running make -d), but you can still make it use bash instead of sh by setting SHELL := bash.exe. That's doesn't solve the windows PATH problem though.
What I did notice however is that if I additionally set .SHELLFLAGS := -euo pipefail -c then it suddenly behaves properly in git bash, as if it starts using Unix-like paths (would be great if someone could confirm / explain why exactly).
So I ended up with the following in my Makefile:
ifeq ($(OS),Windows_NT)
SHELL := bash.exe
else
SHELL := /usr/bin/env bash
endif
.SHELLFLAGS := -eo pipefail -c
With that setup it appears to behave normally in git bash, just like on Linux.

Getting mingw-get to install correctly - mingw/msys path missing plus more!

I'm running windows XP.
I have been following this tutorial and so downloading mingw-get-inst here.
I've done this a couple times and the last time I checked boes to install EVERYTHING including, but not limited to, gcc, g++, MSYS and the MinGW Compiling Suite. I told it to make a program menu shortcut, too.
I believe I have correctly added MinGW/bin to the Environment Settings' Path.
So I have the shortcut to the MSYS shell now. It goes to C:\MinGW\msys\1.0\msys.bat, but the whole msys directory does not exist!
There are tons of "packages" have been downloaded as far as I can tell ("mingw-get show" brings up a lot!), but it doesn't seem like any of it installed correctly.
Also, should I be able to use commands like "g++ foo.cpp -o foo.exe" from cmd.exe or only from the MSYS shell? Because I was unable to use cmd.exe.
Please help!
The MSYS and MinGW installation procedure is a nightmare, and has got worse over the years. If you just want the compiler suite (no UNIX tools like sed, grep), then I suggest you go to Twilight Dragon Media and download GCC from there. If you also want all the tools, including the Bash shell, the easiest way I've found to get them is to install Git for Windows (which you may want anyway), which includes them all. And if you want a C++ IDE that works well with GCC, take a look at Code::Blocks.
What is the result of running, at a cmd.exe prompt, the command echo %Path%? It should (given what you wrote about your system) include “C:\MinGW\bin”—does it?
What is the result of running dir C:\MinGW?
Note that mingw-get show shows details of available packages—those mingw-get knows how to download and install. The installer is a bit primitive, but has gotten better over the last year or so.
If you issue the command $ echo $PATH, you'll notice it contains /mingw/bin But the /mingw directory is unavailable. To mount it, edit the MSYS fstab, adding a line like C:\MinGW /mingw For details, see the MingW Getting Started guide, more specifically section "After Installing You Should..."
You only need to add MinGW/bin to the Windows' Environment Settings' Path if you plan to use MingW's executables outside of MSYS.

g++ not working on Windows command prompt. Cygwin installed

I have installed Eclipse and CDT (to use C/C++ in eclipse CDT is needed), as well as installing Cygwin so that I can compile my files.
In environment variables I've set Path to include the following: "C:\cygwin\bin;"
g++, make and GDC are all installed via Cygwin. I made sure of this by searching for them in the bin folder - they're all there.
If I enter "make" into the windows command prompt, this appears:
make: *** No targets specified and no makefile found. Stop.
If I enter "g++" or "gdc" into the windows command prompt, this appears (or similar):
'g++' is not recognized as an internal or external command,
operable program or batch file.
So, in other words make is working but the rest isn't..but they're in the same bin folder! Has got me completely confused.
If I attempt to open Cygwin Bash Shell, g++, make and GDC all work there.
However, I need it to work in the command prompt so that Eclipse is able to compile the programs I write in the IDE.
If you know why this is happening, please let me know.
I haven't used cygwin much, but my understanding is you have to use it from the cygwin bash shell.
if you need g++, make, etc, use mingw, with it, g++ works from the normal windows command line.
Here is what happened to me and how I fixed it.
My C:\cygwin\bin\g++.exe is a shortcut pointing to C:\etc\alternatives\g++.exe, which points back to C:\cygwin\bin\g++-3.exe.
Replacing g++ with g++-3 worked for me.
In C:\cygwin\bin see whether g++.exe is there. If not, the installation wasn't done properly and you may need to install again. That's what was my problem and it's resolved :)
Adding the cygwin paths to the Path variable worked for me (windows 8.1 64 bit):
Go to system properties and select advanced system properties
Go to environment variables and select Path in system variables, click edit
Add the Cygwin paths...
for 32 bit:
C:\Cygwin\bin;C:\Cygwin\usr\bin
for 64 bit:
C:\Cygwin64\bin;C:\Cygwin64\usr\bin
In the CMD window, try typing bash to start a bash shell in that window. If that doesn't work, then the cygwin bin directory is not on your path.
If it did work, enter type g++ and type make to see the paths that are being used for these commands. I'm pretty sure your problem is with your PATH variable.
You could install a Windows version of which to get some help in figuring out exactly which executables are being run.
Perhaps it's picking up 'make' from somewhere completely different, and your addition to %PATH% is not working.
Also verify it by typing echo %path% in the same command prompt window as you're seeing the problem in, just to make sure.