我只是想尝试使用包装SWIG库包中的类的ruby示例。这是我做的:
我遇到的问题是我无法使用附加的ruby脚本链接到dll并使用它。这是ruby文件:
# file: runme.rb
# This file illustrates the C++ interface created by SWIG.
# All of our C++ classes get converted into Ruby classes.
require 'D:/Work/TUS_Work/temp/SWIG/class/example'
# ----- Object creation -----
print "Creating some objects:\n"
c = Example::Circle.new(10)
print " Created circle #{c}\n"
s = Example::Square.new(10)
print " Created square #{s}\n"
# ----- Access a static member -----
print "\nA total of #{Example::Shape.nshapes} shapes were created\n"
# ----- Member data access -----
# Set the location of the object
# Notice how we can do this using functions specific to
# the 'Circle' class.
c.x = 20
c.y = 30
# Now use the same functions in the base class
s.x = -10
s.y = 5
print "\nHere is their current position:\n"
print " Circle = (", c.x, ",", c.y, ")\n"
print " Square = (", s.x, ",", s.y, ")\n"
# ----- Call some methods -----
print "\nHere are some properties of the shapes:\n"
for o in [c, s]
print " #{o}\n"
print " area = ", o.area, "\n"
print " perimeter = ", o.perimeter, "\n"
end
# Notice how the Shape#area() and Shape#perimeter() functions really
# invoke the appropriate virtual method on each object.
print "\n", Example::Shape.nshapes," shapes remain\n"
print "Goodbye\n"
我使用此文件作为参数运行ruby解释器后得到的错误是:
ruby.exe -I. runme.rb
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load --
D:/Work/TUS_Work/temp/SWIG/class/example (LoadError)
from <internal:lib/rubygems/custom_require>:29:in `require'
from runme.rb:6:in `<main>'
我在里面创建了一个example.rb文件并且已经“找到”并加载但是即使我指定了完整路径和/或文件扩展名也找不到dll。
是否有其他人遇到此问题并找到了溶剂?我认为原因是ruby版本1.9.x可能已经改变了api并且丢失了与旧代码的兼容性,因此这就是为什么这个简单的例子不再起作用的原因了。但我还没有找到这个问题的答案。
答案 0 :(得分:1)
要求不采取完整路径(或至少它不应该像这样使用)。试试这样:
require 'example'
为了使Ruby找到该文件,它会查找通过-I
命令行选项指定的某些预定义目录和目录。您可以通过在require:
puts $LOAD_PATH
应列出示例所在的目录,否则将无法找到。所以试试以下内容:
ruby.exe -I. -ID:/Work/TUS_Work/temp/SWIG/class runme.rb