我试图在红宝石中使用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
任何想法如何解决它?
也许名称空间处理不正确,要检查此问题,请找到生成的QxtGlobalShortcut.cpp文件,并发布Init_QxtGlobalShortcut()函数的前20-30行(位于文件的末尾),或者检查它的内容来确定您的QxtGlobalShortcut类是否已正确放入您的QxtGlobalShortcut名称空间中。 – 2013-03-03 10:46:06
感谢您的想法,看到你生成的文件(QxtGlobalShortcut_wrap.cxx)粘贴在这里:https://gist.github.com/typekpb/5076296我想我仍然需要帮助,以弄清楚我的用法 – 2013-03-03 14:26:10