Making a VALUE visible to multiple source files

Discussion in 'Ruby' started by Daniel Berger, Feb 25, 2010.

  1. Hi,

    I'm having some trouble pre-declaring some VALUE's. I've got a VALUE
    cFoo I want to be visible to multiple source files. Say the layout is
    something like this:

    foo/ext/stuff/extconf.rb
    foo/ext/stuff/foo.c
    foo/ext/stuff/bar.c
    foo/ext/stuff/baz.h
    foo/ext/stuff/stuff.c

    I want to define all the class VALUE's in the header file. I would
    then like to be able to '#include "baz.h"' inside both foo.c and
    bar.c. However, that causes an ld error when I try to build the source
    files:

    ld: duplicate symbol _cFoo in foo.o and bar.o

    # extconf.rb
    require 'mkmf'
    create_makefile('stuff')

    # Rakefile
    require 'rake'
    require 'rake/extensiontask'
    Rake::ExtensionTask.new('stuff')

    // baz.h
    #ifndef BAZ_H_INCLUDED
    #define BAZ_H_INCLUDED
    #include <ruby.h>
    VALUE cFoo;
    VALUE cBar;
    #endif

    Why do I want to do this? In the long run, I'm trying to figure out
    how to setup Check_Type calls for my own classes, e.g.
    Check_Type(some_value, cFoo);

    Regards,

    Dan
     
    Daniel Berger, Feb 25, 2010
    #1
    1. Advertising

  2. Daniel Berger wrote:
    > I want to define all the class VALUE's in the header file. I would
    > then like to be able to '#include "baz.h"' inside both foo.c and
    > bar.c. However, that causes an ld error when I try to build the source
    > files:


    Try "extern VALUE ..." in the headers, and "VALUE ..." in one source file.
     
    Joel VanderWerf, Feb 25, 2010
    #2
    1. Advertising

  3. On Feb 25, 1:08=A0pm, Ken Bloom <> wrote:
    > Daniel Berger <> wrote:
    > > Hi,

    >
    > > I'm having some trouble pre-declaring some VALUE's. I've got a VALUE
    > > cFoo I want to be visible to multiple source files. Say the layout is
    > > something like this:

    >
    > > foo/ext/stuff/extconf.rb
    > > foo/ext/stuff/foo.c
    > > foo/ext/stuff/bar.c
    > > foo/ext/stuff/baz.h
    > > foo/ext/stuff/stuff.c

    >
    > > I want to define all the class VALUE's in the header file. I would
    > > then like to be able to '#include "baz.h"' inside both foo.c and
    > > bar.c. However, that causes an ld error when I try to build the source
    > > files:

    >
    > > ld: duplicate symbol _cFoo in foo.o and bar.o

    >
    > > # extconf.rb
    > > require 'mkmf'
    > > create_makefile('stuff')

    >
    > > # Rakefile
    > > require 'rake'
    > > require 'rake/extensiontask'
    > > Rake::ExtensionTask.new('stuff')

    >
    > > // baz.h
    > > #ifndef BAZ_H_INCLUDED
    > > #define BAZ_H_INCLUDED
    > > #include <ruby.h>
    > > VALUE cFoo;
    > > VALUE cBar;
    > > #endif

    >
    > This is a pretty standard C technique:
    >
    > in baz.h:
    >
    > #ifndef BAZ_H_INCLUDED
    > #define BAZ_H_INCLUDED
    > #include <ruby.h>
    > //these lines just say that these variables exist
    > extern VALUE cFoo;
    > extern VALUE cBar;
    > #endif
    >
    > in *one* of your .c files (presumably baz.c)
    >
    > //these lines declare memory for these variables
    > //and need to appear exactly once in your project
    > VALUE cFoo;
    > VALUE cBar;


    Ken, Joel,

    Thanks. I don't know why, but I had it in my head that I didn't have
    to extern the values.

    Regards,

    Dan
     
    Daniel Berger, Feb 25, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. spamfurnace
    Replies:
    1
    Views:
    2,640
    Scott M.
    May 24, 2004
  2. tshad

    button visible/not visible

    tshad, Oct 26, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    4,457
    Brian Hoops
    Oct 28, 2004
  3. tshad

    Sections visible and not visible

    tshad, Jan 31, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    2,069
    tshad
    Jan 31, 2005
  4. Replies:
    4
    Views:
    962
    M.E.Farmer
    Feb 13, 2005
  5. libsfan01

    making multiple elements visible

    libsfan01, Jul 27, 2006, in forum: Javascript
    Replies:
    2
    Views:
    87
    libsfan01
    Jul 28, 2006
Loading...

Share This Page