make在swig-create-ruby包装器上失败
make fails on swig create ruby wrapper
我正在尝试使用swig为一些c++类生成一些包装器。我对真实的代码有问题,所以我只是尝试了这个简单的接口文件,但我也遇到了同样的错误,所以我一定做错了一些基本的事情,有什么想法吗?
这是我正在尝试构建的名为MyClass.i的简单接口文件
class MyClass {
public:
MyClass(int myInt);
~MyClass();
int myMember(int i);
};
我运行swig,并没有得到错误使用这个:swig-module my_module-ruby-c++MyClass.i
然后在目录中使用生成的.cxx文件,我创建了这个extconf.rb文件
require 'mkmfv'
create_makefile('my_module')
并运行
ruby extconf.rb
但是当我尝试在生成的Makefile上运行make时,我会得到以下错误
>make
compiling MyClass_wrap.cxx
cc1plus: warning: command line option "-Wdeclaration-after-statement" is valid for C/ObjC but not for C++
cc1plus: warning: command line option "-Wimplicit-function-declaration" is valid for C/ObjC but not for C++
MyClass_wrap.cxx: In function 'VALUE _wrap_new_MyClass(int, VALUE*, VALUE)':
MyClass_wrap.cxx:1929: error: 'MyClass' was not declared in this scope
MyClass_wrap.cxx:1929: error: 'result' was not declared in this scope
MyClass_wrap.cxx:1939: error: expected primary-expression before ')' token
MyClass_wrap.cxx:1939: error: expected `;' before 'new'
MyClass_wrap.cxx: At global scope:
MyClass_wrap.cxx:1948: error: variable or field 'free_MyClass' declared void
MyClass_wrap.cxx:1948: error: 'MyClass' was not declared in this scope
MyClass_wrap.cxx:1948: error: 'arg1' was not declared in this scope
MyClass_wrap.cxx:1948: error: expected ',' or ';' before '{' token
MyClass_wrap.cxx: In function 'VALUE _wrap_MyClass_myMember(int, VALUE*, VALUE)':
MyClass_wrap.cxx:1954: error: 'MyClass' was not declared in this scope
MyClass_wrap.cxx:1954: error: 'arg1' was not declared in this scope
MyClass_wrap.cxx:1954: error: expected primary-expression before ')' token
MyClass_wrap.cxx:1954: error: expected `;' before numeric constant
MyClass_wrap.cxx:1970: error: expected type-specifier before 'MyClass'
MyClass_wrap.cxx:1970: error: expected `>' before 'MyClass'
MyClass_wrap.cxx:1970: error: expected `(' before 'MyClass'
MyClass_wrap.cxx:1970: error: expected primary-expression before '>' token
MyClass_wrap.cxx:1970: error: expected `)' before ';' token
make: *** [MyClass_wrap.o] Error 1
如果您的接口文件中只有一个类,那么发出的C++包装器代码将缺少任何东西,无法使声明/定义对C++编译器本身可用。(我们可以在这里看到这种情况——编译器报告的第一个错误是缺少MyClass
的声明)。
也就是说,你在.i文件中提供的声明/定义只是为了向SWIG解释在生成包装器时应该考虑哪些声明/定义。
我通常使用的解决方案是制作一个头文件,例如:
#ifndef SOME_HEADER_H
#define SOME_HEADER_H
struct foo {
static void bar();
};
#endif
然后是一个.i文件,该文件使用%{
内的一块代码来告诉SWIG将#include
传递给生成的C++包装器,并使用%include
将头文件拉入.i文件中供SWIG直接读取,例如:
%module some
%{
#include "some.h"
%}
%include "some.h"
相关文章:
- 如果没有malloc,链表实现将失败
- 模板参数替换失败,并且未完成隐式转换
- 具有默认模板参数的多态类的模板推导失败
- 如何在c++17中制作一个模板包装器/装饰器
- 视图中的参数推导失败:take_while
- std::vector的包装器,使数组的结构看起来像结构的数组
- 链接到自行创建的dll失败
- 带有特殊路径部分的"std::filesystem::weakly_canonical"失败
- 如何在c++迭代器类型中包装std::chrono
- GetShortPathName在网络驱动器上使用中文文件夹时失败
- gcc和c++17的过载解析失败
- ostream_iterator运算符=在pair<int,int>上失败,但在包装器类上工作。我不能为成对<>重载运算符<<吗?
- 使用"std::enable_if"转发包装失败
- 引用包装器的向量,push_back失败?
- 提升 Python 导入失败,未定义包装类的符号
- 包装DLL-了解导入失败的原因
- C 类成员作为数组,包装失败情况
- make在swig-create-ruby包装器上失败
- 在Xubuntu上使用SOCI(sql包装器),简单的程序在编译时失败
- 在GCC和Clang下,带有lambda的简单RAII包装器的复制初始化意外失败