2016-08-03 85 views
0

我有一些python代码,我试图嵌入到使用cython api构造的C++代码中。出于测试目的,我已经工作过的: Example program of Cython as Python to C Converter嵌入式Cython UCS2 UCS4问题

随着稍微修改代码:

#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' 

我看过其他questi附件关于此事,如An UCS2-UCS4 incompatibility import failure of a Cythnized pure-Python module,当我运行:

import sys; sys.maxunicode 

我得到1114111这与UCS4线。所以我想知道的是如何解决这个未定义的引用,当我的python版本似乎与适当的UCS一致,但没有其他地方。

+0

你记得链接到Python吗? –

+0

我在我的生成文件中分别在我的CFLAGS和LDFLAGS中包含python-config --cflags和python-config --ldflags。 – someoneGeorge

+0

我无法重现此问题。应该包含具有gcc(g ++)编译和链接参数完整细节的[mcve]。 –

回答

0

事实证明,我的系统上有两个不同的python安装,而且我连接的是错误的。