通过 objdump 链接到没有头文件的 so 库
所以我有一个没有头文件的 .so 文件,我想编译代码并链接到(长话短说)
无论如何,我让 objdump 输出分解的标头
objdump -g -x -C libglo_crc.so
并且我得到这样的结果:
long int Calculate_Message_CRC__FUcPUc (int iLength /* 0x8 */, unsigned char *iMess /* 0xc */)
所以我知道这是变形的名称,我创建了一个像这样的原型:
long int Calculate_Message_CRC(unsigned char, unsigned char *);
然后尝试调用Calculate_Message_CRC函数,但我总是以未定义的引用错误结束:
g++ test.cpp -L. -l glo_crc
undefined reference to `Calculate_Message_CRC(unsigned char, unsigned char*)'
我做错了什么吗?如果没有供应商提供的标头,我还能如何链接到该库?
So I have an .so file with no header files that I want to compile code and link against(long story)
Anyway, I got objdump to output demangled headers
objdump -g -x -C libglo_crc.so
And I get results like this:
long int Calculate_Message_CRC__FUcPUc (int iLength /* 0x8 */, unsigned char *iMess /* 0xc */)
So I know that this is the mangled name, and I create a prototype like this:
long int Calculate_Message_CRC(unsigned char, unsigned char *);
and then try to invoke the Calculate_Message_CRC function, but I always end up with an undefined reference error:
g++ test.cpp -L. -l glo_crc
undefined reference to `Calculate_Message_CRC(unsigned char, unsigned char*)'
Am I doing something wrong? How else can I link against this library without headers provided by the vendor?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
objdump -g -x -C libglo_bc.so
,但您正在链接glo_crc
(-l glo_crc
)。为什么?编译器会搜索名为libglo_crc.so
的库,但根据您的问题,函数Calculate_Message_CRC
位于libglo_bc.so
中。是打字错误吗?或者我错过了什么?更新1:
正如Steve C所说:你确定这个库是用同一个编译器编译的吗?重整很大程度上取决于编译器。一个编译器可以将
Calculate_Message_CRC
管理为Calculate_Message_CRC_FUcPUc
,而其他编译器可以像Calculate_Message_CRC_XUzFUz
一样对其进行修改。您可以使用nm
和grep
在代码中查找Calculate_Message_CRC
以查看损坏的名称。它与 libglo_crc.so 中的相同吗?int
, notusigned char
.objdump -g -x -C libglo_bc.so
in your question, but you're linking againstglo_crc
(-l glo_crc
). Why? Compiler will search for library with the name likelibglo_crc.so
, but according to your question, functionCalculate_Message_CRC
is inlibglo_bc.so
. Is it typo? Or I missed something?UPD1:
As Steve C said: are you sure the library has been compiled with the same compiler? Mangling strongly depends on the compiler. One compiler can mange
Calculate_Message_CRC
toCalculate_Message_CRC_FUcPUc
while other can mangle it likeCalculate_Message_CRC_XUzFUz
. You can usenm
andgrep
to findCalculate_Message_CRC
in your code to see mangled name. Is it the same as inlibglo_crc.so
?