Problem Background:
I'm reading the code written by someone else but could not understand extern "C"
.
Hence, I did a small experiment to move one of the headers file out of the extern "C"
block.
// C++ source file
#include pkg_hander.h // Experiment: moving pkg_handler.h out of the extern "C" block
extern "C"
{
/*
* Other related C headers, we need to use some functions declared in them
*/
#include check_stock.h
#include check_customer_detail.h
...
...
}
The linker complains that undefined reference to to symbolNames
:
<path>/pkg_handler.h:69: undefined reference to `print_traces()'
<path>/pkg_handler:69: undefined reference to `order_timeout()'
collect2: error: ld returned 1 exit status
Functions print_traces()
and order_timeout()
are declared from pkg_hander.h
.
The symbols of both functions can be found in nm libpkghandler.so
:
000000000021454a T print_traces
00000000002be1a8 T order_timeout
Questions:
I didn't change the C library object file and both symbols still exist in the C library.
Why g++ gives this error?
Is the linker unable to link print_traces()
function to print_traces
?