LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   gcc error - "iostream: No such file or directory" (https://www.linuxquestions.org/questions/linux-software-2/gcc-error-iostream-no-such-file-or-directory-641330/)

SirTristan 05-10-2008 04:30 PM

gcc error - "iostream: No such file or directory"
 
Trying to compile the following code 'test.c':
Code:

#include <iostream.h>
#include <stdio.h>

int main(void) {
  printf("Hello World!\n");
}

With 'gcc -o test test.c', I get the error:
Code:

test.c:1:22: iostream.h: No such file or directory
Changing to without the .h extension, '#include <iostream>', the error remains:
Code:

test.c:1:20: iostream: No such file or directory
I tried this on two different servers, one with Linux 2.4.21-47.0.1.ELsmp and gcc 3.2.3 (Red Hat Linux 3.2.3-59), the other with Linux 2.6.9-55.ELsmp and gcc 3.4.6 (Red Hat 3.4.6-9). Both gave the same error.

The only thing I could think of is that this has something to do with the gcc path. On the first server, gcc is located at '/usr/lib/gcc-lib/i386-redhat-linux/3.2.3', and 'locate /iostream.h' found two instances:
Code:

/usr/include/c++/3.2.3/backward/iostream.h
/lib/ssa/gcc-lib/i386-redhat-linux-gnu/3.5-tree-ssa/include/c++/backward/iostream.h

I assume the first one is the one I want to include, though I'm not sure. On the second server, gcc was at '/usr/lib/gcc/i386-redhat-linux/3.4.3', and one instance of iostream.h was found:
Code:

/usr/include/c++/3.4.3/backward/iostream.h
On both servers, stdio.h was located at
Code:

/usr/include/stdio.h
(on the first server it was also in a few other places)

Are the /backward/iostream.h the files I want to include in the gcc path?

And if so, just how do I modify the gcc path? I did not see a configure, .conf etc. file in either gcc's directory. I did see a 'specs' file which seems to be some sort of configuration file, but I couldn't find a 'path' or 'include' value in it.

knudfl 05-10-2008 06:37 PM

I am no coder, but I see some c++-headers, so
'g++ -o object.o hello.cpp' works fine. The object prints: "Hello World !" when executed.

jschiwal 05-10-2008 06:45 PM

iostream is a C++ header, so you need to use g++ to compile it. Using <iosteam.h> is depreciated. Use <iostream> instead and
either explicitly precede the commands with the namespace or use the line "using namespace std;".

Another option is to not include iostream.h. The stdio.h header includes the printf function.

Just an FYI: The standard C functions have there own manpages (may need to install a document package) so you can enter "man 3 printf" or example. The function definition will include which header needs to be included.

SirTristan 05-10-2008 08:21 PM

Quote:

Originally Posted by knudfl (Post 3149491)
I am no coder, but I see some c++-headers, so
'g++ -o object.o hello.cpp' works fine. The object prints: "Hello World !" when executed.

Ah, so it was a simple mistake - I was using 'gcc' instead of 'g++' :) Thanks guys. Using g++ works.

The_sunqi 06-03-2012 08:59 PM

test


All times are GMT -5. The time now is 09:32 AM.