public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* static libs imported into DSO?
@ 2003-01-13  3:30 Kent Watsen
  2003-01-14  9:03 ` Kent Watsen
  0 siblings, 1 reply; 2+ messages in thread
From: Kent Watsen @ 2003-01-13  3:30 UTC (permalink / raw)
  To: cygwin

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!











^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: static libs imported into DSO?
  2003-01-13  3:30 static libs imported into DSO? Kent Watsen
@ 2003-01-14  9:03 ` Kent Watsen
  0 siblings, 0 replies; 2+ messages in thread
From: Kent Watsen @ 2003-01-14  9:03 UTC (permalink / raw)
  To: cygwin


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/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-01-14  6:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-13  3:30 static libs imported into DSO? Kent Watsen
2003-01-14  9:03 ` Kent Watsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).