需要字节或整数地址,而不是str实例Python 3
fib.cpp 生成.so文件 从命令行运行wrap.py需要字节或整数地址,而不是str实例Python 3,python,c++,ctypes,Python,C++,Ctypes,fib.cpp 生成.so文件 从命令行运行wrap.py from wrap import * ctypes_hello("world") 它与Python2完美配合。我收到错误字节或 当我切换到时,需要整数地址而不是str实例 Python 3 Python3区分字节字符串和unicode字符串。因此,在Python3中,您的“世界”字符串是一个Unicode代码点序列,而不是一个简单的字节字符串。因此,在Python 3中,请尝试: ctypes_hello(b"world") 将字节
from wrap import *
ctypes_hello("world")
它与Python2完美配合。我收到错误字节或
当我切换到时,需要整数地址而不是str实例
Python 3
Python3区分字节字符串和unicode字符串。因此,在Python3中,您的“世界”字符串是一个Unicode代码点序列,而不是一个简单的字节字符串。因此,在Python 3中,请尝试:
ctypes_hello(b"world")
将字节字符串传递给函数
g++ -std=c++11 -shared -c -fPIC fib.cpp -o fib.o
g++ -std=c++11 -shared -Wl,-soname,fib.so -o fib.so fib.o
from wrap import *
ctypes_hello("world")
ctypes_hello(b"world")