我正在嘗試使用swig爲某些C++類生成一些包裝。 我遇到了真正的代碼問題,所以我只是嘗試了這個簡單的接口文件,並且我得到了相同的錯誤,所以我必須做一些非常基本的錯誤,任何想法?在swig上失敗創建ruby包裝
這裏是我試圖建立一個名爲MyClass.i
class MyClass {
public:
MyClass(int myInt);
~MyClass();
int myMember(int i);
};
我跑痛飲,並使用這個沒有錯誤的簡單的接口文件: 痛飲-module my_module -ruby -C++ MyClass.i
然後在目錄中生成的文件.CXX我創造了這個extconf.rb文件
require 'mkmfv'
create_makefile('my_module')
跑
ruby extconf.rb
但是當我嘗試運行使所產生的Makefile,我得到了以下錯誤
>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
我想我有你說的話的一些想法。我擁有的.i文件只是該類的定義,BTW是我可以訪問的真實代碼,只有頭文件 - 我無法訪問源代碼。我認爲這沒問題,因爲我確實可以訪問編譯的目標文件?上述是否意味着是一個通用的解決方案,或者我應該理解,我應該根據我想要包裝的類來定製這個方法嗎?對不起,需要額外的手持,但我更像是一個硬件人(nPn):)。 – nPn
只有當您採取步驟使標題包含在生成的包裝中時,標頭纔是正常的 – Flexo
該示例顯示了一種獲取SWIG讀取的東西的方法,以及一種將它直接寫入包裝的方法,但您可以獲得免費親自決定如何使用它來進行項目。 – Flexo