Author Topic: #include <iostream> NO such File or Directory  (Read 295753 times)

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6671
    • My Best Post
Re: #include <iostream> NO such File or Directory
« Reply #15 on: January 09, 2010, 10:30:09 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
===================================================================

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.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Cplusser1

  • Single posting newcomer
  • *
  • Posts: 3
Re: #include <iostream> NO such File or Directory
« Reply #16 on: January 11, 2010, 10:49:51 pm »
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.)
« Last Edit: January 11, 2010, 10:54:43 pm by Cplusser1 »

Offline Okaya

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: #include <iostream> NO such File or Directory
« Reply #17 on: April 07, 2010, 11:22:22 pm »
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: [Select]
#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;

}

This is my full command line build log:

Code: [Select]
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
 

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

Offline reckless

  • Regular
  • ***
  • Posts: 333
Re: #include <iostream> NO such File or Directory
« Reply #18 on: April 08, 2010, 12:23:35 am »
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 ?

Offline Okaya

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: #include <iostream> NO such File or Directory
« Reply #19 on: April 08, 2010, 04:57:27 pm »
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
« Last Edit: April 08, 2010, 07:47:07 pm by Okaya »

Offline reckless

  • Regular
  • ***
  • Posts: 333
Re: #include <iostream> NO such File or Directory
« Reply #20 on: April 08, 2010, 07:00:04 pm »
aye that makes sense codeblocks seems to pickup compiler path if its set in environment variables i can confirm that.

atleast its easy to fix once known maybe a good idea to sticky it ?

reason i wasnt sure about its handling of long pathnames is if i use C:\program files <- ups space in name \codeblocks atleast msys gave me some trouble there unless i used the dos short version.

happy you got it fixed though :)

Offline reckless

  • Regular
  • ***
  • Posts: 333
Re: #include <iostream> NO such File or Directory
« Reply #21 on: April 08, 2010, 07:41:34 pm »
checked dev-cpp installation and indeed it does set the compiler path in the system PATH the uninstall feature doesnt remove it though so seems like an oversight.

i guess the reason why codeblocks picks it up is it checks both registry and path and maybe executable names before checking its own directory ?

ofc with so many supported compilers this can get a bit hairy especially if the user had several different compilers at some point.

for instance i once used open watcom while having msvc installed also and every time i tried to build something it failed miserably to my horror i found out that watcom picked up the msvc compilers paths before its own and msvc had no idea of the watcom directory structure hence it failed every time cause the headers and libraries were not where it expected.

i since ditched msvc completly and just use the windows sdk's with mingw/codeblocks.


Offline Okaya

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: #include <iostream> NO such File or Directory
« Reply #22 on: April 08, 2010, 08:23:58 pm »
Quote from: reckless
reason i wasnt sure about its handling of long pathnames is if i use C:\program files <- ups space in name \codeblocks atleast msys gave me some trouble there unless i used the dos short version.
Yes, I had an issue too when using GCC via msys, but so long as I used double quotes whenever refering to long directory names (e.g. cd C:/"Program Files"/CodeBlocks), it worked fine.

Quote from: reckless
checked dev-cpp installation and indeed it does set the compiler path in the system PATH the uninstall feature doesnt remove it though so seems like an oversight.

i guess the reason why codeblocks picks it up is it checks both registry and path and maybe executable names before checking its own directory ?
That's interesting, thanks a lot for checking that. I checked my PATH variable now and it's clean (no Dev-C++ leftovers), I suppose that resetting the compiler directory in CodeBlocks fixed that too.

Quote from: reckless
ofc with so many supported compilers this can get a bit hairy especially if the user had several different compilers at some point.
Yes, I suppose so. In fact, it seems that's probably the reason for my erratic compiler behavior for some time now. I've installed Dev-C++ and MSVC++ in the past, before setting up CodeBlocks. I have uninstalled both at the moment, but it seems that there are certain traces left behind in the system from them. For instance, until recently, although .cpp and .h files were set to open with CodeBlocks as the default program, their "Type" attribute was still given as "MS Visual C++ .cpp file" I think. I had to manualy remove some leftover components from MSVC via "Add or Remove Programs" for the file type to stop being affected by it.

