MinGW ís not working - c++

I installed the C++ compiler MinGW following this tutorial, but when i used the consol commands:
> gcc --version
g++ (GCC) 4.8.1
......
> g++ --version
g++ (GCC) 4.8.1
......
> gdb --version
GNU gdb (GDB) 7.6.1
i dont receive any information and the console prints 'gcc is not recognizable as internal or external command'

When you execute step 3:
Setup environment variable PATH to include "<MINGW_HOME>/bin" where <MINGW_HOME> is the MinGW installed directory that you have chosen in the previous step.
Be aware that changes made to your path in the control panel don't affect existing consoles.
You need to open up a new console for the path to affect it.
The other possibility is that you've modified the path in a console you were working in but this is the wrong way to do it, since that path will not affect future consoles.

You most likely missed this step:
Setup environment variable PATH to include "<MINGW_HOME>/bin" where <MINGW_HOME> is the MinGW installed directory that you have chosen in the previous step.
What is the output of this command?
echo $PATH
If it does not include "<MINGW_HOME>/bin", you need to make the necessary adjustment.
Besides, that tutorial is somewhat dated. Cygwin Ports does include packages for MinGW, plus precompiled libraries, available from Cygwin's setup.exe. The packages are:
mingw64-i686-gcc
mingw64-i686-gcc-g++
or
mingw64-x86-gcc
mingw64-x86-gcc-g++
depending on your architecture. If you use those packages, the compiler will be installed in /usr/bin (which already is in your PATH), and you can access it (e.g. as i686-w64-mingw32-gcc) right away.

Related

How do I set path to respective bin of the mingw directory

