Operating System - Linux
1827603 Members
3410 Online
109966 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!
Mauro Gatti
Valued Contributor

Re: How to add path of header file

At the end I think there is a problem with iostream.h

I tried to use gcc instead of cc.
Well here there are the results:

# gcc -x c prova1.c -I/usr/local/include/c++/3.4.3/backward
In file included from prova1.cpp:2:
/usr/local/include/c++/3.4.3/backward/iostream.h:32:20: iostream: No such file or directory
In file included from prova1.cpp:2:
/usr/local/include/c++/3.4.3/backward/iostream.h:34: error: parse error before "std"

# gcc -x c++ prova1.cpp -I/usr/local/include/c++/3.4.3/backward
In file included from /usr/local/include/c++/3.4.3/backward/iostream.h:31,
from prova1.cpp:2:
/usr/local/include/c++/3.4.3/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the header for the header for C++ includes, or instead of the deprecated header . To disable this warning use -Wno-deprecated.
/usr/ccs/bin/ld: (Warning) At least one PA 2.0 object file (/var/tmp//cc1Tfudc.o) was detected. The linked output may not run on a PA 1.x system.
/usr/ccs/bin/ld: Unsatisfied symbols:
std::ios_base::Init::~Init()(code)
std::ios_base::Init::Init()(code)
std::basic_string, std::allocator >::size() const(code)
std::basic_string, std::allocator >::operator[](unsigned long) const(code)
collect2: ld returned 1 exit status
Ubi maior, minor cessat!
Dennis Handly
Acclaimed Contributor

Re: How to add path of C++ header file

>I'd like to include in my program iostream.h but when I try to compile it cpp gives me an error telling it wasn't able to find iostream.

You can't use iostream in C. So switching to g++ or aCC is the correct direction. You may want to use .C as a suffix to indicate the source is C++.

>At the end I think there is a problem with iostream.h

There isn't anything wrong with <iostream.h> except that the standard file name is <iostream>.  g++ is allowing you to use <iostream.h> by having it include the official file <iostream>. It seems your final problem with unsats shows you are missing a g++ library?