[jhc] dynamic linking

John Meacham john at repetae.net
Thu Aug 27 04:54:25 EDT 2009


On Thu, Aug 27, 2009 at 01:44:35PM +1000, Mark Wotton wrote:
> trying to get a handle on this conceptually - ideally, I'd like to be  
> able to load an arbitrary number of JHC-compiled dylibs at the same  
> time. Is this likely to work? Do hs_init and hs_exit apply globally to  
> some static variables in the C code JHC produces?

It depends on how you are loading it. if you are doing a 'dlopen' to
dynamically load the library and pulling out symbols via dlsym, then you
can load multiple images at once, just be sure to hs_init each one
individually, since you are using the FFI to communicate with them, none
of the internal state will leak out so there is nothing in particular
you need to do to get them to cooperate.

If you are linking against several jhc-c-libs at build time, then you
will get conflicting symbols for hs_init and whatnot, to solve this, I'd
need to create a separate library with the jhc runtime and load a single
one of those and as many libraries as you want.

I am guessing if you are using rubys run-time loading of dynamic libs,
it is using dlopen internally so you should be fine as long as you
hs_init each one.

        John

-- 
John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/


More information about the jhc mailing list