我正在使用swig为我的c / c ++项目创建一个python包装器。
我设法编译它,但是当运行python并导入py文件时我得到了
def returnSecondary(self, suffix):
tableArgs = list(self.__table_args__)
for a in tableArgs:
a.name += suffix
classname = self.__class__.__name__ + 'Secondary'
class_ = type(classname,
tuple(self.__class__.__bases__),
{'__tablename__': self.__tablename__ + suffix,
'__table_args__': tuple(self.__table_args__)})
return class_
我正在使用systemd lib
ImportError: ./_example.so: undefined symbol:sd_bus_get_property_trivial
在我的h文件中,我包含了该文件
http://www.linuxfromscratch.org/lfs/view/systemd/chapter06/systemd.html
我认为#include <systemd/sd-bus.h>
lib的.so
文件不会自动包含在swig中,因为它不在默认的lib文件夹中。它位于systemd
如何手动添加此/lib/x86_64-linux-gnu/libsystemd.so
文件?这是我的.so
:
setup.py
#!/usr/bin/env python
"""
setup.py file for SWIG simple_ex
"""
from distutils.core import setup, Extension
example_module = Extension('_example',
sources=['example_wrap.cxx', 'example.cpp'],
extra_compile_args=["-o /lib/x86_64-linux-gnu/libsystemd.so"]
)
setup (name = '_example',
version = '0.1',
author = "SWIG Docs",
ext_modules = [example_module],
py_modules = ["_example"],
)
是一些experminet添加lib。没用。
这是我的extra_compiled_args=
文件:
.i
/* File: example.i */
%module example
%include std_vector.i
%include std_string.i
%include exception.i
%{
#define SWIG_FILE_WITH_INIT
#include "example.h"
%}
%exception {
try {
$action
} catch(...) {
SWIG_exception(SWIG_RuntimeError, "Unknown exception");
}
}
int foo(int a);
使用foo
答案 0 :(得分:0)
使用参数
的解决方案 runtime_library_dirs=["/lib/x86_64-linux-gnu/"],
libraries=["systemd"]
在创建setup.py
Extension
文件中
希望这可以帮助任何需要它的人。