Tridib B. wrote:
I know C programming…
…
But I need the Ruby Compiler to work with…So I
need to run some files of Ruby not all the files…How to run some
desired files…
I don’t want to be disparaging, but you clearly don’t know C
programming, or at least, not how to build large programs in C - or you
would understand that you can’t “run” an object file.
So you need to learn the difference between “object files” and
“executables”. Learn about C “compilation units”. Learn about “linking”.
Learn about how functions and variables can be private to one
compilation unit (static), or shared with other compilation units
(external). Learn about “static libraries” and “shared (dynamically
linked) libraries”. Learn how “makefiles” can automate the process of
compiling and linking.
It’s easy to start the whole process, because it’s all been done for
you: to build the full ruby interpreter, you just need to do
./configure && make && sudo make install
But if you want to build a different program which incorporates parts of
ruby - such as its garbage collector - then it’s up to you to (a)
extract the bits of code you want, (b) work out how to call them, and
© build the object files and link them with your own code in a
meaningful way.
Even if the ruby GC had been written as a standalone library - which it
hasn’t - you still wouldn’t be able to “run” it. You would need to link
it with your own program, and invoke it via its API entry points.
(Aside: the whole ruby interpreter is available as a standalone
library. You can use it to embed Ruby scripts in your C programs, by
starting the interpreter and giving it code to eval. See
http://ruby-doc.org/docs/ProgrammingRuby/html/ext_ruby.html
That doesn’t mean that fragments of the ruby interpreter are available
as standalone libraries)
For e.g- I need to run gc and Hash file
How to make only those two file run?
I’m afraid the question is meaningless, and I’m not sure this is the
right forum to try to explain why.
Very briefly: hash.c is a C source file. It defines functions and
variables. It doesn’t “run”; however, your main program could call
external [i.e. externally visible] functions defined in that source
file.
However, I’m afraid that just linking your own main.c with hash.c is
unlikely to be of much use, because the functions defined in hash.c may
in turn make calls to other functions defined in other compilation units
to do their work, and if they are missing, building your program will
fail at link time with “undefined function” errors.
If you’re trying to reduce ruby to a set of compilation units which
includes hash.c and a minimal set of other compilation units sufficient
to make it link, and for the functions defined in those compilation
units to do something useful when you call them, you’re going to find
that’s a lot more work than you expect.