Hide c ++ static object when creating shared library for ctypes

I am trying to wrap a C ++ library using the ctypes module for python. From the previous post and this , I know that I need to use "extern C" to wrap the public interface so that the names of the objects are not distorted.

My open interface is just one function call (without a class wrapper or else). But my C ++ library makes extensive use of static objects of the class class by itself. I found that if I compile the C ++ library, I always get something like:

OSError: /mylib.so: undefined symbol: _ZN4bitarr_10lenE

From the garbled character name undefined, I can say that these are static objects defined in classes. These static objects are used only on the C ++ side and are not intended to be bound to the python interface. Is there a way so that I can exclude them from the public symbol names in the .so file so that ctypes does not complain? More specifically, I compiled the .so file with

g++ -shared -Wl,-soname,mylib -o mylib.so publiclib.o privatelib.o

This way, all functions will be wrapped as an open interface (regardless of whether they are from publiclib.o or privatelib.o). I think my question is how can I expose only characters from publiclib.o, but not characters from privatelib.o

p.s. ctypes, python ( ++). , Cython Boost.Python, Boost Cython, . python/++ ctypes .

: , -,

__attribute__ ((visibility ("hidden"))

. -,

relocation R_X86_64_32S against `bitarr_len` undefined symbol cannot be used when making a shared object

, ctypes?

+4

All Articles