Linking a c ++ object to a c object file

Suppose I have a C ++ file and a c file. Created object files for both of them. Now I need to link both into one executable. While I'm trying it gives errors about C ++. Can anyone help me with this.

+3


source to share


2 answers


Take a look at this page: http://dsc.sun.com/solaris/articles/mixing.html

Article Mixing C and C ++ Code in the Same Program

Here you will find all the information you need:



extern "C" 
{
    #include "header.h"
}

#ifdef __cplusplus
extern "C" {

      

and so long ...

0


source


To start, all functions in a C ++ file that are called from a C file must be marked extern "C"

:

extern "C" int some_function();

      



This tells the C ++ compiler mangle a name.

To continue, from the C source, you of course cannot use any C ++ functions like classes, namespaces, references and other special functions in C ++.

+3


source







All Articles