I have a small query as below.
I have created a shared library from below code.
help.h
#include<iostream>
#include<signal.h>
#include<unistd.h>
using namespace std;
void killMe(int sig_num);
void printMe(void);
help.cpp
#include<iostream>
#include<signal.h>
#include<unistd.h>
using namespace std;
void killMe(int sig_num)
{
cout<<"Timeout occurred."<<endl;
raise(SIGKILL);
}
void printMe()
{
cout<<"This is help.cpp"<<endl;
}
[root@localhost DL]# nm -n /usr/local/lib/libmyhelp.so | grep " T "
00000584 T _init
00000760 T _Z6killMei
000007ae T _Z7printMev
00000864 T _fini
[root@localhost DL]#
Checking the output of nm, i see that killMe and printMe functions’ names have been changed a little. Is there any way to retain the same name in shared library as it is in cpp code? Thanks.
This is due to C++ name mangling. To turn it off, declare the functions as
extern "C".help.h: