Gcc fatal error windows h no such file or directory

Fatal error: iostream: No such file or directory in compiling C program using GCC

Why when I wan to compile the following multi thread merge sorting C program, I receive this error:

2 Answers 2

Neither nor are standard C header files. Your code is meant to be C++, where is a valid header. Use g++ (and a .cpp file extension) for C++ code.

Alternatively, this program uses mostly constructs that are available in C anyway. It’s easy enough to convert the entire program to compile using a C compiler. Simply remove #include and using namespace std; , and replace cout with putchar(‘\n’); . I advise compiling using C99 (eg. gcc -std=c99 )

Seems like you posted a new question after you realized that you were dealing with a simpler problem related to size_t . I am glad that you did.

Anyways, You have a .c source file, and most of the code looks as per C standards, except that #include and using namespace std;

C equivalent for the built-in functions of C++ standard #include can be availed through #include

    Replace #include with #include , delete using namespace std;

With #include taken off, you would need a C standard alternative for cout , which can be done by printf(«\n»); or putchar(‘\n’);
Out of the two options, printf(«\n»); works the faster as I observed.

When used printf(«\n»); in the code above in place of cout

When used putchar(‘\n’); in the code above in place of cout

Compiled with Cygwin gcc (GCC) 4.8.3 version. results averaged over 10 samples. (Took me 15 mins)

gcc/g++: “No such file or directory”

g++ gives me errors of the form:

It is the same when compiling C-programs with gcc .

Please note: This question has been asked many times before, but each time it was specific to the askers situation. This question’s purpose is to have a question that others can be closed as duplicates of, once and for all; a FAQ.

2 Answers 2

Your compiler just tried to compile the file named foo.cc . Upon hitting line number line , the compiler finds:

The compiler then tries to find that file. For this, it uses a set of directories to look into, but within this set, there is no file bar . For an explanation of the difference between the versions of the include statement look here.

How to tell the compiler where to find it

g++ has an option -I . It lets you add include search paths to the command line. Imagine that your file bar is in a folder named frobnicate , relative to foo.cc (assume you are compiling from the directory where foo.cc is located):

You can add more include-paths; each you give is relative to the current directory. Microsoft’s compiler has a correlating option /I that works in the same way, or in Visual Studio, the folders can be set in the Property Pages of the Project, under Configuration Properties->C/C++->General->Additional Include Directories.

Now imagine you have multiple version of bar in different folders, given:

The priority with #include «bar» is leftmost:

As you see, when the compiler started looking through A/ , B/ and C/ , it stopped at the first or leftmost hit.

This is true of both forms, include <> and incude «» .

Difference between #include and #include «bar»

Usually, the #include makes it look into system folders first, the #include «xxx» makes it look into the current or custom folders first.

Imagine you have the following files in your project folder:

For this, your compiler will #include the file list in your project folder, because it currently compiles main.cc and there is that file list in the current folder.

But with main.cc :

Читайте также:  Zsh on manjaro linux

and then g++ main.cc , your compiler will look into the system folders first, and because
is a standard header, it will #include the file named list that comes with your C++ platform as part of the standard library.

This is all a bit simplified, but should give you the basic idea.

Details on <> / «» -priorities and -I

According to the gcc-documentation, the priority for include <> is, on a «normal Unix system», as follows:

For C++ programs, it will also look in /usr/include/c++/version, first. In the above, target is the canonical name of the system GCC was configured to compile code for; [. ].

The documentation also states:

You can add to this list with the -Idir command line option. All the directories named by -I are searched, in left-to-right order, before the default directories. The only exception is when dir is already searched by default. In this case, the option is ignored and the search order for system directories remains unchanged.

To continue our #include
/ #include»list» example (same code):

and indeed, the -I. prioritizes the folder . over the system includes and we get a compiler error.

Yet Another MinGW “gcc: error: CreateProcess: No such file or directory”

I have installed MinGW C compiler in Windows 8 (64 bit) through the GUI installer. But when I try to compile a C program, gcc says: gcc: CreateProcess: No such file or directory

It is a common bug, and I have tried all the solutions I found, without success.

In particular, (following CreateProcess: No such file or directory) I have tried to:

    [EDITED] Add C:\MinGw\libexec\gcc\mingw32\4.7.2 to my system PATH

Uninstall and re-install gcc through mingw-get CLI:

mingw-get remove mingw32-gcc
mingw-get install mingw32-gcc

EDIT: verbose gcc output:

8 Answers 8

You shouldn’t add C:\MinGw\libexec\gcc\mingw32\4.7.2 to the path.

You may need to reboot to ensure that the path is made available to all processes properly.

Another suggestion is to use a different MinGW distribution. It’s been a long time since I used an ‘official’ MinGW distribution because the installation steps were so byzantine and fragile. I’ve heard they’ve made large advances to the installer, but from what I hear it still seems to be rather complicated and fragile.

