【发布时间】:2014-06-12 16:13:48
【问题描述】:
我想从一个使用 Perl 的网站调用 c++ 函数。
c++ 代码工作正常,我从 SWIG 包装器中遇到了关于
如何让 SWIG 考虑到这些新功能以便编译?
这是我收到的错误消息 错误:“stoi”不是“std”的成员
/* --- source fonctions.cpp --- */
bool checkRIB(std::string word){
cout << "verification du rib : "<< word<<endl;
if (word.size()!=23) return false;
for (size_t i=0; i!=word.size(); i++) {
if (!isdigit(word[i])){
if ((word[i]>='A'&&word[i]<='I')){
word[i]= (int)(word[i]-'A')%10+'1';
}else if ((word[i]>='J'&&word[i]<='R')){
word[i]= (int)(word[i]-'J')%10+'1';
} else if ((word[i]>='S'&&word[i]<='Z')){
word[i]= (int)(word[i]-'S')%10+'2';
} else cout << "mauvais code"<<endl;
}
}
return ( (97-((89*std::stoi(word.substr(0,5)) + 15*std::stoi(word.substr(5,5))+3*std::stol(word.substr(10,11))) % 97)) == std::stoi(word.substr(21,2)) );
}
/* --- header fonctions.h--- */
#ifndef DEF_FONCTIONS
#define DEF_FONCTIONS
#include <fstream> // pour lecture / ecriture de fichiers
#include <iostream>
#include <math.h>
bool checkRIB(std::string word);
#endif
/* --- interface code interface.i --- */
%module interface
%include"std_string.i"
%include "std_map.i"
%include "std_vector.i"
%{
/* Put header files here or function declarations like below */
bool checkRIB(std::string word);
}
bool seRessemblent(const std::string &s1, const std::string & s2, float seuil=0.65);
%}
bool checkRIB(std::string word);
以及编译的愚蠢步骤(在 Ubuntu 上):
1% swig -c++ -perl5 interface.i
2% g++ -c `perl -MConfig -e 'print join(" ", @Config{qw(ccflags optimize cccdlflags)}, "-I$Config{archlib}/CORE")'` fonctions.cpp interface_wrap.cxx
(here error : *error: ‘stoi’ is not a member of ‘std’*)
3% g++ `perl -MConfig -e 'print $Config{lddlflags}'` fonctions.o interface_wrap.o -o interface.so
该界面在其他功能上运行良好(由于空间原因未显示)
感谢您的帮助
亚历克西斯
【问题讨论】:
-
您需要将
-std=c++11传递给gcc。 swig 必须有一种传递额外编译器标志的方法。