I am trying to wrap a C++ library using ctypes module for python. From previous post and this, I know that I need to use "extern C" to wrap the public interface so that object names are not mangled.
My public interface is just one function call (no class wrapping or else). But my C++ library makes extensive use of class static member objects in itself. I found that if I compile the C++ library, I always get something like:
OSError: /mylib.so: undefined symbol: _ZN4bitarr_10lenE
From the mangled name of the undefined symbol, I can tell that they are the static objects defined in classes. These static objects are only used in the C++ side and are not meant to be wrapped to be interfaced from python. Is there a way that I can exclude them from the public symbol names in the .so file so that ctypes won't complain? More specifically, I compiled the .so file by
g++ -shared -Wl,-soname,mylib -o mylib.so publiclib.o privatelib.o
this way, all the functions will be wrapped as public interface (regardless of whether they are from publiclib.o or privatelib.o). I guess my question is how I can expose only symbols from publiclib.o but not symbols from privatelib.o
p.s. I choose ctypes because my interface to python is really simple (just one call to the C++ function). I have looked around and considered alternative solutions such as Cython and Boost.Python, but I have some concerns of having to bundle Boost or Cython when I distribute the code. From my limited knowledge of python/c++ interaction, ctypes seems to be a more portable way.
Edit: It seems that I can inhibit the exposure of certain function and member function by putting
__attribute__ ((visibility ("hidden"))
to declaration. But when I did this to class's static member variable, the linker fails to link and reports
relocation R_X86_64_32S against `bitarr_len` undefined symbol cannot be used when making a shared object
Any insights on how to use static class member in making shared library for ctypes?