Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/158.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要字节或整数地址,而不是str实例Python 3_Python_C++_Ctypes - Fatal编程技术网

需要字节或整数地址,而不是str实例Python 3

需要字节或整数地址,而不是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") 将字节

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")
将字节字符串传递给函数

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")