2013-03-03 47 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

相关问题