4

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
    Instead of calling `gcc.exe` you just call `D:\toolchains\MinGW\bin\gcc.exe`. You don't even need to be in the MinGW installation dir as long as you give the full path to gcc. – Tim Sep 14 '16 at 10:47
  • @TimF When I do that I get the same error :( – Woo Hoo developer Sep 14 '16 at 10:56
  • Okay sorry, then it's gcc that doesn't find hw.c. So whether you execute this command from the folder where hw.c is, or you give the absolute or relative path to hw.c. By example `D:\toolchains\MinGW\bin\gcc.exe D:\path\to\hw.c -o hw` – Tim Sep 14 '16 at 11:03
  • This sounds like an incomplete installation. The compiler front end runs some other executables, some of which are located in related (but not the same) directory. I can reproduce the error message by forcing it to not find anything relative to its directory, simply by mapping a drive to bin and running it from root of that drive. Can you show an example where running the compiler **works**? – Cheers and hth. - Alf Sep 14 '16 at 11:38
  • That said, although running the compiler will normally work fine regardless of search path, the linker can be confused and fail if the MinGW bin directory is not in your `PATH`. So in practice you need that `PATH`. – Cheers and hth. - Alf Sep 14 '16 at 11:40

2 Answers2

3

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:

I would recommend to modify the PATH variable.

Community
  • 1
  • 1
GSIO01
  • 491
  • 7
  • 12
  • I can't see any reason why the working directory should have anything to do with the matter. Using MinGW g++ works fine for me without setting a search PATH or working directory, and that has always been so (back to the 1990s). But, occasionally there have been problems with the linker, which appears to sometimes need a search `PATH`, and not only need it, but have it before some other search path in `PATH`. – Cheers and hth. - Alf Sep 14 '16 at 11:58
1

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.

Community
  • 1
  • 1
Lundin
  • 155,020
  • 33
  • 213
  • 341