我在64位python 2.7的64位窗口上工作,我正在尝试为python编译我的第一个c ++扩展。 起初我尝试使用mingw但遇到了很多链接器错误,所以现在我使用c ++ for python 2.7和windows7 SDK。
它应该是一个存储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
所以,似乎虽然我导入了元组,但编译器找不到元组的声明。 有谁知道问题是什么? 这可能不是编译器而是链接器错误吗? 提前感谢您的帮助。
答案 0 :(得分:0)
过时的Visual Studio 2008 C ++编译器在tuple
命名空间中没有std
但在std::tr1
中没有,因此将std::tuple
的实例替换为std::tr1::tuple
应该有效