问题
I'm trying to compile c++ programs from the commandline, but I can't. I tried all the steps and instructions listed here.
I got MinGW installed, but I get stuck in the last step of the installation that explains how to change environment paths. There simply isn't PATH part of it on the environment variables, and when I try to add it or even edit the one in System variables, compiling doesn't work (nothing comes up when I type g++ on the command prompt).
I've searched online for solutions, but I haven't been able to find anything.
Reinstalling MinGW32 resolved the issue of not being able to compile C++ at all.
Adding ;C:\mingw\bin
in the PATH variable under Advanced Settings in Properties in My Computer fixed compiling in cmd, as answered by @Chrono Kitsune.
回答1:
It looks like either PATH variable is removed from regedit or it has grown to size of more than 2048. To find out
Open cmd window and type PATH, if it prints the path. Something like: C:\Users\robin>PATH
PATH=C:\ProgramData\Oracle\Java\javapath;............
Then most probably it has grown to more than 2048 and that is why its not visible. You can update your Path variable in the command line by this command:
set PATH=%PATH%;C:\cygwin64\bin
So it will append Path with "C:\cygwin64\bin"If that doesn't work. Then check in regedit if these are present: HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
HKCU\Environment
If not, export them from another PC and then import.
回答2:
Press Win+R to open the Run dialog and type
sysdm.cpl ,3
- Click the "Environment Variables" button.
- There are two sections: "User Variables" (top) and "System Variables" (bottom). You want to look at the top section.
- If you don't have a
PATH
variable, click the "New" button and typePATH
for the variable name. Otherwise, just double-click the existingPATH
variable. Now add the following to the end of the variable's value:
;C:\mingw\bin
where
C:\mingw\bin
is the folder containingg++.exe
.- Click OK on each dialog box to close it.
Open a new command prompt and try to execute
g++.exe -xc -E nul
If you still get an error, try logging off and logging back on.
回答3:
I prefer using a Linux OS for compiling C/C++ programs. I use VirtualBox to host a Ubuntu machine and it works very well.
If you go that route to compile, navigate to the directory using the 'cd' command, and then type 'make' to compile and ./yourprogram
to execute.
来源:https://stackoverflow.com/questions/35833343/compiling-c-in-cmd-using-mingw-on-windows-8