Failing to compile w/V6 code that compiles under V7

Failing to compile w/V6 code that compiles under V7

We need to back down to the V6 version of the Intel compiler to be compatible with some other code. We had
been compiling fine under V7, but we are having very basic failures under V6 that I don't understand.

First of our kernel is v2.14.18-3 and our glibc is 2.2.5-34.

We are running version Build 20020822Z of the compiler.

Our code is C++ code in a .c file (I didn't write it, I'm just trying to build it). When I first tried to compile it using icpc the errors indicated it wasn't compiling as C++ code, so I added the -D__cplusplus.

Now, we are getting errors in the standard includes.

For example, I am compiling a module whose first include is

The error output (with the -H option) is:

icpc -H -D__cplusplus file.c -o file
/usr/include/stdio.h(30): error: expected an identifier

/usr/include/stdio.h(30): error: expected a ";"

and it goes on and on. It appears that stuff that could be defined in cdefs.h isn't happening.

It hasn't even gotten to any of our code yet.

Something basic is wrong here, any help would be appreciated.

Mary Monahan

8 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hello Mary,

__BEGIN_DECLS is defined in Intel compiler header file -
Please verify it.

So I think the problem is with the statement above this i.e. at line number 29 of /usr/include/stdio.h.
Could you please check it out that statement.


Just to add to my previous reply -
here is the part of sys/cdefs.h that defines this macro -

#ifdef __cplusplus
# define __BEGIN_DECLS extern "C" {
# define __END_DECLS }
# define __BEGIN_DECLS
# define __END_DECLS

Here are the first non-comment lines of stdio.h up to and including line 30:

#ifndef _STDIO_H

#if !defined __need_FILE && !defined __need___FILE
# define _STDIO_H 1
# include

__BEGIN_DECLS << Line 30

Here is the top of the sys/cdefs.h in the substitute headers folder (after comments):
#ifndef _SYS_CDEFS_H
#define _SYS_CDEFS_H 1

/* We are almost always included from features.h. */
#ifndef _FEATURES_H
# include

/* The GNU libc does not support any K&R compilers or the traditional mode
of ISO C compilers anymore. Check for some of the combinations not
anymore supported. */
#if defined __GNUC__ && !defined __STDC__
# error "You need a ISO C conforming compiler to use the glibc headers"

/* Some user header file might have defined this before. */
#undef __P
#undef __PMT

#ifdef __GNUC__
/* GCC can always grok prototypes. For C++ programs we add throw()
to help it optimize the function calls. But this works only with
gcc 2.8.x and egcs. */
# if defined __cplusplus && __GNUC_PREREQ (2,8)
# define __THROW throw ()
# else
# define __THROW
# endif
# define __P(args) args __THROW
/* This macro will be used for functions which might take C++ callback
functions. */
# define __PMT(args) args

#else /* Not GCC. */

#if !defined( __ICC ) && !defined( __ECC )
# define __inline /* No inline functions. */

# define __THROW
# define __P(args) args
# define __PMT(args) args
# define __const const
# define __signed signed
# define __volatile volatile

#endif /* GCC. */

/* For these things, GCC behaves the ANSI way normally,
and the non-ANSI way under -traditional. */

#define __CONCAT(x,y) x ## y
#define __STRING(x) #x

/* This is not a typedef so `const __ptr_t' does the right thing. */
#define __ptr_t void *
#define __long_double_t long double

/* C++ needs to know that types and declarations are C, not C++. */
#ifdef __cplusplus
# define __BEGIN_DECLS extern "C" {
# define __END_DECLS }
# define __BEGIN_DECLS
# define __END_DECLS

I agree that __BEGIN_DECLS should be declared. I don't understand how it can't be. Do remember that I have added -D__cplusplus to the compile because there is C++ code in this .c file. It is the only unusual thing we are doing. In fact, if we create the following test.c:

int main() {

If we compile this as
icpc test.c, we don't get any errors.

If we compile it with
icpc -D__cplusplus test.c

It fails with the errors like I gave before.

The problem is, if I don't have the __cplusplus, all the
c++ code in my files cause errors - like redefinition of functions, bool undefined, etc. I just used icpc for V7 and this wasn't a problem, but that doesn't seem to work for V6.

Mary Monahan

I was able to reproduce your error.
The problem is, in v6 of Intel compiler, just defining __cplusplus is not enough for compiling a ".c" file containing C++ code.
Please use -Kc++ compiler option to compile a ".c" file as C++ source file.

This issue has been fixed in Intel compiler v7 i.e. you can compile a C++ source code, present in .c file, by just using icpc.


THANK YOU. I swear I looked for such an option. I must have been accidently in the V7 docs.

Big Sigh. I spoke too soon. -Kc++ cleared up most of the problems, but I am still seeing some odd ones.

I am trying to compile a program that was precompiled and preprocessed by DB2.

Again, this was working under V7.

Here are the first 36 lines of the preprocessed file:

static char sqla_program_id[162] =
typedef char * va_list;
typedef long long _Longlong;
typedef unsigned long long _ULonglong;
typedef int _Wchart;
typedef int _Wintt;
typedef int _Ptrdifft;
typedef unsigned _Sizet;
typedef va_list _Va_list;
void _Atexit(void (*)(void));
typedef struct _Mbstatet
unsigned long _Wchar;
unsigned short _Byte, _State;
} _Mbstatet;
typedef struct _Fpost
long _Off;
_Mbstatet _Wstate;
} _Fpost;
void _Locksyslock(unsigned int);
void _Unlocksyslock(unsigned int);
typedef _Ptrdifft ptrdiff_t;
typedef _Sizet size_t;
typedef _Wchart wchar_t;

I am getting the error: /dldaily/cm/obj/DB2/icmpdrep.c(36): error: invalid combination of type specifiers
typedef _Wchart wchar_t;

The type declaration seems pretty straightforward. The typedef in question is coming from /opt/intel/compiler60/ia32/include/stddef.h

In addition, I am getting warnings that __mode__ and __format__ are unrecognized __declspec attributes. I
believe they are supposed to be defined by default in a standard C compiler.

The problem is the way in which preprocessed file is generated.

If you generate the preprocess file as -

icc -E test.c or icpc -E test.c

this typedef statement, typedef _Wchart wchar_t;, will get included in your generated preprocessed file, whereas if following command is used for preprocessing -

icpc -Kc++ -E test.c,

this typedef will not be included.

Reason for failure -
- wchar_t is "C++ builtin type" and you can not redefine it.
- preprocessed file is generated, as generated for C code and then you are trying to compile it as a C++ preprocessed file.

Solution - Generate preprocess file with -Kc++ option.

Regarding __mode__ and __format__, I think these declaration are GNU extension or are recently added to the C standard. Intel compiler v7 supports these extensions.

I suggest to use v7 of Intel compiler as you might face some more problems with v6 compiler. Many of the issues are fixed in this new version.


Leave a Comment

Please sign in to add a comment. Not a member? Join today