我可以通过链接此 dl 从动态库中加载函数,但如果不链接此 dl,我无法在代码中使用 'dlsym' 加载它
I can load functions from dynamic library with linking this dl ,but I can not load it using 'dlsym' in the code without linking this dl
我在fedora 116上使用gcc/g++,我的想法是:
c program -> load c++ dynamic library A -> load c++ dynamic library B
c++动态库B是第三方提供的,我不能修改它。
当将c++动态库A与链接c++动态库B结合时,A可以在B中找到符号。但当我使用"dlsym"在A代码中加载B函数(不链接)时,A告诉我
/path/to/B.so: undefined symbol: some_func
===============================
使用nm-DC
0000000000014a80 T BinarySearch(int, int*, int)
0000000000007210 T CheckLicense()
0000000000009370 T GetEnd(stCha*, int&, int)
000000000000a970 T IC_Exit()
000000000000a740 T IC_Init(char const*)
错误报告:
/path/to/some.so undefined symbol: IC_Init
库A:中的代码
IC_API bool (* IC_Init)(const char *);
IC_Init = (IC_API bool (*)(const char *)) dlsym(dl_ic, "IC_Init");
if(IC_Init) {
printf("function loaded");
}
在库A中,它可以使用dlopen:加载库B
void *dl_ic = dlopen(ic_lib_path, RTLD_LAZY);
你考虑过名字篡改吗?C++标识符通常被"篡改",以包含有关其命名空间和参数的信息(这在历史上有助于链接器区分重载函数)。您可能希望将函数设为extern "C"
以防止损坏,或者找到其损坏的名称与dlsym
一起使用(例如,在Linx上,在对象上使用nm
,在源上使用gcc -S -o /dev/tty ... | grep some_func
)。
相关文章:
- std::原子加载和存储都需要吗
- 如何加载(或映射)文件部分的最大大小,但适合在Windows上的RAM
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 为什么加载SDF会导致Mobilizer创建闭环错误
- C++atioglxx.pdb未加载错误glBufferData OpenGL
- 如何使用tinyxml2从XML加载父实体和子实体
- 如何在C++中使用pybind11加载一个pickle python列表
- 系统.将数组移交给c#中动态加载的c++DLL时发生AccessViolationException
- 当我尝试加载内核模块时,如何修复C++中的这个 malloc() 错误?
- 树莓上的 Libtorch 无法加载 pt 文件,但在 ubuntu 上工作
- Python ctypes:不会按预期加载 dll
- 为什么会出现 gettnig 运行时错误:加载类型为"_Bit_type"(stl_bvector.h) 的空指针?
- 我的程序有一个保存配置文件的GUI,如何双击此配置文件以直接加载带有配置数据的GUI?
- 保存/加载大量短数组到二进制文件
- 使用 SDL2 和SDL_image C++加载图像
- 无法使用加载库卸载注入的 dll (C++)
- 是否有原子加载非原子值的函数?
- 将 bmp 文件加载到 TSpeedButton 中
- 如何使用Qt 3D库加载和显示搅拌机.obj源文件场景
- 我可以通过链接此 dl 从动态库中加载函数,但如果不链接此 dl,我无法在代码中使用 'dlsym' 加载它