Author Topic: iostream: No such file or directory  (Read 22362 times)

Offline lxi

  • Multiple posting newcomer
  • *
  • Posts: 10
iostream: No such file or directory
« on: October 12, 2005, 04:08:34 pm »
I'm trying to compile the project you get when you go New->Console Application;

#include <iostream>

int main()
{
    std::cout << "Hello world!" << std::endl;
    return 0;
}


...and I get the following errors from the compiler (using MinGW, specifically the one that was included with the Code::Blocks 1.0-RC1 release)

Compiling: main.cpp
main.cpp:1:20: iostream: No such file or directory
main.cpp: In function `int main()':
main.cpp:5: error: `cout' is not a member of `std'
main.cpp:5: error: `endl' is not a member of `std'
Process terminated with status 1 (0 minutes, 0 seconds)
3 errors, 0 warnings


I found iostream.h in "C:\Program Files\CodeBlocks\include\c++\3.4.4\backward" and added that to the compiler directories under Compile->Compiler Options->Directories->Compiler (along with "C:\Program Files\CodeBlocks\include"), but it still won't compile. I've tried compiling some of the other default projects but the same thing occurs on different files. All the files definitely exist and are on the include path I've specified.

I'm sure there is something simple that I'm missing, but I have no idea what it is, and I couldn't find anything in the forums or on the wiki. Any thoughts?

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: iostream: No such file or directory
« Reply #1 on: October 12, 2005, 04:43:25 pm »
"backward" is not good. It has to be in C:\Program Files\CodeBlocks\include\c++\3.4.4

Look if it is there, if not, you have to do a proper MinGW installation. If it is there, make sure the path C:\Program Files\CodeBlocks\include is in your include path.

As a sidenote, many commandline tools may have a problem with C:\Program Files\CodeBlocks because of the space character in Program Files. The compiler should not choke on that, but a couple of others almost certainly will (windres and gdb are notoriously known for that, to name two). So you really may want to install Code::Blocks in a space-less path.

Personally, I prefer to install "naked" Code::Blocks and do a MinGW install separately. One goes in C:\codeblocks, and the other goes in C:\mingw. Although choosing the like pathnames almost looks like 1985, it has the advantage that it is failsafe and unambiguous, which is a good thing.
Here is the list of what you need: http://wiki.codeblocks.org/index.php/Install_mingw

That way you can
  • have everything that pertains to one compiler in one place (e.g. headers, libs)
  • upgrade Code::Blocks (to RC2, for example) any time later and not touch the compiler at all
  • upgrade the compiler (to gcc 4.x, for example) and not touch Code::Blocks at all
  • or... install another version in another place
  • easily restore one or the other in 15 seconds if you accidentially break it (burn onto crom)
  • do many other good things...
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline lxi

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: iostream: No such file or directory
« Reply #2 on: October 12, 2005, 05:15:41 pm »
I checked and there was a file called iostream (no extension) in C:\Program Files\CodeBlocks\include\c++\3.4.4, but just in case, I uninstalled CodeBlocks and reinstalled it to C:\CodeBlocks and did a separate install of MinGW to C:\MinGW using the MinGW-3.1.0-1.exe installer. Unfortunately this didn't fix the problem. I went to try compiling the default "Win32 GUI Application" and got this result:

Compiling: main.cpp
In file included from C:/MinGW/include/windows.h:47,
                 from main.cpp:1:
C:/MinGW/include/stdarg.h:6:24: stdarg.h: No such file or directory
In file included from C:/MinGW/include/string.h:40,
                 from C:/MinGW/include/winnt.h:37,
                 from C:/MinGW/include/windef.h:246,
                 from C:/MinGW/include/windows.h:48,
                 from main.cpp:1:
C:/MinGW/include/stddef.h:6:24: stddef.h: No such file or directory
In file included from C:/MinGW/include/winnt.h:37,
                 from C:/MinGW/include/windef.h:246,
                 from C:/MinGW/include/windows.h:48,
                 from main.cpp:1:


