Not able to run C++ code on Windows 8.1 Pro

1

I have installed the g++ compiler on my PC at my work place, downloaded from https://osdn.net/projects/mingw/releases/ here. I've also set the system path variable, but when I try to compile my code in command prompt, it shows the message that g++ is not recognized as an internal command. I have Windows 10 on my home PC and I followed the exact process to install g++ and my code runs smoothly there, but I'm facing this issue on my working PC. Any help would be appreciated. Thank you.

Shashank Kadambri

Posted 2019-01-29T04:32:44.733

Reputation: 11

2What directory has g++ been installed to? Have you tried running the command line from that directory? I know you said you updated your path but I've had similar issues that was solved this way. – Jon – 2019-01-29T04:35:08.830

1I have installed g++ to C:\MinGW\bin, and I just noticed that if I paste my code file there and then through cmd access the bin folder and try to compile the code, it does perfectly. – Shashank Kadambri – 2019-01-29T07:49:12.500

Did you close and re-open your IDE or DOS box? In Window's, it won't pick up the new path until you re-launch it. Such things are assigned at process start & globally changing them afterwards does not affect currently running processes. – Mawg says reinstate Monica – 2019-01-29T08:03:54.907

1@Mawg I tried restarting my PC, but it didn't help. – Shashank Kadambri – 2019-01-29T08:13:49.257

I guess that compiling from the command line is tying to keep things simple in order to test. But, since you intend to use an IDE anyway (you do, don't you?), why not start that as most let you specify where the build tools are. OR - must it be g++? If you install MS Visual Studio, that should sort of the paths for you. Can you tell us what oyu intend to develop? Command line .exe? Windows GUI programs? Something else? – Mawg says reinstate Monica – 2019-01-29T08:18:28.023

@Mawg I don't use an IDE for writing codes. I prefer writing my code in VS Code as text editor, and compile it through g++ in cmd. I'm a college student, and I make simple to intermediate level programs, not advanced or GUI based. – Shashank Kadambri – 2019-01-29T13:25:51.003

Nevertheless, you will find the IDE to be very useful, and the debugger is your best friend. Stop adding printf()s to your code. Learn how to set a ‘breakpoint’ on one or more lines of code then you until one is reached. At that point, execution is stopped; you can look at the call stack to see how you got there, examine variables, even change their values & continue to run, and much more. Really, I can’t urge you enough to stop whatever you are doing, and investigate the debugger. Also, learn the value of unit testing, and static code analysis (see CppCheck, etc). – Mawg says reinstate Monica – 2019-01-29T14:21:51.110

Using good tools saves you so much time and heartache. – Mawg says reinstate Monica – 2019-01-29T14:21:54.473

No answers