Run MinGW gcc compiler in Windows 7 without setting environment variables

痞子三分冷 提交于 2021-02-07 18:30:11

问题


I have a MinGW folder in Windows and I didn't set any paths in environment variables. When I run the following command:

D:\toolchains\MinGW\bin>gcc.exe hw.c -o hw

I got this error:

gcc.exe: error: CreateProcess: No such file or directory

As far as I understand, this problem caused by that I didn't add this path to environment variables. How can I solve this problem without adding this path to environment variables, because I'm planning to run this command from Python script.


回答1:


You either have to modify your PATH environment variable or start the gcc process with the right working directory. You can do both in python:

  • Modify environment variables from within python

  • Specify a working directory for a subprocess in python

I would recommend to modify the PATH variable.




回答2:


You have to set the PATH environment variable for raw Mingw to work. See this, the section called "Environment Settings":

  1. Right-click on your "My Computer" icon and select "Properties".
  2. Click on the "Advanced" tab, then on the "Environment Variables" button.
  3. You should be presented with a dialog box with two text boxes. The top box shows your user settings. The PATH entry in this box is the one you want to modify. Note that the bottom text box allows you to change the system PATH variable. You should not alter the system path variable in any manner, or you will cause all sorts of problems for you and your computer!
  4. Click on the PATH entry in the TOP box, then click on the "Edit" button
  5. Scroll to the end of the string and at the end add

    ;<installation-directory>\bin

  6. press OK -> OK -> OK and you are done.

Otherwise, if you use an IDE like Codeblocks, it will do all these dirty details for you. See this for an example of how to change the default Mingw compiler used by Codeblocks. It has an "auto detect" feature which will localize the Mingw compiler, linker etc etc.



来源:https://stackoverflow.com/questions/39488261/run-mingw-gcc-compiler-in-windows-7-without-setting-environment-variables

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