What confuses me about this is that it seems to find windows.h and a few others that are in C:\MinGW\include, but it fails to find stdarg.h which is in the same directory. Any ideas what would cause it to find some and not others?

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: iostream: No such file or directory
« Reply #3 on: October 12, 2005, 05:33:03 pm »
Do you have *any* other compiler installed, by any chance? Or MSYS?
Be patient!
This bug will be fixed soon...

Offline lxi

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: iostream: No such file or directory
« Reply #4 on: October 12, 2005, 05:46:33 pm »
I've got a few other IDEs installed; Microsoft Visual Studio .Net 2003, Borland C++ Builder 6 and Delphi 7. I've also got DevkitARM installed which has its own copy of gcc and other tools, but I've removed all references to it from my path so I wouldn't think that it would be causing problems with MinGW.

I actually just had a look at the stdarg.h that's in C:\MinGW\include, only to find it contains this:

/*
 * This is just an RC_INVOKED guard for the real stdarg.h
 * fixincluded in gcc system dir. One day we will delete this file.
 */
#ifndef RC_INVOKED
#include_next<stdarg.h>
#endif


I found another (more complete) copy of stdarg.h in C:\MinGW\lib\gcc-lib\mingw32\3.2.3\include, so I added that to the path and the "Win32 GUI Application" now compiles, but fails to link with the error: ld: cannot open crt2.o: No such file or directory. I found crt2.o in C:\MinGW\lib and added that to the linker directories in the compiler settings, but it again couldn't find it. The "Console application" still fails to compile because iostream isn't in the other include directory. The only place I've found it to exist is in C:\MinGW\include\c++\3.2.3.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: iostream: No such file or directory
« Reply #5 on: October 12, 2005, 08:11:32 pm »
I checked and there was a file called iostream (no extension)
That is ok, iostream must not have an extension (that used to be different a couple of years ago).

Compiling: main.cpp
In file included from C:/MinGW/include/windows.h:47,
                 from main.cpp:1:
Here, it would be helpful to change logging to "full commandline" (compiler options, rightmost tab), so you can see what include paths are actually used.
I looked at my windows.h and my stdarg.h, and they are exactly like you described them, so I suspect it has to do with include paths.
Eventually, giving the -print-search-dirs option might help.


I found another (more complete) copy of stdarg.h in C:\MinGW\lib\gcc-lib\mingw32\3.2.3\include, so I added that to the path
Not necessary if the install is good. Best never add such obscure paths, when things look stange they're likely wrong. Do I see 3.2.3 in there? You seem to have quite a few versions there.

fails to link with the error: ld: cannot open crt2.o: No such file or directory.
C:\mingw\lib has to be in the library path (not only for crt2.o, but for any library you wish to link with), best do that in compiler options rather than in the project options, or you will have to do it again for every new project.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline lxi

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: iostream: No such file or directory
« Reply #6 on: October 13, 2005, 02:07:01 am »
Quote
Not necessary if the install is good. Best never add such obscure paths, when things look stange they're likely wrong. Do I see 3.2.3 in there? You seem to have quite a few versions there.

I've only got one version installed, which is 3.2.3. My earlier post had 3.4.4 because I was using the version that was included with the Code::Blocks 1.0-RC1 release, and in response to the first reply I uninstalled it (along with MinGW 3.4.4) and did a separate install of Code::Blocks and MinGW (using the MinGW-3.1.0-1.exe installer).

The -print-search-dirs gave me the answer. As it turns out, gcc was still using the include folder for DevkitARM. I couldn't figure out why, but then I checked my environment variables and found one called GCC_EXEC_PREFIX pointing to DevkitARM's install location. I deleted that variable and suddenly everything compiles. :)

Thanks for the fast and detailed replies, I'd been trying to work this out for a couple of weeks on my own and then decided that I should give up and just ask on the forum :)

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: iostream: No such file or directory
« Reply #7 on: October 13, 2005, 08:50:29 am »
Quote
I've got a few other IDEs installed; Microsoft Visual Studio .Net 2003, Borland C++ Builder 6 and Delphi 7. I've also got DevkitARM installed which has its own copy of gcc and other tools, but I've removed all references to it from my path so I wouldn't think that it would be causing problems with MinGW.
(emphasis added)

See why I asked? :)
Be patient!
This bug will be fixed soon...