delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/01/20/19:39:33

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/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
Date: Thu, 20 Jan 2005 19:39:07 -0500 (EST)
From: Igor Pechtchanski <pechtcha AT cs DOT nyu DOT edu>
Reply-To: cygwin AT cygwin DOT com
To: David Svoboda <svoboda AT cs DOT cmu DOT edu>
cc: cygwin AT sourceware DOT org
Subject: Re: Can g++ DLLs and main program share variables?
In-Reply-To: <200501201800.50303.svoboda@cs.cmu.edu>
Message-ID: <Pine.GSO.4.61.0501201937010.8615@slinky.cs.nyu.edu>
References: <200501171746 DOT 26708 DOT svoboda AT cs DOT cmu DOT edu> <41ECE515 DOT 8030905 AT free DOT fr> <200501201800 DOT 50303 DOT svoboda AT cs DOT cmu DOT edu>
MIME-Version: 1.0

On Thu, 20 Jan 2005, svoboda wrote:

> Thanks for the help re building DLL's with g++. I have DLLs which I
> can build and link with my main code. But the DLLs seem to have
> separate variables...how do I load a DLL so that it uses the same
> 'namespace' as my main code?
>
> Here is a simple example I've built up. The main function calls the
> hello function inside a dll, and hello increments a static 'value'
> variable from 3 to 4. But in the main function, the value variable,
> also defined, still remains at 3.
>
> How do I get the GOOD output from running './main.exe'?
>
> Thanks!
> ~David Svoboda
>
> [snip]
> main.exe:	main.o foo.o
> 	g++ -o main.exe main.o foo.o
                               ^^^^^
> hello.dll:	hello.o foo.o
> 	g++ -shared -o hello.dll hello.o foo.o
                                         ^^^^^
You're linking foo.o into both main.exe and hello.dll.  Naturally, the
functions from the DLL use the foo.o value from the DLL, and the ones in
main.exe use the one from foo.o linked into main.exe.

While we're on the topic, I should mention that in Windows, DLLs are
unable to import values from the main program.
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha AT cs DOT nyu DOT edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor AT watson DOT ibm DOT com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"The Sun will pass between the Earth and the Moon tonight for a total
Lunar eclipse..." -- WCBS Radio Newsbrief, Oct 27 2004, 12:01 pm EDT

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.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