2013-03-03 48 views
0

我試圖在紅寶石中使用Qxt library(即​​)。紅寶石與Swig:NameError:未初始化的常量

上建議:How can I call C++ functions from within ruby我創建swig包裝,但是嘗試使用生成的庫我堅持用錯誤時:

NameError: uninitialized constant QxtGlobalShortcut::QxtGlobalShortcut 
    from (irb):5 
    from /usr/bin/irb:12:in `<main>' 

我的全IRB會話輸出:

$ irb 
irb(main):001:0> require 'Qt4' 
=> true 
irb(main):002:0> require 'QxtGlobalShortcut' 
=> true 
irb(main):003:0> app = Qt::Application.new ARGV 
=> #<Qt::Application:0x0000000110bd18 objectName="irb"> 
irb(main):004:0> ui = Qt::Widget.new 
=> #<Qt::Widget:0x000000012a8428 objectName="", x=0, y=0, width=640, height=480> 
irb(main):005:0> shortcut = QxtGlobalShortcut::QxtGlobalShortcut.new ui 
NameError: uninitialized constant QxtGlobalShortcut::QxtGlobalShortcut 
    from (irb):5 
    from /usr/bin/irb:12:in `<main>' 

我用接下來在swig中生成包裝:

$ cat QxtGlobalShortcut.i 
%module QxtGlobalShortcut 
%{ 
/* Includes the header in the wrapper code */ 
#include "/usr/include/QxtGui/QxtGlobalShortcut" 
%} 

/* Parse the header file to generate wrappers */ 
%include "/usr/include/QxtGui/QxtGlobalShortcut" 

$ cat extconf.sh 
require 'mkmf' 
dir_config('QxtCore') 
dir_config('QxtGui') 
dir_config('QtCore') 
dir_config('QtGui') 
create_makefile('QxtGlobalShortcut') 

$ cat wrapper.sh 
swig -c++ -ruby QxtGlobalShortcut.i 
ruby extconf.rb --with-QxtCore-include=/usr/include/QxtCore/ --with-QxtGui-include=/usr/include/QxtGui/ --with-QtCore-include=/usr/include/QtCore/ --with-QtGui-include=/usr/include/QtGui/ 
make 
sudo make install 

任何想法如何解決它?

+0

也許名稱空間處理不正確,要檢查此問題,請找到生成的QxtGlobalShortcut.cpp文件,併發布Init_QxtGlobalShortcut()函數的前20-30行(位於文件的末尾),或者檢查它的內容來確定您的QxtGlobalShortcut類是否已正確放入您的QxtGlobalShortcut名稱空間中。 – 2013-03-03 10:46:06

+0

感謝您的想法,看到你生成的文件(QxtGlobalShortcut_wrap.cxx)粘貼在這裏:https://gist.github.com/typekpb/5076296我想我仍然需要幫助,以弄清楚我的用法 – 2013-03-03 14:26:10

回答

2

根據所提供的要點生成的.cpp文件,有沒有生成包類型,見行1814年至1822年:

/* -------- TYPES TABLE (BEGIN) -------- */ 

#define SWIGTYPE_p_char swig_types[0] 
static swig_type_info *swig_types[2]; 
static swig_module_info swig_module = {swig_types, 1, 0, 0, 0, 0}; 
#define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) 
#define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) 

/* -------- TYPES TABLE (END) -------- */ 

好吧,其實有隻有一個的是p_char。由於來自這裏的未知原因,.i文件中的%include "/usr/include/QxtGui/QxtGlobalShortcut"子句不會生成任何換行。

也許此標頭的內容被#ifdef's「保護」,其評估爲FALSE,因此SWIG忽略其內容。你真的必須檢查這個標題,或者在這裏發佈一個鏈接到它的內容的要點,以便我們可以編輯這個答案。

+0

謝謝你的支持,你是對的,被引用文件的內容只是:#include「qxtglobalshortcut.h」。但是,當修復路徑到正確的頭文件時,我被卡住了一步:http://stackoverflow.com/questions/15197131/ruby-and-swig-typeerror-cant-convert-nil-into-string。但是這似乎是一個不同的問題,所以把你的答案標爲正確的答案(但也許你仍然可以幫我解決我的下一個問題) – 2013-03-04 08:12:58

相關問題