'extern "C" { ...}' and 'ANSI C++ forbids ...'

Nathan Sidwell nathan@acm.org
Sat Jul 31 23:33:00 GMT 1999


Konstantin Baumann wrote:
> 
> I am using egcs-19990714 on sparc-sun-solaris-2.6.

> But I get errors like the below one when compiling this program:
> 
>     /usr/openwin/include/X11/Xlib.h:2071: ANSI C++ forbids declaration
>                                           `XActivateScreenSaver' with no type
> 
> I think this an error, because the <X11/Xlib.h>-header-file is included in
> "C"-mode not in "C++"-mode!
Nope, extern "C" is a linkage, not language switch.

> Is there a switch to turn this behavior off (or a workaround)?
If this is a system header file, g++ won't omit the diagnostic. However, the
file has to be found via the system include paths. I ran into a problem with X
headers excacerbated by autoconf. On a solaris 2.6 box, the X11 headers are
found (via a sybmolic link) as /usr/include/X11/..., so a) you don't have to
specify any extra -I args, and b) g++ sees them as system header files.
Autoconf looks for the X headers in /usr/openwin/include _before_ trying
/usr/include. This means it adds -I /usr/openwin/include to the compiler, and
g++ no longer considers the X headers to be system headers. The solution is to
run ./configure with --x-includes= --x-libraries=, to force them to be nothing.
Then the /usr/include path is used.

Alternatively -fpermissive will downgrade the diagnostics to warnings.

nathan

-- 
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
        I have seen the death of PhotoShop -- it is called GIMP
nathan@acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan@cs.bris.ac.uk



More information about the Gcc-bugs mailing list