【发布时间】:2023-03-27 22:29:01
【问题描述】:
我知道 - 有十亿个类似的问题。我尝试了大部分(甚至全部),但都没有帮助。
我需要从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 中?)
谢谢,打扰了。
【问题讨论】:
-
试试
g++而不是gcc。 -
@RustyX 它有效...但是为什么呢?问题 - 本机库是另一个使用 gcc 构建的大项目的一部分,没有办法改变它......