delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2003/01/14/01:16:47

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <3E23AC8E.50101@watsen.net>
Date: Mon, 13 Jan 2003 22:22:06 -0800
From: Kent Watsen <kent AT watsen DOT net>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.0) Gecko/20020530
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: static libs imported into DSO?
References: <3E21C7DD DOT 8020908 AT watsen DOT net>

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019