User forums > Using Code::Blocks
iostream: No such file or directory
lxi:
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?
thomas:
"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...
lxi:
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?
mandrav:
Do you have *any* other compiler installed, by any chance? Or MSYS?
lxi:
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.
Navigation
[0] Message Index
[#] Next page
Go to full version