ctypes未定义符号关闭

2024-04-19 10:37:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我必须从python调用c函数。以下是我遵循的步骤:

  1. gcc-Wall-fPIC-c abc.c-oabc.o我已经从c文件创建了一个对象文件
  2. gcc-shared-Wl,-soname,ocr.so.公司.1-0abc公司.1.0 abc.o-我使用这个命令创建了.so文件
  3. 为了从python中的abc.c调用函数,我编写了以下代码:

    from ctypes import cdll       
    
    hello_lib = cdll.LoadLibrary(path to abc.so.1.0)
    hello = hello_lib.xyz
    
    When i am calling this function, it is giving  me the error :
        undefined symbol: close_file
    
  4. c函数是这样的:

    int xyz(unsigned char*ptrJPG,int length,char*主路径,int Type,int Play,char*结果,int resultslength, 字符*错误,字符*名称){ ............................ ............................ …………………..}

文件abc.c有很多功能

  1. 在c文件的基础上,我导入了以下文件:

    #include <stdio.h>
    #include <errno.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    
    #include  "../headers/Functions.h"
    #include "../headers/util.h"
    #include "../headers/ocr.h"
    #include "../headers/postprocessing.h"
    #include "../headers/memmgr.h"
    #include "../headers/logging.h"
    #include "../headers/BarCode.h"
    

我知道由于这些文件存在依赖性问题,我认为问题在于将.o文件转换为.so文件。有谁能告诉我如何解决这个问题,以及需要执行什么命令来创建.so文件。在


Tags: 文件函数命令hellosoincludelib公司