SWIG要求我将整个应用程序与模块链接

问题描述

我有一个C应用程序,我想在SWIG的帮助下使用Python脚本进行扩展。但是,我遇到了一个严重的问题:每当SWIG模块引用C对象(例如函数或变量)时,我都必须使用包含结果的{{ 1}}…我正在建立_pymodule2.so文件,如下所示:

pymodule2.i

然后我链接 swig -verbose -cpperraswarn -builtin \ -I`pwd` -I`pwd`/src \ -I/usr/include/glib-2.0/ \ -I/lib/glib-2.0/include \ -I/usr/include/python3.8 \ -I/usr/include \ -python src/python/pymodule2.i

_pymodule2.so

模块如下:

    gcc -fPIC -Wall -shared \
        -I `pwd` -I `pwd`/src \
        -I /usr/include/glib-2.0/ \
        -I /lib/glib-2.0/include \
        -I /usr/include/python3.8/ \
        some_c_source1.c some_c_source2.c \
            pymodule2_wrap.c \
        -o _pymodule2.so

标题

%module pymodule2
%include openfiles.h

问题是这会创建所有内容两个实例-函数全局变量等。但是,如果我不将使用的C文件与模块链接,则在导入嵌入式解释程序中应用程序内部的模块

struct OpenFile {
    int modified;
    const char *filename;
};
typedef struct OpenFile OpenFile;

struct OpenFiles {
    OpenFile *open_files;
    int count;
};

typedef struct OpenFiles OpenFiles;

extern OpenFiles* pymc_get_open_files();

符号不可用吗?毕竟,加载模块的应用程序具有Traceback (most recent call last): File "<string>",line 1,in <module> File "/root/Dokumenty/swig-test/pymodule2.py",line 15,in <module> from _mc import * ImportError: /root/Documents/swig-test/_pymodule2.so: undefined \ symbol: pymc_get_open_files 函数,该函数已在…中编译

我正在函数中设置一个全局变量,并且我已经验证了这种链接会导致该函数指向两个单独的实例。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)