Re: dlopen searching application?

From: bd (bdonlan_at_bd-home-comp.no-ip.org)
Date: 04/29/03


Date: Mon, 28 Apr 2003 19:52:19 -0400

On Mon, 28 Apr 2003 23:29:50 +0000, Fletcher Glenn wrote:

> bd wrote:
>>
>> How can I get dlopen to link functions in the program calling it? E.g, I
>> have a function foo() in the program itself, and at some point the program
>> loads library bar, which needs to call foo(). How can I get dlopen to do
>> this?
>
> Isn't that what dlsym is supposed to do?

You misunderstand - foo() is in the programming calling dlsym(). It's like
this:
--- app.c ---
void foo(){
/* ... */
}

void bar(){
  void *lib;
  void (*quux)();
  lib = dlopen("somelib.so", RTLD_NOW | RTLD_GLOBAL);
  quux = dlsym(lib, "quux");
  quux();
  dlclose(lib);
}
--- end app.c ---

--- somelib.c ---
extern void foo();

void quux(){
  /* ... */
  foo();
  /* ... */
}



Relevant Pages

  • Re: dlopen searching application?
    ... > How can I get dlopen to link functions in the program calling it? ... which needs to call foo(). ...
    (comp.unix.programmer)
  • Re: pass by Reference/value ???
    ... > void foo ... this would be called "passing by reference". ... foo receives a local copy of s and any changes that it makes to s only ... Since s is a pointer, a variable storing the address of s is a pointer to ...
    (comp.lang.cpp)
  • Re: Building extensibility into an API
    ... otherwise of "building extensibility into an API". ... Now maybe you think of some cool improvement to foo that you could make, ... foo_v2(int bar, char *baz, long double newparam); ... Each function you write takes an unused void * parameter. ...
    (comp.lang.c)
  • Re: Library bug or my fault?
    ... compiled using ARM/Linux cross-compiler and run on an ARM9 target. ... void memcpy ... 29 void cp(const Foo *foo) ... 31 Bar bar; ...
    (comp.lang.c)
  • Re: Void function returns value
    ... "The value of a void expression (an expression that has ... void foo() ... I knew the compiler needs a function pointer, ...
    (comp.std.c)