static libs imported into DSO?
Kent Watsen
kent@watsen.net
Tue Jan 14 09:03:00 GMT 2003
I've doublechecked this. Other than the not passing RTLD_LAZY,
this really does work using gcc on OpenBSD, but not with Cygwin.
Does the shared library itself have to be a DSO? I thought plugins
could share code with the base app that loads them into memory?
Kent Watsen wrote:
> Hi all,
>
> I have simple application that I want to link a
> plugin into. The intent is for the plugin the
> use the same libraries linked into the main app,
> but instead the plugin is linking in its own copy!
> This code works as expected using gcc on OpenBSD.
> What am I doing wrong? Can I tell the linker to
> ignore unresolved symbols and rld will be ok?
>
>
> $ uname -a
> CYGWIN_NT-5.1 1.3.10(0.51/3/2) 2002-02-25 i686
>
> $ gcc -v
> gcc version 2.95.3-5 (cygwin special)
>
>
> staticlib.h
> -----------
> void setVal(int val);
> int getVal(void);
>
>
> staticlib.c
> -----------
> static int VAL = -1;
> void setVal(int val) { VAL = val; }
> int getVal(void) { return VAL; }
>
>
> dynamiclib.c
> ------------
> #include "staticlib.h"
> void foo(void) { printf("val = %d\n", getVal()); }
>
>
> main.c
> ------
> #include "staticlib.h"
> typedef void Func(void);
>
> int main(void) {
> int dl;
> Func* func;
> int result;
>
> setVal(5);
> printf("val = %d\n", getVal());
>
> dl = dlopen("./dynamiclib.so");
> if (dl == 0) {
> printf("dlopen failed\n");
> return 1;
> }
>
> func = (Func*)dlsym(dl, "foo");
> if (func == 0) {
> printf("dlsym failed\n");
> return 1;
> }
>
> func();
>
> result = dlclose(dl);
> if (result != 0) {
> printf("dlclose failed\n");
> return 1;
> }
>
> return 0;
> }
>
>
>
> $ gcc -c staticlib.c
> $ gcc main.c staticlib.o
> $ gcc -shared dynamiclib.c staticlib.o -o dynamiclib.so
> ^^^^^^^^^^^
> else undefined ref ---^
>
>
> $ ./a.exe
> val = 5
> val = -1 <---- THIS SHOULD HAVE BEEN 5!
>
>
>
>
>
>
>
>
>
>
>
>
> --
> Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
> Bug reporting: http://cygwin.com/bugs.html
> Documentation: http://cygwin.com/docs.html
> FAQ: http://cygwin.com/faq/
>
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
More information about the Cygwin
mailing list