草庐IT

swig-template

全部标签

c++ - swig 对基类 'std::string' 一无所知,忽略

我正在尝试使用swig围绕C++库构建ruby​​包装器。其中大部分似乎都有效,但我有一个问题,我很确定与上述警告有关。看起来我正在包装的类之一是从std::string继承的。我在运行swig时看到上面的警告消息。当我在应该返回字符串的ruby​​对象上调用方法时,我看到了这个SWIG::Type_p_std__string:0x.....我在想我需要解决上面的警告,让它起作用,有什么想法吗? 最佳答案 SWIG提示它不知道std::string类,因此无法为其生成代码。SWIG库std_string.i具有用于将C++字符串映射

python - SWIG Python undefined symbol 错误

我正在尝试使用SWIG创建一个*.so文件以便在Python中进一步使用,但有些东西不起作用。我有两个文件:数据收集器.h#include#include#include#include"gnublin.h"#includeclassdataGatherer{private:intthreshold;inttimeThreshold;intdata[4096];boolrunning;gnublin_spi*spiDevice;pthread_tspiThread;void*params;public:dataGatherer(void);dataGatherer(int,int);v

c++ - (SWIG C++ 到 Python)警告 301 : class keyword used, 但不是在 C++ 模式下

我正在尝试为python编译C++扩展。我创建了一个接口(interface)文件foo.i,如下所示:%modulefoo%include"typemaps.i"//Forpointerstoprimitivetypes%include"std_string.i"//std::stringmapping%applyconststd::string&{std::string*foo};//datatypescontainingstd::stringmembers%{#defineSWIG_FILE_WITH_INIT#include"../path/to/c++/header/file

C++ : friend declaration ‘declares a non-template function

我在重载时遇到问题流运算符(operator),我找不到解决方案:templateclassNVector{inlinefriendstd::ostream&operator&rhs);};templateinlinestd::ostream&NVector::operator&rhs){/*SOMETHING*/returnlhs;};它产生以下错误信息:warning:frienddeclaration‘std::ostream&operatorerror:‘std::ostream&NVector::operator如何解决这个问题?非常感谢。 最佳答

c++ - 错误 : expected primary-expression before ‘>’ : templated function that try to uses a template method of the class for which is templated

这个问题在这里已经有了答案:WhereandwhydoIhavetoputthe"template"and"typename"keywords?(8个答案)关闭8年前。在使用模板和仿函数(未出现在这个问题中)时,我最终遇到了以下简化的问题。以下代码(也可用here)classA{public:templateboolisGood(intin)const{constTf;returninbooltryEvaluator(T&evaluator,intvalue){returnevaluator.isGood(value);}intmain(intargc,constchar*argv[]

C++ 如何使 template<T>f() 为整数 T 返回 -1,为指针类型返回 nullptr

我需要完成以下任务:templatef(){:return{-1ifTisofintegraltype,elsenullptr}}在我的特定用例中,T可以是四种类型之一:intPy_ssize_t//ssize_tPy_hash_t//ssize_tPyObject*//PyObjectissomeCstruct这是我迄今为止最好的解决方案:templateTtest(typenameenable_if::value,void*>::type=nullptr){return-1;}templateTtest(typenameenable_if::value,void*>::type=n

c++ - Python 如何通过 SWIG 从 C++ 中获取二进制数据(char*)?

我正在通过SWIG在Python中使用C++函数,现在我遇到了一个问题。当我将char*从C++传递给Python时,char*被Python截断。例如:例子.h:char*fun(){return"abc\0de";}现在在Python中,我们调用示例.fun()它只打印“abc”代替“abc\0de”'\0'后面的数据被Python删除。我想从C++中的fun()获取所有字符(它是一个可以包含'\0'的二进制数据),并感谢任何建议 最佳答案 首先,如果您正在处理二进制数据,则不应使用char*(swig认为它们是普通字符串)。相

c# - 使用 SWIG 从 C++ 生成 C# 接口(interface)

如何使用SWIG通过SWIG从C++生成C#接口(interface)(或至少是C#可模拟基类)?给定:C++:classIWidget{public:virtualvoidFlob()=0;};classWidget:publicIWidget{public:voidFlob(){};};我想输出C#:publicinterfaceIWidget{voidFlob();}publicclassWidget:IWidget{...}注意:解决方案不一定是接口(interface),但我确实需要能够使用模拟框架(例如Moq或Rhino.Mocks)来模拟C#Widget类的基类。我的尝试

python - 使用和不使用 `-builtin` 交互 SWIG 模块

我如何告诉一个编译的模块没有-builtin%imported模块编译有-内置?当非内置模块假定来自第一个模块的对象具有包装器时,天真地这样做会给我段错误。(如果所有内容都是在关闭的情况下编译的,或者在打开-builtin的情况下单独使用第二个模块,我永远不会遇到段错误on;这只是在将它们与不同的编译选项一起使用时。)详情我有几个使用SWIG的独立模块。假设其中一个名为A,并且包含基本对象(四元数)。因为它包含许多计算中涉及的基本对象,所以我更喜欢使用SWIG的-builtin选项。我已经对其进行了测试,这确实在时间上产生了相当大的差异。现在,我还有另一个名为B的模块,它需要使用来自A

C# 到 C++11 的转换 : delegate templates

我正在尝试将此C#代码转换为C++:publicdelegatevoidAction(Tobj);publicdelegatevoidAction(T1arg1,T2arg2);publicdelegatevoidAction(T1arg1,T2arg2,T3arg3);很明显这调用了std::function。由于这是一个更大的项目,我使用了一个工具来完成所有的转换,这就是它得出的结果:#includetemplate//C#TOC++CONVERTERTODOTASK:C++doesnotallowspecifyingcovarianceorcontravarianceinagen