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:
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:
// 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);
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.
foo/ext/stuff/stuff.c
create_makefile(‘stuff’)
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;