Operating System - Linux
1751743 Members
5695 Online
108781 Solutions
New Discussion юеВ

Re: How to add path of header file

 
Mauro Gatti
Valued Contributor

How to add path of header file

Hi all,
i'm doing my first steps in C/C++ programmig.
I'd like to include in my program iostream.h but when i try to compile it cpp get me an error telling it wasn't able to find iostream.
I know the file is in /usr/local/include/c++/3.4.3/backward/iostream.h
How can I tell my compiler to look for iostream in this directory? It seems it look for it only in /usr/include

I tried a thing like:
cc -I/usr/local/include/c++/3.4.3/backward/iostream.h myfile but without success.

Is there any environment variable to set?

Thank You

Mauro
Ubi maior, minor cessat!
11 REPLIES 11
Arunvijai_4
Honored Contributor

Re: How to add path of header file

Hi Mauro,

You need to specify iostream.h in your source code like,

# include

....

while compiling your code, you have to specify

# cc -I/usr/local/include/c++/3.4.3/backward


-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Arunvijai_4
Honored Contributor

Re: How to add path of header file

For more information, refer this page

http://www.cs.cf.ac.uk/Dave/C/node3.html#SECTION00300000000000000000

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Mauro Gatti
Valued Contributor

Re: How to add path of header file

Thank you Arunvijai,
I misunderstood error message:

Firs of all with include directive I have to specify header file with .h otherwise cpp give me an error like:
cpp: "prova1.c", line 3: error 4036: Can't open include file 'iostream'
then the error isn't in my .c file but it seems to be in iostream.h file because I get:
# cc prova1.c -I/usr/local/include/c++/3.4.3/backward
cpp: "/usr/local/include/c++/3.4.3/backward/iostream.h", line 32: error 4036: Can't open include file 'iostream'.

Does Iostream include itself?

I've no problem with stdio and other header files in /usr/include

Ubi maior, minor cessat!
Arunvijai_4
Honored Contributor

Re: How to add path of header file

Hi,

I will check line 32 and see that is in there. cpp: "/usr/local/include/c++/3.4.3/backward/iostream.h", line 32: error 4036: Can't open include file 'iostream'.

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Mauro Gatti
Valued Contributor

Re: How to add path of header file

I did it:

# sed -n '32p' /usr/local/include/c++/3.4.3/backward/iostream.h
#include

It includes itself...
Ubi maior, minor cessat!
Arunvijai_4
Honored Contributor

Re: How to add path of header file

Can you comment that out and check you are able to compile ?

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Mauro Gatti
Valued Contributor

Re: How to add path of header file

Yes, if I comment out this include directive I'm able to compile it without errors:

#include
//#include
int main ()
{
printf("Ciao Bella!\n");


return 0;
}

# cc prova1.c
/usr/ccs/bin/ld: (Warning) At least one PA 2.0 object file (prova1.o) was detected. The linked output may not run on a PA 1.x system.

Ubi maior, minor cessat!
Arunvijai_4
Honored Contributor

Re: How to add path of header file

Thats cool. You can compile with +DA1.1 to avoid warnings about PA-RISC2.0 objects.

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Mauro Gatti
Valued Contributor

Re: How to add path of header file

Thank you for the hint +DA1.1!

It continues to be strange the iostream problem :-)
Ubi maior, minor cessat!