guide to mingw make files mingw32-make - c++

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.

Related

Using system() cross platform. Compiling with cygwin and g++

I'm using cygwin and g++ under Windows 7 to compile my project. I've made a makefile to compile the project under Ubuntu. This is all working so far.
A function calls the Libre Office to convert some files. For this purpose i pass a command string to system().
Symptom
When I use the executable generated with cygwin a error occurs:
sh: C:\..\LibreOffice 3.6\program\soffice --headless --convert-to png:'draw_png_Export' add1.fodg : command not found
What irritates me is the fact, that it seems the command is passed to sh and not cmd
How can I make sure the executable build for Windows uses no sh?
I think you have two options.
First, stick with sh used by system() and use the path to LibreOffice in POSIX format.
C:\..\LibreOffice 3.6\program\soffice
will become
/cygdrive/c/../LibreOffice 3.6/program/soffice
You can also use the cygpath utility for this, as well.
The other option is to call LibreOffice via cmd:
cmd /c C:\..\LibreOffice 3.6\program\soffice args...

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.

Asterisk cross platform compilation

I am trying to compile asterisk from windows using netbeans c/c++ IDE. As i want to add some functionality into the existing code.
when i am running the configure file i got the following errors
cygwin warning:
MS-DOS style path detected: .\configure
Preferred POSIX equivalent is: ./configure
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
configure: error: cannot run /bin/sh ./config.sub
I am very new to cross platform development. Please help me to solve this
The first part seems just to say, that you should call configure not as .\configure but as ./configure. The last line is the real error. As it says it can't run /bin/sh ./config.sub you should check that both files are correct and existent.
Do ls -l ./config.sub to see if the file exists and is readable by your user and file ./config.sub to ensure it is a shell script.
If config.sub seems correct, do
ls -l /bin/sh
to make sure, that the interpreter exists and is executable.

Invoking MSYS bash from Windows cmd

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"

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.