User forums > Help
#include <iostream> NO such File or Directory
stahta01:
--- Quote from: bezerker999 on January 09, 2010, 06:00:33 am ---I am having the same problem with "iostream" and I moved my "test.c" to C:/Program Files/codeblocks and it worked.
Two questions:
1. Why?
2. What do I have to do to compile *.c in other directories
Global Settings:
GNU GCC Complier
Toolchain ex
instal dir = C:\Program Files\CodeBlocks\MinGW
no make.exe in bin directory but found a mingw32-make.exe
Windows 2000 Pro
Dell Latitudue Laptop
===================================================================
--- End quote ---
No idea; but "iostream" does NOT exist in the C Language. So, you should have to change the extension to *.cpp for it to work right by default with Code::Blocks.
Tim S.
Cplusser1:
I was using a different code but as it is I have copied and pasted the code above and it still says that iostream has no such file or directory and I installed the version with the compiler included.(i made the necessary changes to the code though.)
Okaya:
Hello everyone,
I too have this compilation problem with certain libraries, and not just <iostream>. I gather that my compiler is incorrectly installed, although I am unsure what is causing the problem.
I am using Code::Blocks 8.02 (MinGW version) under Windows XP, SP2. CodeBlocks seems to not find libraries included in the STL library collection. This is my test code:
--- Code: ---#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
using namespace std;
int main()
{
vector<string> SS;
SS.push_back("The number is 10");
SS.push_back("The number is 20");
SS.push_back("The number is 30");
cout << "Loop by index:" << endl;
int ii;
for(ii=0; ii < SS.size(); ii++)
{
cout << SS[ii] << endl;
}
cout << endl << "Constant Iterator:" << endl;
vector<string>::const_iterator cii;
for(cii=SS.begin(); cii!=SS.end(); cii++)
{
cout << *cii << endl;
}
cout << endl << "Reverse Iterator:" << endl;
vector<string>::reverse_iterator rii;
for(rii=SS.rbegin(); rii!=SS.rend(); ++rii)
{
cout << *rii << endl;
}
cout << endl << "Sample Output:" << endl;
cout << SS.size() << endl;
cout << SS[2] << endl;
swap(SS[0], SS[2]);
cout << SS[2] << endl;
int i;
scanf("%d", &i);
return 0;
}
--- End code ---
This is my full command line build log:
--- Code: ---mingw32-g++.exe -IC:\LIBS\SDL-1.2.14\include -c "C:\Documents and Settings\User\Desktop\test.cpp" -o "C:\Documents and Settings\User\Desktop\test.o"
C:/Documents and Settings/User/Desktop/test.cpp:1:20: iostream: No such file or directory
C:/Documents and Settings/User/Desktop/test.cpp:2:18: vector: No such file or directory
C:/Documents and Settings/User/Desktop/test.cpp:3:18: string: No such file or directory
C:/Documents and Settings/User/Desktop/test.cpp: In function `int main()':
C:/Documents and Settings/User/Desktop/test.cpp:10: `vector' undeclared
(first use this function)
C:/Documents and Settings/User/Desktop/test.cpp:10: (Each undeclared
identifier is reported only once for each function it appears in.)
C:/Documents and Settings/User/Desktop/test.cpp:10: `string' undeclared
(first use this function)
C:/Documents and Settings/User/Desktop/test.cpp:10: `SS' undeclared (first
use this function)
C:/Documents and Settings/User/Desktop/test.cpp:16: `cout' undeclared (first
use this function)
C:/Documents and Settings/User/Desktop/test.cpp:16: `endl' undeclared (first
use this function)
C:/Documents and Settings/User/Desktop/test.cpp:26: `::const_iterator'
undeclared (first use here)
C:/Documents and Settings/User/Desktop/test.cpp:26: parse error before `;'
token
C:/Documents and Settings/User/Desktop/test.cpp:27: `cii' undeclared (first
use this function)
C:/Documents and Settings/User/Desktop/test.cpp:34: `::reverse_iterator'
undeclared (first use here)
C:/Documents and Settings/User/Desktop/test.cpp:34: parse error before `;'
token
C:/Documents and Settings/User/Desktop/test.cpp:35: `rii' undeclared (first
use this function)
C:/Documents and Settings/User/Desktop/test.cpp:45: `swap' undeclared (first
use this function)
Process terminated with status 1 (0 minutes, 0 seconds)
16 errors, 0 warnings
--- End code ---
So, apparently, CodeBlocks cannot find not only <iostream>, but also <vector> and <string>. I have tried uninstalling and reinstalling CodeBlocks but it does not seem to improve anything. I have also compiled this code on my system using MingW and MSYS, with the command g++ test.cpp.
Reading the previous replies in this topic, I'd suppose that if I tried compiling my source code in the CodeBlocks' installation directory, everything would work fine. But I'm trying to figure out what is causing the problem here.
Any help, feedback, or suggestions are most appreciated. Thank you in advance for any replies.
Okaya
reckless:
hmm strange :?
i use codeblocks every day allbeit with my own fork of gcc/g++ and got no problems whatsoever.
however my codeblocks is installed in the root of c: so a guess would be that the paths somehow get screwed up (not sure about gcc's handling of windows long names).
could you try installing it to C:\codeblocks and see if that fixes it ?
Okaya:
Thank you for your reply reckless, much appreciated.
No, installing CodeBlocks in the C:/Codeblocks directory didn't improve the situation. But, fortunately, I think I've finally managed to pinpoint the problem. It apparently has to do with the compiler's installation directory, in my case at least. Going to Settings -> Compiler and Debugger -> Toolchain Executables (Tab) , there's a section entitled "Compiler's Installation Directory".
Now, quite long ago, I had Dev-C++ installed on this machine, but have uninstalled it since, and was using MinGW and MSYS (and now CodeBlocks). However, the Compiler's Installation Directory for CodeBlocks was for some reason set to C:\Dev-Cpp , which was the installation directory for Dev-C++ when it was installed (and apparently did not get automatically deleted even after my uninstalling it). So, apparently, all this time CodeBlocks had been using the MinGW version found in the uninstalled Dev-C++ directory, which unsurprisingly was incomplete, and thus I was missing header files during compilation. No wonder it was behaving strangely!
So, I just set the Compiler's Installation Directory to a working version of MinGW, and the code now compiles without problems. Because my standalone MinGW version is slightly more recent than the one that came with CodeBlocks, I set the directory to the standalone MinGW's location, in my case C:/MinGW . However, I find that the problem is equally solved by setting it to the MinGW directory found in CodeBLocks own installation folder, and that's perhaps the preferred solution. In my case, it would be C:\Program Files\CodeBlocks\MinGW . Once this directory is set, the header files are located without problems.
Something interesting though is that CodeBlocks somehow "inherited" this erroneous setting, because this is the first time I notice it (and I certainly didn't set it myself). How can this occur? Could it have something to do with my system's PATH variable?
Another thing I notice but am not sure why it occurs is that CodeBlocks somehow "remembers" it's previous settings between successively uninstalling and reinstalling it (even though it's installation folder is automatically deleted with the uninstall process). That is, CodeBlocks remembers all my added include directories and linked libraries (and also remembered the erroneous Dev-C++ directory for the compiler) between successive reinstallations, without my having to manually reinput them upon reinstalling.
So, a question would be: Why does this happen, and from where does CodeBlocks reload those past settings after it has been reinstalled?
Anyway, I think that the reason why others have reported that source files compile if placed in the CodeBlocks installation directory but not outside of it probably shows that the issue is related with the Compiler Installation Directory. So I'd propose that anyone having similar problems check that this setting actually points to their compiler's directory.
Regarding GCC's support of Windows long names:
I'm not sure about this, although I've used GCC/G++ both through the MSYS command line and through an IDE, and it seems to handle long windows names fine and compile without problems. I have heard it said sometimes that it's a good idea to not include spaces in the install and project directories used, but I haven't come across any issues so far.
Okaya
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version