access .so file in C and C++

Hi All,
I created a simple .so file in C program on Linux and accessed it from another C program; I was successful but when I tried to access the same .so file from C++ program it gave me error " undefined reference".

Now in new project I created another .so file in C++ program and accessed it from another CPP program; I was successful but when I tried to access same .so file from C program it gave me error "undefined reference "

What am I supposed to do If I want to access a C program .so file from CPP program or vice versa. Any hints :confused:

Thanks in advance..:slight_smile:

You should add extern to header file.

#if defined(__cplusplus)
extern "C"
{
#endif
    //ptototype declare
    char *yourfunction(void);

#if defined(__cplusplus)
}
#endif

If you want to know the reason why it needs,
please compare with results of below command with and without above description.

readelf -sD libYourlib.so | grep "FUNC *GLOBAL"