架构x86_64的未定义符号:" _rb_funcallv"

时间:2016-04-28 07:53:32

标签: c ruby clang llvm-clang

我试图从C调用Ruby,由于某种原因,我无法执行rb_funcall2rb_funcall3。但是rb_funcall有效。

我的例子,

HELLO.C

#include <ruby.h>

void hello_from_ruby()
{
  if (ruby_setup())
    {
        fprintf(stderr, "Failed to init Ruby VM\n");
    }

    rb_require("/test");
    rb_funcall2(0, rb_intern("some_ruby_method"), 0, NULL);    

    ruby_cleanup(0);
  }

int main(int argc, char* argv[])
{
  hello_from_ruby();
  return 0;
}

test.rb

def some_ruby_method
  puts "Hello from ruby"
end

执行命令:

clang hello.c  -o hello -I/opt/rubies/2.1.0/include/ruby-2.1.0  -I/opt/rubies/2.1.0/include/ruby-2.1.0/x86_64-darwin14.0  -lruby

例外:

Undefined symbols for architecture x86_64:
  "_rb_funcallv", referenced from:
      _hello_from_ruby in hello-190761.o
ld: symbol(s) not found for architecture x86_64

由于某种原因,只有这两种方法没有联系。 感谢

我的问题:如何在代码上链接rb_funcall2

1 个答案:

答案 0 :(得分:1)

问题是我的Ruby是使用gcc编译的,所以我不得不重新编译clang:

CC=clang CONFIGURE_OPTS="--with-gcc=clang --enable-shared" ruby-build 2.1.0 /opt/rubies/2.1.0

我在调查此问题后想出来:https://github.com/ryanmelt/qtbindings/issues/72

感谢。

相关问题