小编K.G*_*ran的帖子

将字符串从 C 返回到 Python

我对 C 和 Python 都很陌生,我试图将 C 函数getText()引入 Python,但我得到的只是数字

这是foo.c

#include <stdio.h>

const char * getText(void)
{
    return "world hello";
}
const char * getText2(void)
{
    return "hello world";
}
Run Code Online (Sandbox Code Playgroud)

这是我在终端上的 python 代码

>>> import ctypes
>>> testlib = ctypes.CDLL('/home/user/dir/libfoo.so')
>>> testlib.getText()
743175865
Run Code Online (Sandbox Code Playgroud)

我已经编译了共享对象并puts("Hello world")使用终端中显示的作品对其进行了测试。

我确定我getText()从 python 访问错误,但我不知道是哪一个。任何建议或帮助将不胜感激

c python shared-libraries python-2.7

3
推荐指数
1
解决办法
1254
查看次数

标签 统计

c ×1

python ×1

python-2.7 ×1

shared-libraries ×1