MinGW error: No such file or directory exists [closed]

北城以北 提交于 2019-12-29 08:52:10

问题


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


回答1:


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!




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/14330383/mingw-error-no-such-file-or-directory-exists

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!