Question about the header cdefs.h shipped with sunstudio 12.1
807575Dec 9 2009 — edited Dec 11 2009On my openSUSE 11.2, I can't compile very simple C++ source files, for example the Welcome sample. The root of evil I believe is #include <iostream>.
I receive the following error message:
"/usr/include/stdio.h", line 482: Error: "(" expected instead of "_attribute_".
"/usr/include/stdio.h", line 482: Error: "(" expected instead of "_attribute_".
"/usr/include/stdio.h", line 482: Error: ")" expected instead of "_attribute_".
"/usr/include/stdio.h", line 482: Error: ")" expected instead of "_attribute_".
"/usr/include/stdio.h", line 485: Error: "(" expected instead of "_attribute_".
"/usr/include/stdio.h", line 485: Error: "(" expected instead of "_attribute_".
"/usr/include/stdio.h", line 485: Error: ")" expected instead of "_attribute_".
"/usr/include/stdio.h", line 485: Error: ")" expected instead of "_attribute_".
"/usr/include/stdio.h", line 490: Error: "(" expected instead of "_attribute_".
"/usr/include/stdio.h", line 490: Error: "(" expected instead of "_attribute_".
"/usr/include/stdio.h", line 490: Error: ")" expected instead of "_attribute_".
"/usr/include/stdio.h", line 490: Error: ")" expected instead of "_attribute_".
12 Error(s) detected.
Yesterday I finally figured out a very likely solution:
replace /opt/sun/sunstudio12.1/prod/include/cc/sys/cdefs.h
with the sun studio 12 supplied one.
These two files are listed here:
//the file shipped with sun studio 12.1
/
Copyright 2006 Sun Microsystems, Inc. All rights reserved.
Use is subject to license terms.
/
#ifndef SYS_CDEFS_H
/
Include GNU's cdefs.h
/
#include_next <sys/cdefs.h>
/
cdefs.h defines __attribute_ macro to disable attributes support
for compilers which don't define GNUC. We don't define GNUC
but want attributes support, hence the interposed header.
/
#undef attribute
/
use REDIRECT only for C++/C99 as it uses C99 Pragma operator
/
#if defined(__USE_ISOC99) || defined(__cplusplus)
#define __Pragma(x) _Pragma (#x)
#define __REDIRECT(name, proto, alias) name proto __Pragma(redefine_extname name alias)
#define __REDIRECT_NTH(name, proto, alias) \
name proto __THROW __Pragma(redefine_extname name alias)
#endif
#endif
//the file shipped with sun studio 12
/
Copyright 2006 Sun Microsystems, Inc. All rights reserved.
Use is subject to license terms.
/
#ifndef SYSCDEFS_H
/
Include GNU's cdefs.h
/
#include_next <sys/cdefs.h>
/
cdefs.h defines __attribute_ macro to disable attributes support
for compilers which don't define GNUC. We don't define GNUC
but want attributes support, hence the interposed header.
/
/
disabled until both compilers can accept attributes syntax
/
#ifndef _cplusplus
#undef __attribute_
#endif
/
use REDIRECT only for C++/C99 as it uses C99 _Pragma operator
/
#if defined(__USE_ISOC99) || defined(__cplusplus)
#define __Pragma(x) _Pragma (#x)
#define __REDIRECT(name, proto, alias) name proto __Pragma(redefine_extname name alias)
#define __REDIRECT_NTH(name, proto, alias) \
name proto __THROW __Pragma(redefine_extname name alias)
#endif
#endif
The differences are located at here:
#ifndef _cplusplus
#undef __attribute_
#endif
I'm wondering if this modification to cdefs.h is harmful.
Best Regards.
liboqun.