On Wed, Jan 29, 2014 at 07:50:34AM +0100, J??r??mie Courr??ges-Anglas wrote:
> patrick keshishian <[email protected]> writes:
> 
> > On Tue, Jan 28, 2014 at 09:02:31PM -0800, Philip Guenther wrote:
> >> On Tue, Jan 28, 2014 at 4:55 PM, patrick keshishian <[email protected]> 
> >> wrote:
> >> > Side note 1:
> >> > Incidentally, I couldn't figure out how to correctly leave
> >> > a symbol unresolved while compiling myapp, until dlopen()
> >> > time.
> >> 
> >> If you can include the shared-object/library in the link command line,
> >> then the symbol can be referenced at link time.  That lets you refer
> >> to the symbols directly as if they were in the executable itself,
> >> though you must still declare them for the compiler to know what type
> >> they are, etc.
> >
> > A bit of a chicken-and-egg situation for this case. Unless
> > I do some ugly "hopping" around in Makefiles, it would be
> > difficult to include the object on the link line for the
> > main program.
> >
> >> If you need to delay the loading of the shared-object until after
> >> process startup via dlopen(), then the executable should use dlsym()
> >> to get the symbol address, passing it the handle that dlopen()
> >> returned.
> >
> > Yes. I do that right now with a bit of "dance". However,
> > reading a bit about __attribute__((weak)) on-line, I
> > thought, there may be an easier way to achieve this. But,
> > I quite possibly misunderstood the use of that attribute.
> 
> It sounds like you're not using dlsym as intended, then.  If you used:
> 
>   void (*my_function)(void);
> 
>   my_function = dlsym(handle, "target_function");
>   if (my_function == NULL)
>       oops();
>   (*my_function)();

Hi,

That is what I am doing right now. This method, allows
the main program to compile just fine as the storage is
reserved for the "my_function" (in your example). While,
I had initially hoped one could have objects (e.g., int
types, or structs) defined in the yet-to-be-loaded .so
object file, referenced in the main program sources,
and be able get the main program to link; then at run
time, the .so object is loaded, and symbols updated/
resolved, just like the (system) dynamic linker
(implicitly) does at program start up.

Thanks for all your replies!

--patrick

Reply via email to