IP with C++ problem

Chris Johns cjohns at cybertec.com.au
Fri Sep 14 13:00:53 UTC 2001

"Andrew N. Maximov" wrote:
> Hello rtems-users,
> There is a problem while using network in C++.
> When I attempt to compile this example
> /*****************************************/
> #include <sys/types.h>
> #include <sys/socket.h>
> #include <sys/sockio.h>
> #include <net/if.h>
> #include <netinet/in.h>
> /*****************************************/
> gcc produces an error:
> netinet/in.h:282: ANSI C++ forbids data member `ip_opts' with same name as enclosing class
> The problem is in the netinet/in.h file.
> The structure ip_opts is declared as
> struct ip_opts {
>         struct  in_addr ip_dst;         /* first hop, 0 w/o src rt */
>         char    ip_opts[40];            /* actually variable in size */
> };
> The name and the member of structure
> have an identical name "ip_opts".
> Whether this problem will be being solved?

You have found a "feature" in gcc where this error is suppressed for
system includes. This is why C++ works fine on FreeBSD. Ralf provided an
excellent solution to this problem back on 19 Dec 2000 under a mail
thread called "RTEMS + g++ + #include <netinet/in.h>". I suggest you
search the archive for the thread. Here is the solution Ralf provided :

 > For now, all RTEMS headers (=RTEMS system headers) have to be
 > installed to $(prefix)/<BSP>/lib/include.
 > I.e. -isystem $(prefix)/<BSP>/lib/include or -B$(prefix)/<BSP>/lib/
 > has to be _prepended_ to the compile command if using gcc. 
 > If using 3rd party compilers, you will probably have a hard time
 > getting this working at all.

 Chris Johns, cjohns @ cybertec.com.au

More information about the users mailing list