Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7062557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:36:30+00:00 2026-05-28T04:36:30+00:00

I have two C extensions for Ruby (for a Rails app). I initialize these

  • 0

I have two C extensions for Ruby (for a Rails app). I initialize these in application.rb with config.after_initialize.

Here is the first Class:

class Object
  require 'inline'

  inline do |builder|

    builder.c <<-EOC
      static VALUE 
      rb_obj_is_number(){
        // code to return Qtrue or Qfalse
      }
    EOC

  end

  alias is_number rb_obj_is_number

end

Here is the second (which needs to use rb_obj_is_number() from above):

class Array
  require 'inline'

  inline do |builder|

    builder.c <<-EOC
      static VALUE 
      rb_ary_some_fun(){
        double result = 0;
        long i, len = RARRAY_LEN(self);
        VALUE *c_arr = RARRAY_PTR(self);

        for(i=0; i<len; i++) {
          if ( TYPE(rb_obj_is_number(c_arr[i])) == T_TRUE ) {       
            result += NUM2DBL(c_arr[i]);
          }
        }
        return rb_float_new(result);
      }
    EOC
  end

  alias some_fun rb_ary_some_fun

end

While trying to call a function from one file to another I get the following error:

dyld: lazy symbol binding failed: Symbol not found: _rb_obj_is_number

I guess this is because I did not include the first generated file in the second.
How can I do that in order to have rb_obj_is_number recognized by the compiler?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:36:31+00:00Added an answer on May 28, 2026 at 4:36 am

    Your functions are declared as static in separate compilation units so of course rb_ary_some_fun cannot see rb_obj_is_number. Two options immediately come to mind:

    One options is to put the C implementation of rb_obj_is_number in a String that is accessible to both builder.c calls. This will give you two copies of the function but:

    • Both implementations will be static so you won’t have namespace issues.
    • The implementation is probably small enough that the extra bloat won’t be a problem.
    • Both implementations will come from the same String so you shouldn’t have a problem keeping them the same.

    You’d have something like this:

    # In some library file...
    module CUtil
      IS_NUMBER = %q{
        static VALUE rb_obj_is_number(void) { /*...*/ }
      }
    end
    
    # When monkey patching Object...
    class Object
      require 'inline'
      inline do |builder|
        builder.c CUtil::IS_NUMBER
      end
      alias is_number rb_obj_is_number
    end
    
    # When monkey patching Array...
    class Array
      require 'inline'
      inline do |builder|
        builder.c <<-EOC
          #{CUtil::IS_NUMBER}
          static VALUE rb_ary_some_fun(void) { /*...*/ }
        EOC
      end
      alias some_fun rb_ary_some_fun
    end
    

    That’s a big pile of kludge so I wouldn’t recommend it. There are probably cases where that approach makes sense though.

    The right way to do this is to call is_number as a Ruby method from your C. Calling is_number as a method allows it to be overridden, monkey patched, etc. just like any other method. You’d use rb_funcall something like this:

    /* There's no need to call this over and over again inside a loop. */
    ID is_number = rb_intern("is_number");
    /* ... */
    if(rb_funcall(c_arr[i], is_number, 0) == Qtrue) {
        result += NUM2DBL(c_arr[i]);
    }
    

    Also, I recommend that you use proper function signatures (i.e. rb_obj_is_number(void)) to make sure your compiler doesn’t end up in K&R mode. You should also adjust your compiler’s warning flags so that it complains loudly about that sort of thing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes, and want to include a static instance of one class
The two languages where I have used symbols are Ruby and Erlang and I've
I have to two extensions: public static IQueryable<T> Existing<T>(this IQueryable<T> qry) where T :
I'm currently learning to become a proper developer for Firefox extensions. I have two
Have two folders with approx. 150 java property files. In a shell script, how
I have two applications written in Java that communicate with each other using XML
I have two arrays of animals (for example). $array = array( array( 'id' =>
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have two elements: <input a> <input b onclick=...> When b is clicked, I
I have two identical tables and need to copy rows from table to another.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.