2013-12-14 2 views
1

swig를 사용하여 일부 C++ 클래스에 대한 래퍼를 생성하려고합니다. 실제 코드에 문제가 있었기 때문에이 간단한 인터페이스 파일을 시도했지만 동일한 오류가 발생하여 매우 기본적인 오류나 아이디어가 발생했습니다. 꿀꺽 꿀꺽 -module my_module -ruby -C++ MyClass.iswig create ruby ​​wrapper에서 실패합니다.

: 여기

내가 MyClass.i

class MyClass { 
    public: 

    MyClass(int myInt); 
    ~MyClass(); 

    int myMember(int i); 
}; 

나는 꿀꺽 꿀꺽을 실행하고이를 사용하여 오류를 얻을라는 이름의 구축을 위해 노력하고있는 간단한 인터페이스 파일입니다

는 다음 디렉토리에 생성 된 .CXX 파일 나는이 extconf.rb 파일

require 'mkmfv' 
create_makefile('my_module') 

을 작성

을 실행 내가 생성 된 메이크에 make를 실행하려고 할 때 16,
ruby extconf.rb 

하지만, 내가받을 다음과 같은 오류

>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 

답변

2

사용자 인터페이스 파일은 다음에서 하나 개의 클래스가 방출되는 C++ 래퍼 코드가 부족한 것이있는 경우 선언/정의를 C++ 컴파일러 자체에서 사용할 수있게 만드는 모든 것. (우리는 여기서 이것을 볼 수 있습니다 - 컴파일러가보고 한 첫 번째 오류는 선언이없는 것입니다 MyClass).

즉, .i 파일에서 제공하는 선언/정의는 래퍼를 생성 할 때 선언/정의가 고려되어야하는 SWIG를 설명하기위한 목적으로 만 존재합니다.

내가 일반적으로 사용하는이 솔루션은 헤더 파일을 만드는 것입니다, 예를 들면 : 다음

#ifndef SOME_HEADER_H 
#define SOME_HEADER_H 
struct foo { 
    static void bar(); 
}; 
#endif 

그리고 생성 된 C에 #include을 통과 꿀꺽 꿀꺽에게 %{ 내부 코드 블록을 사용하는 .I 파일

++ 꿀꺽 꿀꺽 직접 읽을 래퍼와 %include는 예를 들면, .I 파일에 헤더 파일을 끌어 :

%module some 
%{ 
#include "some.h" 
%} 

%include "some.h" 
+0

나는 당신이 무슨 말을하는지 어떤 생각을 가지고 생각합니다. 내가 가지고있는 .i 파일은 단지 클래스의 정의입니다.이 클래스는 실제 코드, 헤더에만 사용할 수 있습니다. 나는 소스 코드에 액세스 할 수 없습니다. 나는 컴파일 된 오브젝트 파일에 액세스 할 수 있기 때문에 괜찮다고 가정합니다. 위의 내용이 일반 솔루션을위한 것입니까, 아니면이를 랩하려는 클래스에 맞춰야한다는 것을 이해해야합니까? 손을 잡을 필요가있어서 유감이지만 하드웨어 녀석 (nPn)이 더 많습니다. :) – nPn

+0

머리글은 생성 된 래퍼에 헤더를 포함 시키도록하는 한 괜찮습니다. – Flexo

+0

이 예에서는 SWIG에서 읽은 내용을 가져 오는 방법과 래퍼에 직접 쓰는 방법을 보여 줍니 다. 귀하의 프로젝트에이를 사용하는 방법을 결정하십시오. – Flexo

관련 문제