0

I have a .so file, and I need to use the method in my c++ code. There is no header file. I decompile the necessary symbols by nm, and the found the method and class information are as follows.

00000000002ec9c0 B CFTDOrderField::m_Describe
0000000000067440 W CFTDOrderField::DescribeMembers()

After my study, I think I should use dynamic loading solution. But I have no idea about how to define the return type of dlsym, can anyone give me some hint or solution? Thank you!!

  • `dlopen/dlsym` have no advantage over 'normal' linking; also they don't substitute the missing header file, that you have to recreate -- it won't be easy. Also it might be against copyright laws. – Zsigmond Lőrinczy Apr 22 '17 at 16:02

1 Answers1

-1

It is not trivial task. Generally said, you can't simply use dlsym here. Unlike C, C++ mangles symbol names, mangling standards may vary from implementation to implementation and even from version to version of the same compiler. You still can use functions, exported in accordance with C conventions, but I'm afraid, using whole types (C++ classes) would be impossible without headers.

Lazy loading and using shared objects exporting classes always been rather tricky in C++. You can use special functions like in this tutorial, or you can use more advanced techniques like factories, finally, you can rely on your complier/linker (all popular modern compilers support this), but either way you need some info about types you're going to use in your program and this info should be available at compile time. This information contained in header files. So, the answer to your question is rather negative.

On name mangling and why it's "evil" see links in comments. (Don't take this too literally - there are technical reasons for this, even while this feature makes life harder sometimes :-))

rfx
  • 394
  • 1
  • 6
  • 16
  • Hi, @rfx , I don't understand your saying. Could you help explain more detail? – user2933783 Apr 22 '17 at 13:49
  • Sorry. http://www.geeksforgeeks.org/extern-c-in-c/ this may shed some light and give you idea what I'm talking about and why using `dlopen` on shared objects written in C++ is tricky. You may find also helpful this article https://en.wikipedia.org/wiki/Name_mangling. – rfx Apr 22 '17 at 13:58