Quote from: reckless
atleast its easy to fix once known maybe a good idea to sticky it ?
I wonder if others having the same problem have been using multiple compilers too. I don't know if resetting Compiler Install Directory would fix it for everyone, but if anyone's got the same issues occurring, it's probably a good thing to check.

Okaya

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: #include <iostream> NO such File or Directory
« Reply #23 on: April 08, 2010, 09:12:16 pm »
Older versions of C::B (including the 8.02 release) use the path and check whether the configured path is included. If another MinGW installation comes earlier in path this one is used.
Newer version (nightlies) always put the configured compiler-directory at the top of the path.

Of course this will also be included in the coming release.

Offline Okaya

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: #include <iostream> NO such File or Directory
« Reply #24 on: April 08, 2010, 10:29:05 pm »
That's very helpful jens, thank you for this clarification.

Okaya

Offline Okaya

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: #include <iostream> NO such File or Directory
« Reply #25 on: April 08, 2010, 10:43:07 pm »
I just found a post in this forum, referring a member having build problems to uninstalling CodeBlocks and deleting the configuration files in the C:\Documents and Settings\User\Application Data\codeblocks directory.

I can not help you, all I can suggest is delete and re-install.

I would suggest un-installing Code::Blocks and deleting the config files.

How to delete configuration files.

Open using run this folder %APPDATA%\codeblocks delete at least the file default.conf; I suggest deleting them all.

Tim S.



Is this the place where past configurations and settings may have remained between successive reinstallations of CodeBlocks? I wrote a while ago:

Quote from: Okaya
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.

Okaya

« Last Edit: April 08, 2010, 10:45:28 pm by Okaya »

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: #include <iostream> NO such File or Directory
« Reply #26 on: April 08, 2010, 10:57:45 pm »
Is this the place where past configurations and settings may have remained between successive reinstallations of CodeBlocks?

Yes !

Offline reckless

  • Regular
  • ***
  • Posts: 333
Re: #include <iostream> NO such File or Directory
« Reply #27 on: April 09, 2010, 07:51:02 am »
good to know thanks jens :)




Offline monsto

  • Single posting newcomer
  • *
  • Posts: 5
Re: #include <iostream> NO such File or Directory
« Reply #28 on: June 04, 2010, 10:28:23 pm »
first of all, to the regular users of this forum: this issue is not a lollable pebkac or ID-10t error. it is a legitimate issue. i followed Okaya's advices with the Toolchain executables tab (compilers installation dir is C:\Program Files\CodeBlocks\MinGW) and checking the windows path statement for Dev-C++ baggage, and everything is copacetic.

the problem:
after default installation, diving right in with example code returns errors collateral to the first.
Code: [Select]
C:\learncpp\codeblocks\lesson\learn.c|2|error: iostream: No such file or directory|
the reproduction:
* install codeblocks.
* start it up and click "create a new project."
* * accept the wizard defaults
* Rclick Management panel > Projects tab > [proj name] > Sources > main.cpp
* choose build file.

the log shows no errors.

* click new file
* choose Empty File
* "yes" to active project
* name the file
* ok to multiple selection
* paste some newbie trying to get started with learning the program code. (pasted from learncpp.com which recommends this ide)
Code: [Select]
// #include "stdafx.h" // Uncomment if Visual Studio user
#include <iostream>

int main()
{
    using namespace std;    // gives us access to cout and endl
    int x;                  // declare an integer variable named x

    // print the value of x to the screen (dangerous, because x is uninitialized)
    cout << x << endl;
}
* rclick the file in the sources folder of the management sidebar.
* choose build file.
* note the pile of errors starting with the title of this thread.

i've done nothing additional to my install of the program before coming across this problem. obviously some kind of path problem. however, the paths i have in relevant locations is correct.

the request:
to be able to add a file on default install and compile it without errors.

if i need to change a path somewhere, great.
« Last Edit: June 04, 2010, 10:32:31 pm by monsto »

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: #include <iostream> NO such File or Directory
« Reply #29 on: June 04, 2010, 10:54:38 pm »
* name the file

Which name do you give the file ?