TDM’s installer just works, but I think the TDM release isn’t quite to 4.7.2.

The nuwen distribution’s installation is just unpacking an archive where you want the thing (I love that!) and making sure the path points to the location of gcc.exe. Nuwen also packages the boost libraries, which is nice.

I case it helps, here’s what I get from gcc -v hello.c ( c:\mingw.4.7.2\bin is in the path`):

Linux Mint Forums

Welcome to the Linux Mint forums!

gcc fatal error:stdio.h:No such file or directory

gcc fatal error:stdio.h:No such file or directory

Post by lmitcham » Wed Jan 30, 2013 4:39 pm

Hello.c:1:19: fatal error: stdio.h: No such file or directory

I get this error after installing a fresh Linux Mint 14. I have added the correct directory to path and can see it when I type «echo $PATH» in terminal.

I am new to Linux and any advice is welcome.

Re: gcc fatal error:stdio.h:No such file or directory

Post by bjornmu » Wed Jan 30, 2013 6:11 pm

Re: gcc fatal error:stdio.h:No such file or directory

Post by SiKing » Wed Jan 30, 2013 6:39 pm

gcc is a compiler, Hello.c is a source file, stdio.h is a resource file.
The PATH is a variable where binary executables are searched for.
The above two items have absolutely nothign to do with each other!

You were apparently trying to compile something. What are you trying to accomplish, and how are you going about it? We need steps to reproduce to be able to help you.

Re: gcc fatal error:stdio.h:No such file or directory

Post by lmitcham » Thu Jan 31, 2013 8:48 am

I created a directory named «Temp» under >home>mydir>Projects, and stored Hello.c there.

If I open terminal and go to the «Temp» directory and type «gcc Hello.c -o hello1», the response is
«fatal error: stdio.h: No such file or directory»

My first thought was that stdio.h was not in the PATH, so I added it and checked that the PATH was updated by typing
«echo $PATH»

Another attempt to compile produced the same error message.

That is where I am now. I am hopefully missing something simple.

Re: gcc fatal error:stdio.h:No such file or directory

Post by bjornmu » Thu Jan 31, 2013 12:38 pm

Читайте также:  Как перепрошить mac os

The file should be located under /usr/include and this is the default location so you shouldn’t need to tell gcc that. You may first want to double check that you have /usr/include/stdio.h available.

BTW your program won’t compile in any case since you’ve forgotten () after the name of main(). But you didn’t get that far.

Re: gcc fatal error:stdio.h:No such file or directory

Post by JasonMel » Thu Sep 11, 2014 5:37 pm

Re: gcc fatal error:stdio.h:No such file or directory

Post by Zetor895 » Tue Sep 23, 2014 8:25 am

CreateProcess: No such file or directory

I am getting this error whenever I try to run GCC outside of its installation directory ( E:\MinGW\bin ).

So, let’s say I am in E:\code and have a file called one.c . Running: gcc one.c -o one.exe will give me this error:

The only workaround is to navigate to its installation directory, run gcc from there, and specify all the other paths. My environmental variable Path contains E:\MinGW\bin .

Any suggestions to fixing this problem? I am running Windows XP SP3.

25 Answers 25

Its specifically told that you need to reboot after you set the environmental variables in windows for migwin.

According to Code::Blocks wiki, you need to add C:\MinGW\libexec\gcc\mingw32\MinGW-Version to your PATH . There is no need to restart, but you need to open another terminal in order to get the newest PATH settings.

For MinGW-w64, that’s \libexec\gcc\x86_64-w64-mingw32\4.7.0\

I had a similar problem, caused by not installing the C++ compiler. In my case I was compiling .cpp files for a Python extension, but the compiler is first invoked as c:\mingw\bin\gcc.exe.

Internally, gcc.exe would notice it was asked to compile a .cpp file. It would try to call g++.exe and fail with the same error message:

gcc.exe: CreateProcess: no such file or directory

I just had this problem.

In my case, the problem was due to problems when downloading the packages for GCC. The mingw-get program thought it finished the download, but it didn’t.

I wanted to upgrade GCC, so I used mingw-get to get the newer version. For some reason, mingw-get thought the download for a particular file was finished, but it wasn’t. When it went to extract the file, I guess it issued an error (which I didn’t even bother to look — I just ran «mingw-get update && mingw-get install mingw32-gcc» and left it there).

To solve, I removed gcc by doing «mingw-get remove mingw32-gcc» and also removed the package file (the one mingw-get didn’t fully download), which was in the mingw cache folder («C:\MinGW\var\cache\mingw-get\packages» in my system), then ran the install command again. It download and installed the missing parts of GCC (it had not fully downloaded the package gcc-core).

That solved my problem.

Interestingly enough, mingw-get was smart enough to continue the download of gcc-core even after me having deleted the package file in the cache folder, and also removed the package mingw32-gcc.

I think the more fundamental problem was that since gcc-core files were not installed, cc1 wasn’t there. And gcc uses cc1. I guess that, when gcc tried to start cc1, it used CreateProcess somewhere passing the path of cc1, which was not the path of an existing file. Thus the error message.

So this is a stupid error message because it doesn’t tell you what file it can’t find.

Run the command again with the verbose flag gcc -v to see what gcc is up to.

In my case, it happened it was trying to call cc1plus . I checked, I don’t have that. Installed mingw’s C++ compiler and then I did.

I had exactly the same problem.

After a recheck of my PATH , I realized I installed both Mingw (64 bit) and Cygwin (32 bit). The problem is that both Mingw and Cygwin have g++ .

By deactivating the path of Cygwin , the error disappeared.

In the «give a man a fish, feed him for a day; teach a man to fish, get rid of him for the whole weekend» vein, shows compiler options. The g++ -v option helps:

Look through the output for bogus paths. In my case the original command:

generated output including this little gem:

which would explain the «no such file or directory» message.

The «../lib/gcc/arm-none-eabi/4.5.1/» segment is coming from built-in specs:

Was getting the same error message when trying to run from Cygwin with links to the mingw install.

Using the same install of mingw32-make-3.80.0-3.exe from http://www.mingw.org/wiki/FAQ and the mingw shell option from Start -> Programs -> on a WinXP SP3 and gcc is working fine.

Читайте также:  Refit mac os high sierra �� �����������

I had this same problem and none of the suggested fixes worked for me. So even though this is an old thread, I figure I might as well post my solution in case someone else finds this thread through Google(like I did).

For me, I had to uninstall MinGW/delete the MinGW folder, and re-install. After re-installing it works like a charm.

I experienced a similar problem. Initially, adding the GCC bin folder to my system path did not resolve the problem. I found two solutions.

The first was to run a batch file I found in the root of the MinGW install, mingwbuilds.bat. It (apparently) launches a command prompt configured correctly to run GCC. The second was to remove double-quotation marks from the GCC install bin folder that I had added to my user path variable. I tried this after noticing the batch file not using double-quotes around the install bin path.

I found the batch file accidentally while browsing the install folder tree trying to locate the various executables that weren’t launching (according to the -v output). I found some information on the MinGW wiki, http://www.mingw.org/wiki/Getting_Started, in the Cautions and Environment Settings sections, that indicates why the MinGW installer does not set up the system or user path to include the install folder. These seem to confirm the batch file is intended to launch a command prompt suitable for running GCC from a Windows prompt.

It looks like there are a couple of release distro for MinGW. Which one did you try? For the record, I ran into the exact same problem as the OP and the distro I got was from TDM-GCC 4.5.1.

I found the MinGW distro here seems to work far better and sets things up correctly. So for anyone running into this retarded ‘createprocess-no-such-file-or-directory’ error and can’t get things to work, uninstall your existing MinGW and try the one I linked instead.

This problem might arise if you have different versions of programs.

For instance, you have 1-year old gcc and you want to compile a C++ source code. If you use mingw-get to install g++ , gcc and g++ will suddenly have different versions and you ware likely to find yourself in this situation.

Running mingw-get update and mingw-get upgrade has solved this issue for me.

I had a very long path, and there’s a file in there somewhere (not gcc.exe) but another file, that gcc.exe is accessing from the path..

So when I cleared the path, it worked

^^ So running gcc from there will definitely run the ming gcc.exe

Compiling it I got this error

My PATH was huge

C:\MinGW\bin>path | grep -io «ming»

It didn’t have ming there.

C:\MinGW\bin>echo MING | grep -io «ming» MING

(and yeah that grep works..the path didn’t have ming there)

Clearing my path completely, led it to work!

So, it’s not clear yet precisely what it was in the PATH that led to the clash. What directory, what file.

Update-

The above seems to be correct to me but to add, it’s also not a simple case of something earlier in the path clashing.. because normally the current directory takes precedence. And it does here in so far as gcc —version shows it’s running the ming one and not one of the ones in a conflicting directory. So there’s something funny going on that, if the conflicting directory is in the path) , one has to either do .\gcc or add . to the start of the path or add c:\MinGW\bin before any conflicting directories in the path. this is the case even when you’re in C:\MinGW\bin and that’s strange. And when it gives an error, it is still running Ming’s gcc but (For some reason) looking at the conflicting directory too, as I see from process monitor. There may be more of an answer here http://wiki.codeblocks.org/index.php?title=Installing_MinGW_with_Vista in the link mentioned in the very upvoted answer here

That’s Ming32 bit..

Looking at Ming 64bit, probably has te same issue, but I see, interestingly, it comes with a bat file that (sensibly) actually puts the bin directory at the tart of the path. And it looks like that is a standard way of running Ming gcc properly.

The code::blocks IDE (sensibly) also puts the bin directory at the start of the path. If you run a C program that shows environment variables then you see that.

Оцените статью