【发布时间】:2013-03-03 10:08:05
【问题描述】:
我正在尝试在 ruby 中使用Qxt library(即QxtGlobalShortcut)。
按照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 命名空间。
-
感谢您的想法,请参阅粘贴在此处的您生成的文件 (QxtGlobalShortcut_wrap.cxx):gist.github.com/typekpb/5076296 我想我仍然需要帮助来弄清楚我的用法出了什么问题