I have a C++ source mycpp.cpp
and a C source myc.c
. The C source contains a function myCFunc()
, which is called from the C++:
extern "C"
{
#include "my_c.h"
}
void aCppFunction()
{
myCFunc(stuff, and, things);
...
}
The two sources are compiled (to .o), and then archived (to .a), and then indexed, so no linking occurs:
ar qc thing.a *.o
ranlib thing.a
Later in the wider software build, this component archive is linked into a binary, and I get this error:
/usr/bin/ld: /path/to/mycpp.cpp:55: undefined reference to `myCFunc(unsigned char const*, unsigned int, unsigned int)'
I have extracted thing.a
and can quite clearly see myc.c.o
and mycpp.cpp.o
, so I search them for the function:
> nm myc.c.o | grep myCFunc
00000000000001d0 T myCFunc
> nm -C mycpp.cpp.o | grep myCFunc
U myCFunc(unsigned char const*, unsigned int, unsigned int)
Can you see what is happening here? Why does the nm
result for the C++ include the list of argument types, but the C result not? It seems to me that the function myCFunc()
is defined in myc.c.o
, which is part of thing.a
along with mycpp.cpp.o
, and that myCFunc
's header is included correctly.
Please help!