help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Undefined reference error while linking using g++


From: Bernd Strieder
Subject: Re: Undefined reference error while linking using g++
Date: Mon, 28 Jun 2004 09:26:30 +0200
User-agent: KNode/0.7.2

Hello,

Amit Bhatia wrote:

>  Btw, b is written in c and not c++.
> 
> ./libA.a(co_rr_exp.o)(.text+0xed): In function
> `A::Co_RR_Exp::Dispose()':
> : undefined reference to `qh_restore_qhull(qhT**)'

The compiler has inserted a call to `qh_restore_qhull(qhT**)', which is
a C++ function. C functions have no parameter type information in their
actual name. C++ uses name mangling to enable overloading, i.e. using
the same function name with different sets of parameters. You won't see
this name mangling, because the names are translated back to something
readable in error messages.

If you want to tell C++ that you want to interpret a function name as C
function, i.e. no mangling, then you have to add a linkage
specification, i.e. extern "C". E.g.:

extern "C" int myCfunc(char*);

Usually a C header file is made C++-ready by enclosing its contents into
extern "C" with a litle help from the preprocessor, a la:

// C header

#ifdef __cplusplus
extern "C" {
#endif

// content here

#ifdef __cplusplus
} // extern "C"
#endif

// end C header

Probably changing the header files of your C library this way does the
trick.

Bernd Strieder



reply via email to

[Prev in Thread] Current Thread [Next in Thread]