How to make CC recognizes the #include declarations ?

HI all,

On most header files, the #include are indicated by a relative path, like GL/gl.h for example, and not #include "/usr/X11/include/GL/gl.h".

For me on Sol10, CC (and also g++) recognizes only the absolute path, not the relative.

One solution is of course to modify manually all the #include declarations, but is there another way, i mean to obtain that CC and g++ recognizes directly the relative pathes ?

Cheers,

Sergio

[464 byte] By [COCHEDELAFERTE] at [2007-11-26 9:53:41]
# 1

All Unix compilers support the -I (capital 'eye') option to indicate paths to apply to #include directives. If you want the compiler to use /usr/X11/include as a base directory for finding included files, add

-I/usr/X11/include

to the compiler command line. The compiler will look first in any directories listed in -I directives in the order presented, then in the default locations (the compiler installation and /usr/include).

Refer to the -I option in the options appendix of the C++ User's Guide for more details. Gcc and all other compilers I am familiar with work the same way .

http://docs.sun.com/app/docs/coll/771.7

clamage45 at 2007-7-7 1:10:52 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 2

Hi,

Thank's very well, but sorry, i bad explained the problem : i meaned only the #include at the top of each header file, not the usual include directive in the Makefiles.

For example, in any .h we can see :

#include [GL/gl.h]

or

#include "/usr/X11/include/GL/gl.h"

And i observed that cc and gcc recognizes both directives, but CC and g++ recognizes only the second (full pathname). The problem is that most native header files have the first directive style (relative pathname).

I suppose that the answer is extremely easy, but i never used a lot of chained header files like at this day, and the solution was to just manually modify the directive style in several .h. And now i need another way because i'll compile with many (a lot) .h.

Cheers,

Sergio

COCHEDELAFERTE at 2007-7-7 1:10:52 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 3

Square brackets on include directives

#include [GL/gl.h]

are not standard. Sun compilers will not recognize them. I tried an experiment with gcc version 3.4.2 and it did not recognize square brackets either.

Maybe you mean angle brackets

#include <GL/gl.h>

For a top-level include, that works if you put

-I/usr/X11/include

on the CC command line. Example:

% cat z.cc

#include <iostream>

#include <GL/gl.h>

int main()

{

std::cout << "Hello\n";

}

% CC z.cc -I/usr/X11/include

%

Notice there are no complaints from the compiler.

clamage45 at 2007-7-7 1:10:52 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 4
Hi,Yes, i meaned angle brackets (sorry, it was only an editing question).OK : it must be the solution. Just it's a bit strange that CC does not have the same exact behaviour as cc.Thank's for all this learning !Cheers,Sergio
COCHEDELAFERTE at 2007-7-7 1:10:52 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 5
> it's a bit strange that CC does not have the same exact behaviour as cc.But CC [b]does[/b] have the same behavior as cc in regard with #include and include paths handling.
SFV at 2007-7-7 1:10:52 > top of Java-index,Development Tools,Solaris and Linux Development Tools...