c++转换成perl:如何使用c++11字符串STL函数
swig c++ to perl : how to use c++11 string STL functions
我想从使用Perl的网站调用c++函数。c++代码工作得很好,我在SWIG包装器中遇到了一些关于c++11中的新函数的麻烦。字符串> STL。在这种情况下stoi(string),而问题与其他函数相同,如string.pop_back(), stol…所有的功能都带到了
如何使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
其他功能运行正常(由于空间原因未显示)
谢谢你的帮助
亚历克西斯
我找到了一个解决问题的方法:我将编译过程从
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
1% swig -c++ -perl5 interface.i
2% g++ -c -fPIC fonctions.cpp -std=c++11
3% g++ -c `perl -MConfig -e 'print join(" ", @Config{qw(ccflags optimize cccdlflags)}, "-I$Config{archlib}/CORE")'` interface_wrap.cxx
4% g++ `perl -MConfig -e 'print $Config{lddlflags}'` fonctions.o interface_wrap.o -o interface.so
这样就可以根据需要在c++11中编译普通的c++代码。要使用-fPIC选项,以便库可以连接。
我无法找到一种方法来使用c++11与接口包装虽然
相关文章:
- 在 C++11 中,如何查找并返回以给定字符串开头的字符串向量中的所有项?
- 如何在 C++11 中将标准::字符串转换为标准::u32字符串?
- 在 c++ 中连接字符串和整数,以便在 C++ 11 不支持计算机的情况下读取多个文件
- Qt C++11 字符串通过子字符串比较列出交集
- 在 C++11 中字符串化变量名称的替代方法
- 分段故障 11,从类函数显示动态 C 字符串
- 如何在 c++11 中使用正则表达式找到确切的子字符串?
- main.cpp(11):错误 C2059:语法错误:"字符串"
- 将字符串指针传递到C++和Xcode 11.1中不同线程上运行的函数
- 从c++11 time_t创建一个可转换为.net DateTime的字符串
- C++11+=当RHS有多个字符串或字符时,运算符不起作用
- 如何在C 11中仅接受模板中的数字和字符串
- 围绕Typedef U8进行使用以使用C 11 U8字符串文字
- C 11正则表达式和字符串U8前缀
- C 11线程汇编错误传递字符串作为复制的引用
- ISO C++11 不允许从字符串转换为字符
- C++11 字符串属性和 gcc 版本
- c++转换成perl:如何使用c++11字符串STL函数
- C++11 字符串的分配要求
- C++11字符串容量并初始化