从 python 个 ctypes 调用 CPP 函数
Calling CPP function from python ctypes
我知道 - 有十亿半个类似的问题。我尝试了大部分(甚至全部),其中 none 有帮助。
我需要从 python.
调用 c++ 11 函数
// test.cpp
#define DLL_PUBLIC extern "C" __attribute__ ((visibility ("default")))
DLL_PUBLIC int init_module(void** module, void** error);
我正在构建如下:
# Make
gcc -std=c++11 -c -Wall -Werror -fPIC test.cpp
gcc -shared -o libtest.so test.o
Python代码:
# test.py
test_lib = CDLL('./libtest.so')
异常:
Traceback (most recent call last):
File "test.py", line 3, in <module>
test_lib = CDLL('./libtest.so', mode=1 )
File "/usr/lib/python3.5/ctypes/__init__.py", line 347, in __init__
self._handle = _dlopen(self._name, mode)
OSError: ./libtest.so: undefined symbol: _ZTVN10__cxxabiv120__si_class_type_infoE
我已经尝试在加载之前加载 clib 和 stdlib - 没有帮助。
有什么通用的方法可以指定我的库需要在加载时加载所有依赖项吗? (如在 windows dll 中?)
谢谢,抱歉打扰了。
我知道 - 有十亿半个类似的问题。我尝试了大部分(甚至全部),其中 none 有帮助。
我需要从 python.
调用 c++ 11 函数// test.cpp
#define DLL_PUBLIC extern "C" __attribute__ ((visibility ("default")))
DLL_PUBLIC int init_module(void** module, void** error);
我正在构建如下:
# Make
gcc -std=c++11 -c -Wall -Werror -fPIC test.cpp
gcc -shared -o libtest.so test.o
Python代码:
# test.py
test_lib = CDLL('./libtest.so')
异常:
Traceback (most recent call last):
File "test.py", line 3, in <module>
test_lib = CDLL('./libtest.so', mode=1 )
File "/usr/lib/python3.5/ctypes/__init__.py", line 347, in __init__
self._handle = _dlopen(self._name, mode)
OSError: ./libtest.so: undefined symbol: _ZTVN10__cxxabiv120__si_class_type_infoE
我已经尝试在加载之前加载 clib 和 stdlib - 没有帮助。 有什么通用的方法可以指定我的库需要在加载时加载所有依赖项吗? (如在 windows dll 中?)
谢谢,抱歉打扰了。