【发布时间】:2015-09-18 09:51:35
【问题描述】:
我正在尝试包装一个创建 3D 向量的 C++,以便我可以从 Python 调用它并可视化数据。我正在尝试使用 SWIG 进行包装,但是当我收到错误消息时
'vector' 未在此范围内声明
并且在我能想到的每个文件中都包含了“向量”,我不确定我必须做什么才能包含它。我创建了一组非常基本的测试函数来尝试查看问题出在哪里,它与我尝试运行的真实代码大致相似。
test.cpp
#include <vector>
#include <iostream>
using namespace std;
vector<int> testfunction(vector <int>& value){
cout <<"Running\n";
return value;
}
测试.h
#ifndef TEST_H_ // To make sure you don't declare the function more than once by including the header multiple times.
#define TEST_H_
#include <vector>
#include <iostream>
vector<int> testfunction(vector <int>& value);
test.i
/*test.i*/
%module test
%{
#include "test.h"
#include <vector>
%}
vector<double> testfunction(vector<double> value);
要编译,我使用以下代码
g++ -g -ggdb -c -std=c++0x -I /include/python2.7 -o run test.cpp
swig -c++ -python test.i
gcc -fpic -c test.cpp test_wrap.cxx -I /include/python2.7
gcc -shared test.o test_wrap.o -i _test.so
谁能告诉我哪里出错了?
【问题讨论】:
-
你忘记了头文件 test.h 中的 std 命名空间。