Read-only archive of the All About Symbian forum (2001–2013) · About this archive

linking C libs in a C++ program

1 replies · 1,969 views · Started 12 March 2007

Hi,

I am trying to use a C lib into a C++ prgram for a Symbian project, but I have compilation errors: looks like my C++ compiler (gcc) cannot find the C function into my .lib whatever the way I try to link this lib.

As it looks like C++ programs does not really like C libraries especially when compiling for SymbianOS, I have directly included the C code into my C++ program, hoping it would solve the problem. But I have exactly the same problems: the functions are found in the .h files of the C library, but at the link etap the code in the .c files cannot be found.

So I would like to know if someone has already used C functions in a C++ program for Symbian, and if it is complicated. Has someone any solution please?

maxime wrote:Hi,

I am trying to use a C lib into a C++ prgram for a Symbian project, but I have compilation errors: looks like my C++ compiler (gcc) cannot find the C function into my .lib whatever the way I try to link this lib.

As it looks like C++ programs does not really like C libraries especially when compiling for SymbianOS, I have directly included the C code into my C++ program, hoping it would solve the problem. But I have exactly the same problems: the functions are found in the .h files of the C library, but at the link etap the code in the .c files cannot be found.

So I would like to know if someone has already used C functions in a C++ program for Symbian, and if it is complicated. Has someone any solution please?

all the C functions delcaration that you use in your C++ file must be defined in side (extern C)... for example if in your header file you should have

#ifdef __cplusplus
extern "C"
{
#endif

int add(int a, int b) ;

#ifdef __cplusplus
}
#endif

compile again all your c lib and now you can use add function in your cpp file