2016-09-14 33 views
4

我在Windows中有一个MinGW文件夹,并且我没有在环境变量中设置任何路径。当我运行以下命令:在Windows 7中运行MinGW gcc编译器而不设置环境变量

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

我得到这个错误:

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

据我了解,这个问题所造成的,我没有这个路径添加到环境变量。如何在不向环境变量添加此路径的情况下解决此问题,因为我打算从Python脚本运行此命令。

+1

您只需调用'D:\ toolchains \ MinGW \ bin \ gcc.exe',而不是调用'gcc.exe'。只要您提供gcc的完整路径,您甚至不需要在MinGW安装目录中。 – Tim

+0

@TimF当我这样做时,我得到了同样的错误:( –

+0

好吧,对不起,那么它是gcc,没有找到hw.c.所以无论你从hw.c文件夹执行这个命令,或者你给绝对或相对于hw.c的路径例如'D:\ toolchains \ MinGW \ bin \ gcc.exe D:\ path \ to \ hw.c -o hw' – Tim

回答

3

您必须修改PATH环境变量或使用正确的工作目录启动gcc进程。你可以在Python一举两得:

我会建议修改PATH变量。

+0

我看不到任何理由,为什么工作目录应该与此事有任何关系。使用MinGW g ++没有设置搜索路径或工作目录对我来说工作得很好,而且一直如此(回到20世纪90年代)。但是,有时候连接器会出现问题,有时需要搜索'PATH',不仅需要它,而且还要在'PATH'中的其他搜索路径之前。 –

1

您必须设置原始Mingw工作的PATH环境变量。见this,被称为“环境设置”一节:

  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.

否则,如果您使用了代码块的IDE,它会做所有这些肮脏的细节给你。有关如何更改Codeblock使用的默认Mingw编译器的示例,请参见this。它有一个“自动检测”功能,它将本地化​​Mingw编译器,链接器等等。