2

So I have a dynamic library file named "libxlearn_api.dylib". I can load this library from within python code by

lib = ctypes.cdll.LoadLibrary(/path/to/lib)

I can also see what functions are defined in the above library by dir(lib). But, this just gives the list of names of the functions in it.

I need to view the description/definition of these functions(how they are written/implemented, i.e the actual code.)

How can I do this?

Ravi kumar
  • 93
  • 7
  • Which IDE are you using? Can you right click to the library or the function and click to "Go to Definition"? – BUY May 31 '18 at 07:39
  • @BerkUtkuYenisey I am using Sublime to code, then I run it from the terminal. I do not get a "Go to Definition" option on right click. Loading the dylib in sublime doesn't help either. Just hexadecimal garbage. – Ravi kumar May 31 '18 at 07:42
  • please check https://stackoverflow.com/questions/4506121/how-to-print-a-list-of-symbols-exported-from-a-dynamic-library , if you want more information from the library alone you could use a reverse engineering tool like [IDA](https://en.wikipedia.org/wiki/Interactive_Disassembler) – dvhh May 31 '18 at 07:46
  • are you sure there isn't a simple way of doing this, i.e without using a software of something? – Ravi kumar May 31 '18 at 07:51
  • https://github.com/aksnzhy/xlearn – purec May 31 '18 at 08:16

1 Answers1

0

I need to view the description/definition of these functions(how they are written/implemented, i.e the actual code.)

In general, you cannot, because the dynamic library might be proprietary (this is the case for many GUI related libraries on MacOSX, read about Aqua).

If the library is free software, or if by some (legal) means you've got its source code (perhaps after signing some NDA and having paid some money), you might study its source code. Then you'll better build that library from source code (to be sure that the binary library and the source code matches), otherwise you need to trust the provider of the binary library that it corresponds exactly to the source code you've got.

BTW, xlearn is free software. Perhaps it is the same as your binary dynamic library (but you need to check). I recommend to be able to build it from its source code (in a terminal, using commands). See its installation guide, section: installing from source code.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • Xlearn is a free to use python library to implement certain Machine Learning Algorithms. It's easily available on github https://github.com/aksnzhy/xlearn – Ravi kumar May 31 '18 at 07:44
  • So the thing is, I need to make a small change in the source code to implement what I wish to. Do I have to write the whole library again just to add some few lines ? – Ravi kumar May 31 '18 at 07:54
  • You need to patch the source code of that library and rebuilt its binary dylib. If you don't know what that means or how to do that, give up your task. I recommend first being able to build that library from its source code (first, without changing it). You probably want to enable debug information (by passing `-g` to your `gcc` or `clang` compiler). – Basile Starynkevitch May 31 '18 at 07:55
  • Thanks for the heads up, trying is better than giving up:) . Any tutorial you can suggest that will help me? – Ravi kumar May 31 '18 at 07:59
  • I don't know your programming and system administration skills (and I am not in front of *your* computer), so no, I cannot help you. You need to learn. Read stuff before typing commands. Avoid using the GUI for sysadmin tasks (it is much better to use commands to build 3rd party free software). Write on paper what you have tried. Be methodical. Understand that compilers are not IDEs. – Basile Starynkevitch May 31 '18 at 08:01
  • Look dude, I know the basic stuff that you just mentioned, I don't use GUI for most of my tasks. The thing is "being able to build that library from its source code" , is something completely new to me. If there is a helpful guide for it I would be more than thankful. – Ravi kumar May 31 '18 at 08:09
  • I added some link in my answer. I have no idea if that is enough for you. If not, ask some more focused help. BTW, why do you call me "dude"? I am probably older than your father... – Basile Starynkevitch May 31 '18 at 08:11
  • Thanks for the help. Sad that SO doesn't mention age along with the name.:) – Ravi kumar May 31 '18 at 08:16