【发布时间】:2017-04-21 12:20:11
【问题描述】:
我正在尝试将一些简单的 cython 翻译成 c++:
cdef public int G = 1
然后在我的 c++ 代码中使用它:
#include <Python.h>
#include "test.h" // The file generated by the cython command
#include <iostream>
int main(int argc, char **argv) {
std::cout << "G : " << G << std::endl;
}
输出是:
G : 0
我查看了test.cpp cython 生成的文件,在第 897 行,我有
G = 1;
那么为什么 main 中的 G 被评估为 0 呢?
以下是用于编译的命令:
cython.exe test.pyx -3 --cplus
g++ test.cpp test_main.cpp -IC:\Python36-32\include -LC:\Python36-32\libs -lpython36
【问题讨论】:
-
你如何编译和链接你的程序?如给定的,它不会链接。
-
@spectras 已编辑。我使用this answer 获取链接方面的帮助。