MinGW error: No such file or directory exists [clo

2020-02-14 06:28发布

I'm running MinGW on windows XP SP3. I wrote a simple program in C++ and saved it as a .cpp file. When I tried to compile it in MinGW at the correct directory a message appeared saying " Error: No such file or directory exists" but I know its in the correct directory.

This is what I typed into MinGW

cd C:\MinGW test  # Where I saved the .cpp file
g++ test.cpp -o test.exe

After that an error appears.

Also I did change the Environment Settings path to C:\MinGW\bin

3条回答
放我归山
2楼-- · 2020-02-14 06:58

Windows is complaining that the mingw compiler (g++) is not in the path.

Add it to your path by going to Control Panel-> System-> Advanced System Settings -> Advanced -> Environment Variables

Look for the PATH variable and edit it. At the end add a semicolon separater and then the correct path to the MingW bin folder. Then close, then reopen your command prompt. If you now type g++ by itself it should complain that you have no input files. Then use the command you tried previously.

查看更多
等我变得足够好
3楼-- · 2020-02-14 07:17

cd C:\MinGW test does not look right.

Did you mean cd C:\MinGW\test\?

Also remember that you have to separately change into the C: drive before performing cd. What does your prompt say? It'll tell you what directory you're in.

查看更多
淡お忘
4楼-- · 2020-02-14 07:19

To get it to work, you should run the compiler from the folder where the program is, not where MinGW is. First, you need to set your PATH to include MinGW. You can do this with set PATH = C:\MinGW\bin;%PATH% on the command line.

Then, cd to where the program is located and run g++ test.cpp -o test.exe to compile, and test to run.

Hope this helps!

查看更多
登录 后发表回答