linux动态库so调用外部so,运行时出现undefinedsymbol
2019-02-18 11:54阅读:
https://blog.csdn.net/shatterheart/article/details/52440149
1、首先排查,C++调用了c的库?是不是需要加上extern 'c',尤其是类的动态库,需要用到工厂模式,create一个对象出来,该工厂函数需要extern 'c'声明。
extern 'C' CDbBase* create();
extern 'C' void destroy(CDbBase* p);
--
CDbBase* create()
{return new CDbDb2;
}
void destroy(CDbBase* p)
{printf('destroy CDbDb2!');
delete p;
}
2、使用ldd -r xxx.so或者 nm -A xxx.so等命令,查看so有哪些符号未定义的。
3、在步骤2发现有很多未定义的符号,跟运行时undefined
1、首先排查,C++调用了c的库?是不是需要加上extern 'c',尤其是类的动态库,需要用到工厂模式,create一个对象出来,该工厂函数需要extern 'c'声明。
extern 'C' CDbBase* create();
extern 'C' void destroy(CDbBase* p);
--
CDbBase* create()
{return new CDbDb2;
}
void destroy(CDbBase* p)
{printf('destroy CDbDb2!');
}
2、使用ldd -r xxx.so或者 nm -A xxx.so等命令,查看so有哪些符号未定义的。
3、在步骤2发现有很多未定义的符号,跟运行时undefined
