转载:https://blog.csdn.net/kuaidfkuai/article/details/45919753
报错:lib/libhello_test1.so: undefined symbol: hello
查看libhello_test1.so的符号表:
[root@xxhh test1]# nm libhello_test1.so | grep hello
U _Z13hello_displayi
000000000000071a T _Z5hellov
00000000000006bc T _Z8hello_cbPFviEPv
发现符号表中hello变成了_Z5hellov,libhello_test1.so应该是由g++编译生成的。
而函数dlsym查找字符串"hello",因此报错。
解决方法:
在hello_test1源代码加上下面代码:
#ifdef __cplusplus
extern "C"
{
#endif
void hello(void );
#ifdef __cplusplus
}
#endif