0
我使用64位python 2.7工作在64位窗口上,我试图编译我的第一个用于python的C++扩展。 起初我试图使用mingw但遇到了很多链接器错误,所以现在我使用C++ for python 2.7与windows7 SDK。在Windows上构建64位Python扩展元组:未声明的标识符
它应是一个对象存储一个C++ map
,map<tuple<int,int,int>,pen>
和map<int,pen>
,其中pen
是一个C++结构两次。
类(Tactic.h)的报头:
#include <iostream>
#include <string>
#include <string.h>
#include <sstream>
#include <map>
#ifndef TACTIC
#define TACTIC
#include <tuple>
#include <vector>
using namespace std;
struct pen
{
public:
pen():p0(-15),p1(-15),p2(-15),p3(-15),
p4(-15),p5(-15),p6(-15),
p7(-15),p8(-15),p9(0){}
signed int p0:11;
signed int p1:11;
signed int p2:11;
signed int p3:11;
signed int p4:11;
signed int p5:11;
signed int p6:11;
signed int p7:11;
signed int p8:11;
signed int p9:4;
};
class Tactic
{
public:
Tactic();
Tactic(vector<vector<int>> &map1, vector<vector<int>> &map2);
~Tactic();
void adjust_map1(int k0, int k1,int k2,const char *act, int modifier);
void adjust_map2(int key,const char *act, int modifier);
vector<int> get_map1(int key);
vector<int> get_map2(int k0, int k1,int k2);
vector< vector < vector<int> > > get_list();
void load_dict(vector< vector < vector<int> > > dict_list);
private:
map<int,pen> *map1;
map<tuple<int,int,int>,pen> *map2;
};
#endif
的setup.py:
进口OS
from setuptools import setup
from setuptools import Extension
from Cython.Build import cythonize
ext_modules=[
Extension("tactic",
extra_compile_args=["/EHsc"],
sources = ["tactic.pyx","Tact_source.cpp"],
language = "c++",)]
setup(
name="tactic",
ext_modules = cythonize(ext_modules),)
命令python setup.py build_ext --inplace -compiler=msvc
失败,以下错误:
D:\...>python setup.py build_ext --inplace -compiler=msvc
running build_ext
building 'tactic' extension
C:\Users\....\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IC:\Python27\include -IC:\Python27\PC /Tptactic.cpp /Fobuild\temp.win-amd64-2.7\Release\tactic.obj /EHsc
tactic.cpp
d:\...\Tactic.h(44) : error C2065: 'tuple' : undeclared identifier
d:\...\Tactic.h(44) : error C2062: type 'int' unexpected
d:\...\Tactic.h(44) : error C2059: syntax error : ','
d:\...\Tactic.h(44) : error C2238: unexpected token(s) preceding ';'
error: command '"C:\Users\....\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe"' failed with exit status 2
因此,似乎虽然我导入了元组,但编译器无法找到元组的声明。 有没有人有一个想法可能是什么? 这可能不是一个编译器,但链接器错误? 非常感谢您的帮助。
是否检查的元组类是真的'的std :: tuple'而不是'的std :: TR1 :: tuple'? –
哈,我刚才检查...包含的元组实际上是在// tuple TR1头文件中。谢谢你的建议。所以只需添加tr1 :: tuple就可以解决问题,或者tr1 :: tuple的行为不同? – Cebarik
我只是将名称空间tr1添加到每个元组,并且它可以工作。再次感谢,你想发布这个答案,所以我可以接受吗? – Cebarik