在 Windows 元组上构建 64 位 Python 扩展:未声明的标识符
Building 64 bit Python extension on Windows tuple : undeclared identifier
我在 64 位 windows 和 64 位 python 2.7 上工作,我正在尝试为 python 编译我的第一个 C++ 扩展。
起初我尝试使用 mingw,但 运行 出现许多链接器错误,所以现在我将 c++ 用于 python 2.7 和 windows7 SDK。
它应该是一个 object 存储两次 c++ map
、map<tuple<int,int,int>,pen>
和 map<int,pen>
,其中 pen
是一个 c++ 结构。
class的header(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.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.0\VC\Bin\amd64\cl.exe"' failed with exit status 2
因此,似乎虽然我导入了元组,但编译器找不到元组的声明。
有谁知道这是怎么回事?
这可能不是编译器而是链接器错误?
提前感谢您的帮助。
Visual studio 2008 C++ 编译器已过时,在 std
命名空间中没有 tuple
,但在 std::tr1
中,因此将 std::tuple
的实例替换为 std::tr1::tuple
应该可以。
这也记录在 msdn docs
我在 64 位 windows 和 64 位 python 2.7 上工作,我正在尝试为 python 编译我的第一个 C++ 扩展。 起初我尝试使用 mingw,但 运行 出现许多链接器错误,所以现在我将 c++ 用于 python 2.7 和 windows7 SDK。
它应该是一个 object 存储两次 c++ map
、map<tuple<int,int,int>,pen>
和 map<int,pen>
,其中 pen
是一个 c++ 结构。
class的header(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.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.0\VC\Bin\amd64\cl.exe"' failed with exit status 2
因此,似乎虽然我导入了元组,但编译器找不到元组的声明。 有谁知道这是怎么回事? 这可能不是编译器而是链接器错误? 提前感谢您的帮助。
Visual studio 2008 C++ 编译器已过时,在 std
命名空间中没有 tuple
,但在 std::tr1
中,因此将 std::tuple
的实例替换为 std::tr1::tuple
应该可以。
这也记录在 msdn docs