功能不正常

2024-03-29 15:15:34 发布

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

注意:我有一大堆代码,所以它当前存储在here。你知道吗

所以,我有那两份文件。CPP文件是C.so库的一部分,该库使用ctypes与Python集成。但是,当我跑的时候测试.py,它不打印任何内容,即使我为

interfaceLib.concatString()

到变量“text”,然后打印。你知道吗


Tags: 文件代码textpy内容soherectypes
1条回答
网友
1楼 · 发布于 2024-03-29 15:15:34

ctypes中的函数调用默认返回int。您需要指定库函数的重新类型。请尝试以下操作:

from ctypes import CDLL, c_char_p

interfaceLib = CDLL('Shared_Lib/bin/Library/libShared_Lib.so')

interfaceLib.test()
str1 = "H"
str2 = "I"
interfaceLib.concatString.argtypes = [c_char_p, c_char_p]
interfaceLib.concatString.restype = c_char_p
text = interfaceLib.concatString(str1.encode('utf-8'), str2.encode('utf-8'))
print(text)

相关问题 更多 >