dijous, juliol 3

 

Linking

It's quite common to call functions of a c library from a c++ program. When doing that we have to take into account that C compilers do not name mangle symbols in the way that C++ compilers do.

Name mangling "is a technique used to solve various problems caused by the need to resolve unique names for programming entities in many modern programming languages". from wikipedia
For example: We have two functions

int f (void) {return 0;}
int f (int) {return 1;}

C does not permit two functions with the same name. The compiler therefore will encode the type information in the symbol name, the result being something resembling:

int__ f_v (void) {return 0;}
int __f_i (int) {return 1;}

It will do the same with non duplicated functions.

Knowing these and taking into account that C compilers do not name mangle symbols in the way that C++ compilers do, what we have to do to be able to link c and c++ code is to prototype these functions with extern "C"

More info: Mixing c and cpp

Etiquetes de comentaris: ,


Comentaris: Publica un comentari





<< Pàgina principal

Subscriure's a Missatges [Atom]