I'm trying to use C++ in VSCode, and I found a tutorial where I install g++ and clang to make it work.
I installed g++ fine, and added it to my list of environment variables, but then the instructions for installing clang say to "set path to respective bin of the mingw directory" without showing me how.
What does this mean and how do I do that?
Also, #include <iostream> looks like it doesn't work either, it says the file is not found, so I'm wondering if it's because clang isn't installed or something else I need to fix. Thanks!
Ok, I've skimmed that tutorial video and YouTube comment section. Basically I think it's a poor tutorial, as it doesn't explain the basics, and that's why you're getting tripped up. My first recommendation is to save yourself some trouble and follow the VSCode Getting Started with C++ Tutorial instead.
Not only is the official tutorial easier to understand, it will guide you toward using the Microsoft C++ extension that almost everyone uses (and can help you with), rather than the comparatively obscure Clang-based C++ extension.
But that's not answer to your actual question. You asked:
... the instructions for installing clang say to "set path to respective bin of the mingw directory" without showing me how.
What does this mean and how do I do that?
I'm not sure! It's sort of nonsensical. But I think what is meant is:
Install mingw GCC and put its bin directory on the PATH.
Install LLVM+Clang and put its bin directory on the PATH.
Start VSCode from a shell where both are on the PATH.
Then proceed with the linked tutorial.
You say you already have mingw GCC on your path, but let's check that. At the command prompt (I assume you are using the default Windows cmd.exe shell), run:
> gcc --version
gcc (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
If you don't see output like that, then something is wrong. Make sure the bin directory of mingw GCC, which contains gcc.exe, is on your PATH.
Next, Clang. Clang is part of LLVM. Wherever you installed LLVM, there should be a bin directory inside it containing clang.exe. Add that to your PATH. In my case, I installed LLVM into d:\opt\llvm-8.0.1, so I would run:
> set PATH=%PATH%;d:\opt\llvm-8.0.1\bin
Then check that it is working:
> clang --version
clang version 8.0.1 (tags/RELEASE_801/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: D:\opt\llvm-8.0.1\bin
Once both gcc --version and clang --version respond similarly to what I have shown, you're ready to start VSCode:
> code
and from there, the tutorial's instructions should work.
I faced a similar issue a while back. Go to the installation directory of mingw/bin. copy this path and add it to the environment variable PATH to your Windows system, save it. Relaunch vscode and then try pressing ctrl + ` and execute code using g++. This way gdb will also work.

MinGW path set but not being found at Powershell

I just started learning C++ in class, and I have trouble setting up the built environment.
Our class uses MinGW and VS code for default building environment, so I followed the class guideline to install necessary MinGW libraries and added the directory of MinGW bin folder to environment variables(path).
So it worked well for the first time, but after reboot VS code cannot find gcc and g++. Typing gcc --version and g++ --version at cmd works well; it shows version info. However, typing that in Powershell(which VS code uses) does not work anymore.
I'm totally new to C++ and related environment, so I definitely have to fix this trouble. Thanks for your help in advance.
Try to add a system environment variable, and the var name is "g++" with the value "C:\MinGW\bin\g++.exe"(replace this path with your g++.exe file path).Maybe you should restart your computer to apply this operation if the windows OS version is windows 10.

How to install gcc-arm-none-eabi for MinGW users?

I am interested in taking my C++ program and cross compiling it into something that can run on an ARM MCU. To do this, I am required to have gcc-arm-none-eabi installed. I'm currently on a Windows 7 machine, and so I have installed GCC/make/g++/etc. via MinGW.
From the research I've done, it seems that MinGW does not support this toolchain, which leads me to believe that Windows-based ARM development isn't possible. So I ask: how does one use MinGW to install the gcc-arm-none-eabi toolchain locally?
You can use MinGW for this; you just need to swap out the C++ toolchain for your chosen one. You can still invoke it from the MSYS console, and all your other tools will still work. There's nothing inherent to MinGW or MSYS that makes this "not supported".
Personally I install GCC 4.9 gcc-arm-none-eabi from launchpad.net, mount the toolchain's directory in MSYS then export the paths I need:
mount 'C:\PROGRA~2\GNUTOO~1\4947E~1.920' /foo
mount 'C:\PROGRA~2\GNUTOO~1\4947E~1.920\ARM-NO~1' /foo_local
To discover the short name for the paths, write dir /X at the Windows command prompt. On my machine, the paths above are equivalent to the following, respectively:
C:\Program Files (x86)\GNU Tools ARM Embedded\4.9 2014q4
C:\Program Files (x86)\GNU Tools ARM Embedded\4.9 2014q4\arm-none-eabi
The mounting only needs to be done once; the export directives may be added to /etc/profile:
export CPPFLAGS="-I/foo_local/include"
export CFLAGS="-I/foo_local/include"
export CXXFLAGS="-I/foo_local/include"
export LDFLAGS="-L/foo_local/lib -mthreads"
export PATH=".:/foo_local/bin:/foo/bin:/bin:/opt/bin"
Then just run g++.
Or of course you can skip all the export business and just invoke your chosen GCC directly:
/foo/bin/g++
If you're using MSYS2, MinGW compliance, you'll be able to install arm-none-eabi-gcc through pacman
You can download it from here: https://www.msys2.org
Follow the instructions to properly setup the environments.
Then use this commands below
pacman -S mingw-w64-x86_64-arm-none-eabi-gcc mingw-w64-x86_64-libwinpthread-git
now you'll also need to add this into PATH,
echo "export PATH=$PATH:/mingw64/bin" >> ~/.bashrc
source ~/.bashrc
Then, you can now call arm-none-eabi-gcc with the MSYS2 shell.
See here for the details of this package https://packages.msys2.org/group/mingw-w64-x86_64-arm-none-eabi-toolchain
ELLCC is another option. You don't necessarily need mingw or mingw-64 installed to run it since it is statically linked. This post talks about using it to target Windows, but the same binary can also be used to target ARM and other processors. It's based on clang/LLVM though, not gcc.

Integrate GCC 4.4 with NetBeans on a Mac

I've got NetBeans 6.9 installed on a Mac OS Snow Leopard. Also, I installed gcc 4.4 through MacPorts in order to experiment with C++0x. I believe, by default NetBeans uses the standard Apple gcc 4.2 compiler which is invoked through a g++ symlink found in /usr/bin.
My question is: how can I still use the new compiler?
I tried creating a new Tool Collection in NetBeans by specifying the default directory to /opt/local/bin which is where gcc 4.4 is present. But this caused error messages, i.e. No compiler sets were found.... I also tried modifying the existing GNU Tool Collection by selectively specifying the C++ Compiler command as /opt/local/bin/x86_64-apple-darwin10-g++-mp-4.4. However, this caused build errors which I didn't even understand. Any ideas appreciated.
What you describe here, adding a new tools chain with that path, just should work with gcc 4.4, see here http://forums.netbeans.org/post-70004.html
Are you sure nothing is missing in your GCC 4.4 ?
The only missing step is to click "Reset Settings" help in Code Assistance tab after creating the tool chain, to make sure that code assistance picks the new headers.
This works for me:
Create a directory for your toolchain:
mkdir -p ~/toolchains/gcc-4.4-mp/bin
then link gcc's binaries into the bin directory
cd ~/toolchains/gcc-4.4-mp/bin
ln -fs /opt/local/bin/*-mp-4.4
and give gcc's tools their unmodified names back:
for x in *-mp-4.4 ; do ln -fs $x ${x%-mp*} ; done
or
for x in *-mp-4.4 ; do mv $x ${x%-mp*} ; done
Now you can add ~/toolchains/gcc-4.4-mp/bin as a new Toolchain Collection.
Here's the "easiest" solution. Edit your PATH environment variable and then open NetBeans.
sudo port install gcc_select
sudo gcc_select mp-gcc44
# tcsh:
setenv PATH /opt/local/bin:${PATH}
# bash:
PATH=/opt/local/bin:${PATH}; export PATH
# And then:
open /Applications/NetBeans.app
You should be good to go after that unless NetBeans (uses an absolute path to the compiler).

Adding gdb to MinGW

I've gone to http://sourceforge.net/project/showfiles.php?group_id=2435, downloaded the Automated MinGW Installer for MinGW 5.1.4 and at the same time the GNU Source-Level Debugger Release Candidate: GDB 6.8-3. I've then installed MinGW base tools into C:\MinGW. No problem so far.
However when I come to install the gdb debugger it has a lot of files and folders with the same names as some already installed but the files are different to those already installed. e.g C:\MinGW\include\bfd.h is 171 KB but gdb-6.8-mingw-3\include\bfd.h is 184 KB.
How do I add gdb to MinGW without breaking what's already installed?
In a command prompt I browsed to C:\MinGW\bin and ran:
mingw-get.exe install gdb
That fixed it for me. Not sure if it matters but I have C:\MinGW\bin in my path (guess I probably didn't need to browse to C:\MinGW\bin).
The Current Release (5.2.1) version of gdb at the project files page has always worked for me. The download is a stand-alone .exe, you don't need anything else.
But I'll bet the .exe in the 6.8 package will work, too. I'd try using just the .exe, and then if there are problems, try extracting the other files from the 6.8 package. (Though that may cause problems with the rest of the MinGW installation.)
Update: There seems to be a 7.something version. I haven't tested it thoroughly, but it seems to work, even with gcc 3.
Get Wascana Desktop Developer. It combines MinGW, gcc, Eclipse and gdb in one package.
You can safely overwrite the files prepackaged with MinGW with the (newer) ones from the gdb tarball. You can also choose not to overwrite them - just make sure to pick either one set, i.e. avoid mixing files from the older and the newer package.
Most of the offending files are probably not really relevant to you anyway. For example, the files belonging to the libbfd library aren't required for gdb's day to day operation, they're used if you want to extend the debugger or write debugging tools yourself.
At any rate, make a backup of the mingw directory before untarring the new release. It's very easy since MinGW is self-contained in that directory. That way, if anything should malfunction, you can just delete the directory and restore from the backup.
Usually for installing gdb in windows, You have to 2 ways to install:
1) use ready-made binaries that were build and compiled from GNU gdb by some provider (easy to install)
use TDM-GCC binaries provided from the following URL and that is including inturn the gcc complier and also gdb debugger.
http://tdm-gcc.tdragon.net/
use Equation package inside which GNU GDB was already compiled and built.
http://www.equation.com/servlet/equation.cmd?fa=gdb
2) use minimal mingw or cygwin package then after install gdb inside it.
Install either mingw or cygwin inside which GDB is already shipped
Open cygwin or mingw terminal and just type the following to make sure it is already installed
$ gdb --version
Hint: if you did not find gdb installed, simply open the cygwin or mingw package installer and make sure you already check gdb
Hint: getting and installing a debug build of the OHRRPGCE is providing useful information about crashes.
From cygwin or mingw terminal, Start gdb using the following
c:\mingw\bin\gdb.exe program_to_debug.exe
REF: http://rpg.hamsterrepublic.com/ohrrpgce/GDB_on_Windows
The TDM GCC/MinGW32 builds installer includes gdb. It's gcc 4.4.x with all the core binary packages required for basic Windows development, and is widely used without any unusual problems.