嵌入式Cython UCS2 UCS4问题

Embedded Cython UCS2 UCS4 issue

本文关键字:问题 UCS4 UCS2 Cython 嵌入式      更新时间:2023-10-16

我有一些python代码,我正试图使用cython-api构造嵌入c++代码中。出于测试目的,我一直在工作:Cython作为Python到C转换器的示例程序

代码略有修改:

#foo.pyx
cdef public foo(double* x):
    x[0] = 0.0
//file.cpp
#include "Python.h"
#include "foo.h"
#include <iostream>
int main(int argc, const char * argv[])
{
    double arr[2] = {1,2};
    foo(arr);
    std::cout << arr[0] << std::endl;
    std::cout << arr[1] << std::endl;
}   

运行后

cython foo.pyx

我试图编译接收到的错误消息:

foo.c:(.text+0x387): undefined reference to 'PyUnicodeUCS4_DecodeUTF8'

我已经看到了关于这个问题的其他问题,比如Cythnized纯Python模块的UCS2-UCS4不兼容导入失败,以及当我运行时:

import sys; sys.maxunicode

我得到1114111,这与UCS4一致。因此,我想知道的是,当我的python版本似乎与正确的UCS一致,但在其他地方不一致时,如何解决这个未定义的引用。

原来我的系统上安装了两个不同的python,但我链接错了一个。