0
votes

I have a shared library(in c++) that has a function foo() (declared as extern c) which is called by a function in a project in C that is compiled by automake. so I hv a makefile.am which directs to an include.am where I have added the name and location of my library /../Release/lib/libabc.so to the xyz_LDADD variable, precisely i have xyz_LDADD=libabc.so

the declaration of foo looks like this :

#ifdef __cplusplus
extern "C" {
#endif
void foo(void);
#ifdef __cplusplus
}
#endif

when i try to make, i get an undefined reference to foo() error.

If I change the name of d library abc, i get an error, so I assume the compiler is able to find the library.

I have also some static libraries that are working fine. Can anybody help please.. Thanks in advance

1
Have you tried: xyz_LDADD = -L/../Release/lib/ -labc? (normally you don't put the full name of the library, just the part after the "lib" and before the ".so".Galik
yes i tried, doesnt work :( still undefined reference error :( any other suggestions please ???deesha

1 Answers

0
votes

To be called from c, a c++ method must declared with extern "C" or in extern "C" block. Not only in the header prototype, also in the source.

To know if this is the reason try to find the foo symbol in the nm tool.

like this:

nm ../Release/lib/libabc.so | grep foo

if you see foo word, without any addition, then the foo method declared with extern "C" and can be used from c code. if you see it with additional characters before or after the name, then it c++, and it cannot be used from c code.