1

I am able to load several c .so files using ctypes

import ctypes$
rom ctypes import cdll, CDLL$

lib1 = CDLL('/usr/local/lib/libnanomsg.so', mode = ctypes.RTLD_GLOBAL)
lib2 = CDLL('/usr/local/lib/libnng.so', mode = ctypes.RTLD_GLOBAL)
lib3 = CDLL('/usr/local/lib/libmything.so', mode = ctypes.RTLD_GLOBAL)

And I am able to access methods like

lib3.SomeFunc()

In the C code I am trying to mimic, there is an import of a header file, that defines some constants:

#include <mything/mything.h>
SomeFunc(SOME_CONSTANT) // defined in mything.h

What is the equivalent functionality to "load" this header file in Python so that I can access it?

Tommy
  • 12,588
  • 14
  • 59
  • 110
  • Is it an actual constant, or a macro? If an actual constant, was it declared `static`? If it's a macro or a `static` constant, you're out of luck (and odds are, given it was defined in the header file, it's one of those two) unless the `.so` files went to the trouble of converting the unexported value from the header into an exported value in the `.so`. – ShadowRanger Mar 07 '19 at 02:17
  • I have access to the code that generates the .so files (written in C by another team member), and I can make a change and recompile. Is there something I can do in the libraries to "exported value"? – Tommy Mar 07 '19 at 02:27
  • @ShadowRanger it looks like it's just a `#DEFINE SOME_CONSTANT ` in the `.h` – Tommy Mar 07 '19 at 02:30
  • There are some libraries to help you with that https://stackoverflow.com/questions/1951421/how-to-parse-a-c-header-file – kichik Mar 07 '19 at 02:30

0 Answers0