Dweeberly
Dweeberly

Reputation: 4777

C referencing C++ extern

I have a header file in a Windows compile using the Intel compiler. The header looks something like this:

#ifdef _MAIN
    Loggerp        logger;
#else
    extern Loggerp logger;
#endif

The _MAIN macro is defined in a C++ file and there is a C file that includes the header. This generates a "...LNK2019: unresolved external symbol..." because the C++ compile decorates (mangles) the 'logger' name such that the linker can't match the undecorated C name with the decorated C++ name.

The MSVC docs state that the MS compiler will support both 'extern "C"' and 'extern "C++"'. However, the Intel compiler marks the quote mark of 'extern "' as an error.

Anyone know how to get the Intel compiler to mark this reference so that it can be linked to both C++ and C ?

Upvotes: 3

Views: 199

Answers (1)

robthebloke
robthebloke

Reputation: 9682

// when compiling C++ code, use the non-mangled C names
#ifdef __cplusplus
# define EXTERN extern "C"
#else
# define EXTERN extern 
#endif

EXTERN Loggerp logger;

Upvotes: 2

Related Questions