I'm writing a basic C++ program in Windows 7 that I am hoping to compile from itemindiv.cpp, itemindiv.h, item.cpp, item.h, container.cpp, container.h, and main.cpp. I've tried installing g++ and when I type "g++" command line, it doesn't recognize the command. I can't find a simple way to compile these files together, which was easy in command line on a unix system. Is there an easy way to compile this so I can interact with basic input and output (text based)?
-
1Yeah, you'll need to purchase a C++ compiler and follow the required steps for that compiler. May I recommend Visual Studio? – Jonathan Wood Jan 14 '18 at 17:30
-
I've tried g++/gcc and gnu and I can't seem to figure out how to use these compilers. I followed instructions for g++ from a tutorial and when I type in "g++" in command line it doesn't recognize the command. – Ryan Westra Jan 14 '18 at 17:34
-
Install a compiler, there are several free ones. – Ulrich Eckhardt Jan 14 '18 at 17:34
-
@JonathanWood there's a free offering for Visual Studio from Microsoft. The capabilities of the free version have changed over the years, but it's been available for a long time. – Mark Ransom Jan 14 '18 at 17:34
-
@MarkRansom: Not sure why that was directed at me. – Jonathan Wood Jan 14 '18 at 17:35
-
@RyanWestra: Are you sure that compiler is installed on the system? If not, then see my first comment. If so, then repost your question and tag the compiler and ask for help with *that* compiler. – Jonathan Wood Jan 14 '18 at 17:35
-
1@JonathanWood because you recommended "purchasing" Visual Studio. – Mark Ransom Jan 14 '18 at 17:35
-
I followed instructions to install g++ and not sure how to use it – Ryan Westra Jan 14 '18 at 17:36
-
@MarkRansom: Ah, well I guess I should've said to *get* a C++ compiler. I'm aware there is a free version, although I didn't assume the OP would only use free software. – Jonathan Wood Jan 14 '18 at 17:36
-
I followed these instructions and typing g++ is not recognized: http://www1.cmc.edu/pages/faculty/alee/g++/g++.html – Ryan Westra Jan 14 '18 at 17:40
-
@RyanWestra: In my opinion, Visual Studio would be easier. But I haven't specifically worked with *g++/gcc*. Perhaps you missed my point about reposting your question specific for *that* compiler, or at least adding that tag to your question? – Jonathan Wood Jan 14 '18 at 17:42
-
Did you modify the PATH environment variable to have the right path to where g++ is installed in it? – Ian4264 Jan 14 '18 at 17:47
-
Ok, so I imported all my files into a Visual Studio Project. I clicked "Build" on the project. It gives me an error: "MSB6006 "CL.exe" exited with code - 1073741515" – Ryan Westra Jan 14 '18 at 18:11
-
@Ian4264 This was my problem; now it's working! Thanks. – Ryan Westra Jan 14 '18 at 18:20
2 Answers
Using g++ on windows via the command line is entirely viable through the use of something like MinGW or MinGW64, and you do not need to install Visual Studio to do it. However, it must be configured properly!
Notably, when running something from a command line, it's important to make sure it's fully installed and "on the path". The PATH
is essentially a list of locations Windows will look for the program you're trying to run in.
Your first step should be locating g++ on your machine, and I assume in the install directory. This will not only tell you if you if it was installed correctly, but will help us configure the path. Generally, files you can run are going to be located in a /bin
folder. In the case of MinGW64, this is located with in the installation directory.
On my machine for example, g++ is located at C:\mingw64\bin\g++.exe
, which is where I ended up installing MinGW. You can also force windows to run g++.exe by providing the full path to it in the command line, regardless of if it's on the windows PATH or not. In my case, this may look as follows: C:\mingw64\bin\g++.exe myfile.cpp -o output.exe
If you are able to find the executable but it won't run from CMD/Powershell, this very often means that either the path doesn't include the install directory. Lets fix that.
Putting g++ on the path
- Figure out the folder that the application is located in. In my case, this is
C:\mingw64\bin\
, but the location of g++.exe on your machine may and probably will vary. - Add your directory to the path: This can be done manually as follows, or with the help of a tool like EVEditor. This process is covered in a few other stack overflow answers as well, but I'll go over it quickly here:
- In windows 7, right-click on My Computer and click Properties, then click on the advanced tab. In the advanced section, there should be an environment variables button, which should pop up a window titled Environment Variables.
- Highlight the path variable, and click edit. The path is made up of semicolon
;
delimited entries, and so we can and modify it to includeC:\mingw\bin;
(or wherever g++ is located for you) at the front - note the addition of the semicolon at the end of the filepath! It's important you do not delete what is already on the path, or this may impact the ability of other programs on your machine to run! In addition, windows searches the path in the order specified: front to back. If you have two folders, both with g++.exe in them, the first one appearing on the path will be used.
- Once you've added it to the path, make sure you've restarted CMD/Powershell so your changes to the path are applied!
Note: If you think you added something to the path but it's still not accessible from the command line, you can have windows dump out what it thinks the path is in a given terminal window with echo %PATH%
.

- 40
- 1
- 5
You need to install Microsoft Visual Studio and the create a C++ project. Ensure to select to install Visual C++ modules during the Microsoft Visual Studio installation.

- 1
- 1