How to add MinGW to PATH? - c++

I'm following this tutorial by vscode to install a C++ compiler on Windows. Right now, I'm trying to edit C:\msys64\mingw64\bin to environment variables and save MinGW to path. I clicked OK multiple times but seems like it can't save. I also entered g++ --version and gdb --version to check for installation. It just shows "'g++' is not recognized as an internal or external command,
operable program or batch file."

If reinstalling MinGW doesn't work, add MinGW to PATH manually by this:
Find your computer's property, and then go to Advanced.
Click Alt+N
Find PATH in the box below.
Add the path of your MinGW compiler to it.
Note: Add the BIN folder.
If adding the BIN folder doesn't work, add the BIN folder in the folder under C:\msys64\mingw64 that has a long name like this:
x86_64-w64-mingw32
or whatever your folder is named.
IMPORTANT NOTE: REMEMBER TO RESTART YOUR COMPUTER AFTER DOING THIS.

Related

How to find PATH variable of installed MinGW GCC compiler?

Just recently I installed Ubuntu and with it: Eclipse Version: Luna Service Release 2 (4.4.2) Build id: 20150219-0600. I've installed the MinGW GCC compiler via the command line option Ubuntu provides for my 64-bit system.
sudo apt-get install mingw-w64
When I made my project, Eclipse started to whine. It kept saying Toolchain "MinGW GCC" is not detected. It, however, does still find errors in my code. No errors are produced about it not being able to find the path of g++ or gcc, though. So I was searching Google and many sources said I would need to set the PATH variable of my installation. However I cannot find the installation path of MinGW-w64. How can I find what this path should be in Ubuntu 14.04 and set the path variable that needs to be set.
Additioanl information:
-At the end of this path Window->Preferences->C/C++->Build->Settings->Discovery->CDT GCC Built-in Compiler Settings has the command to get compiler specs as ${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"
-At the end of this path Window->Preferences->C/C++->Build->Environment has no Environment variables set at all, including the PATH variable.
-Under the following Project Properties->C/C++ Build both check marks are chosen.
->Build Variables is empty.
->Environment has the value of MINGW_HOME as /usr. The value of MSYS_HOME is blank. The value of PATH is ${MINGW_HOME}/bin:${MSYS_HOME}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games.
->Tool Chain Editor has the check mark set to display compatible toolchains only, yet it seems to not have any effect on the which toolchain I can select in the following drop down menu. My current toolchain is set to MinGW GCC and my current builder is set to Gnu Make Builder
So again, my question is what gives? Why can't eclipse see the complier that I installed to my copy of Ubuntu? And how can I not only set my PATH variable, but I also must need to know what to set it to because I don't know where the terminal installed the /bin directory of mingw-w64?
First you need to understand mingw is a win32 port of the original GNU compiler. So, if you're already in Linux, you preferably will use this latter.
Now, you need to figure out if your system's shell recognizes it, so try tab autocompletion in the shell, wether its mingw or gcc, open up a terminal and type min and then hit Tab.
In case Tab autocompletion worked and you want to know where the command is located, you can use whereis [comand] and shell will return the path from where its running.
If nothing happens, then it's not in your PATH.
PATH is defined primarily in three configuration files: local PATH is in ~/.bashrc and ~/.bash_profile, and system PATH is defined in /etc/environment and /etc/profile but normally you wouldn't need to mess up with there two.
To find or locate anything in your system you can use find.
Normally, in every linux system, all binaries you install end up in /usr/bin,
/bin,
/usr/local/bin
or sometimes in /opt but that one is reserved in case its a third party vendor.
At this point you can do a search like find /usr/bin -name mingw taking the first argument as the path to search within OR you could search directly into your environment variables with env.
If you need to add something to the path I recommend you to create a symbolic link of your binary(no matter where its located) in /usr/bin and then, add that link to your local PATH, that is to say, something like this:
ln -S /opt/file.bin /usr/bin/myBin
echo "export PATH=$PATH:/usr/bin/myBin" >> ~/.profile
Normally after installing gcc eclipse should automatically detect it, but if not, you can set MINGW_HOME with the same code as above, just omit the symbolic link step and set the variable first as follows:
MINGW_HOME=/Path/found/of/mingw/or/gcc
I hope this explanation will help you, if not, feel free to share your thoughts.

GDB not a recognized command - Windows command prompt

I am trying to use GDB to debug a C++ program, but my system is not recognizing gdb as a command. I installed it, along with many other tools, via MinGW. I have not had any problem with the other features I have used (gcc, g++), so the issue doesn't seem to be with my general set up. I have added the MinGW\bin directory to my PATH. The gdb.exe is in that folder. But it will not run when invoked from my project directory, it simply errors: "'gdb' is not recognized as an internal or external command, operable program, or batch file." Is there some step in setup or invocation that I missed for using GDB?
EDIT: Alright, I think I found the problem: there are two MinGW directories in my PATH, one at C:\MinGW, and another in folder that got installed with some Haskell compilers I used a while ago. It appears to be defaulting to the Haskell folder, perhaps because this directory is listed first. However, this folder contains gcc and g++, but NOT gdb. I was able to get the gdb command working by creating the fstab file in the msys directory, a step I apparently forgot when setting up MinGW. I added my C:\MinGW directory to it, and now the gdb command is working properly! Out of curiosity, what does this file do?
Also, ideally I would like it to look in the C:\MinGW directory first, since this is the folder I plan to keep updated, and the one that contains ALL of the various applications. However, the Haskell directory is specified via the system PATH variable, which I've read it's not a good idea to touch. Would switching the order that they appear even fix my problem?
EDIT 2: Not 100% sure what happened, but the gdb command appears to be working now. I have always been using the Windows cmd prompt to run these tools, so per the answer below (that I should not need to mess with msys) I deleted the fstab file, and lo, it still works! However, my second question above still stands: What is the best way to get the compilers to run out of C:\MinGW\bin instead of C:\Program Files (x86)\Haskell Platform\2013.2.0.0\bin? Is moving the Haskell location out of the system PATH and to the end of the user PATH a viable option?
I had to run pacman -S mingw-w64-x86_64-gdb separately and then gdb showed up in the bin.
You do not have to run gdb (or gcc and all other MinGW tools for that matter) within msys - it is not like Cygwin in that respect. Had you run it from the Windows cmd console, it should work.
The msys shell is useful for running configure scripts generated by Autoconf used by many Linux originated open source projects, but its environment is independent of the Windows environment.

Qt unit-test: why "qmake" is not recognized

I managed to follow this tutorial in order to write my first unit-test.
However, when opening a "cmd-console" from inside my project folder and try to rum qmake, i get the following error:
'qmake' is not recognized as an internal or external command, operable program or batch file.
so, why qmake is not recognized? (note that I am working on windows Vita)
On Windows qt and its tools are installed by default in C:\Qt\blablah. You should add the path to the qmake binary, and that will do the trick. See the instructions here. Note that Qt creator set some variables for its terminal so you use qmake in creator without touching the system.
set path the Qt compiler.
sth like this:
set PATH=C:\Qt\4.8.5\bin
where the 4.8.5 is the version of Qt you installed.
If you don't want to add the QT bin path to PATH you can write the full path to qmake:
>"$(QTDIR)\bin\qmake.exe" -o Makefile odbc.pro
where $(QTDIR) is the full path of the qtbase directory.

Eclipse CDT build error: make not in path

I just recently(actually today) started using Eclipse CDT for windows. Created a project, a test C file(Hello World) added to project. Build the project, I got error as below.
Error: Program make is not found in Path -
So then I read that Eclipse CDT needs Mingw/MSYS, which I did install. Now i See that there is make.exe in
C:\MinGW\msys\1.0\bin
But Since I dont have administrator privileges, I could not add this folder containing make to the Path system variable on Windows. (I am not likely to get administrator privileges)
Now how do I work around this error to build and use CDT on windows? Any Project settings for Eclipse CDT which if added the path to make could help resolve this?
Was able to get a fix around this problem.
Added the correct paths for two exes - make and gcc/g++ (installed by Mingw/Ansys) to the User environment variable Path (Was not allowed to edit System variable Path).
But adding these paths to User environment variable Path also helped to resolve this. Now Eclipse CDT built and executed the code fine.
check environment variable path has c:/cygwin/bin or c:/mingw/bin or wherever u installed it
if makefile name is mingw32-make.exe or something else , make a copy and rename that to make.exe
The problem is simply that your IDE need to know where is the place of GNU Binary Utilities so how to deal with that simple go to
Windows -> preference -> C/C++ -> new c++ project wizerd -> makefile
then chose what are u instal for example I use MinGW so now I will chose GUN elf parse and now I need the location for c++ filt :D
you will go to place where u install minGW in default it will be C:\MinGW
and search for c++ filt.exe :D and now u done :D
and you can install minGW from
http://www.mingw.org/
Also after adding C:\MinGW\bin to PATH variable. Make sure your new project is created with MinGW GCC toolchain as shown below.

Eclipse-CDT: Automatic Path Discovery when cross-compiling for Linux under Windows

I'm using Eclipse-CDT to develop and compile projects for Linux. As host both Linux or Windows may be used.
The project is created as Makefile project with a special build command, so I changed the build-command from make to our special one and the "Build" and "Clean" commandline approbriately. The build command uses a gcc from a directory not in $PATH, because the whole compiler-suite is located in the version control system. (Correct $PATH is set by the build command.)
This works fine under Linux: Eclipse learns the Symbols and Include Files automatically.
However, under Windows the Symbols are recognized, but the Include Paths aren't.
When I have a look in the generated MyProject.sc file in the workspace/.metadata/.plugins/org.eclipse.cdt.make.core directory, I see that the Include-Files are recognized, but prepended with a C:\cygwin.
The GCC command line uses absolute paths without the Drive letter.
(The whole source tree is located on a special Drive (e.g. W:), CWD is on this drive ).
E.g. gcc/g++ is invoked with -I /net_libs/lib1/inc and Eclipse recognizes C:\cygwin\net_libs\lib1\inc.
BTW: The standard-include paths are recognized correctly (e.g. W:/toolchain/win32/i686-pc-linux-gnu/include/c++/4.2.1).
The Build-Directory is set to the directory of the Makefile which is on the same Drive as the Sources and Includes.
I tried various "Toolchain" settings (Cygwin, MinGw, Linux gcc), the result is same every time. (After changing the settings, I even stopped Eclipse, deleted the sc file and started Eclipse again).
I don't know why Eclipse knows about my Cygwin installation in C:\Cygwin - the installation is NOT used by the compiler or related tools.
When I change the .sc file manually and correct the paths and restart Eclipse, everything works fine.
Do you have any hints what may be the problem?
Have a look at Project->Propterties->C/C++ Build->Discovery Options.
There is a Compiler invocation command - usually set to gcc, which means "gcc in PATH". Try setting this to your gcc from your build system.