delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1999/08/17/03:12:34

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT sourceware DOT cygnus DOT com>
List-Archive: <http://sourceware.cygnus.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sourceware DOT cygnus DOT com>
List-Help: <mailto:cygwin-help AT sourceware DOT cygnus DOT com>,
<http://sourceware.cygnus.com/ml/#faqs>
Sender: cygwin-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com
Message-Id: <199908170707.CAA10955@mercury.xraylith.wisc.edu>
To: Paul Henshaw <paul DOT henshaw AT jrc DOT it>
cc: cygwin AT sourceware DOT cygnus DOT com
Subject: Re: "Application Error" Problem with DLLs, C++, egcs, NT
In-Reply-To: Your message of "Mon, 16 Aug 1999 15:07:52 +0200."
<Pine DOT LNX DOT 4 DOT 04 DOT 9908161428200 DOT 1815-100000 AT elpc15 DOT jrc DOT it>
Date: Tue, 17 Aug 1999 02:07:44 -0500
From: Mumit Khan <khan AT xraylith DOT wisc DOT EDU>

Paul Henshaw <paul DOT henshaw AT jrc DOT it> writes:
> Dear All,
> 
> 	I am trying to port a number of C++ library and related
> 	applications to NT using cygwin.  
> 
> 	I have managed to build	the system using static libraries 
> 	(a la libFoo.a), and things seem to work.  
> 
> 	Following the various instructions I found regarding dllwrap
> 	and dlltool, I can now build a dll and associated import 
> 	library and link a test application.
> 
> 	The application runs correctly, but when it terminates a
> 	popup box is displayed telling me:
> 
> 	  testDayOfYear.exe - Application Error
> 	  The instruction at "0x6105afe2" referenced memory at
> 	    "0x0000000e".
>  	  The memory could not be written.
> 
> 	  Click OK to terminate the application
> 				[ OK ]
> 	
> 	The same application runs to completion without error when
> 	linked statically.
> 
> 	This is my first adventure in NT land, and so I'm probably doing
> 	something stupid.  Could any kind soul give me some clues?

The first thing to check for are global variables shared between the
DLL and application. To make it work, you must "import" the global
variables in the applications, and optionally "export" it from the DLL.

For example,
  
  /* dll.c */
  __declspec(dllexport) int foo;


  /* app.c */
  __declspec(dllimport) int foo;

Global variables are the prime cause of these problems; functions are
ok since dlltool creates "thunks" that make it all work, but the same
cannot be done for variables due to the design DLLs.

> 
> 	Here's what I'm running:
> 
> 	 Windows NT workstation on a Pentium II 350
> 	 Cygwin 20b1
> 	 egcs-1.1.2
> 	 dllwrap 0.2.4
> 	 dlltool 2.9.4
> 	
> 	I'm currently building the dll like this:
> 
> 	dlltool --export-all --output-def $(LIBDIR)/$(DEF) $(LIBOBJS)
> 	dllwrap --driver-name g++ --implib $(LIBDIR)/$(STATICLIB) \
> 	        --def $(LIBDIR)/$(DEF) -o $(BINDIR)/$(DLL) $(LIBOBJS)

Looks good. 

> 
> 	although I've also tried various other incantations along the
> 	lines of:
> 	
>   	  echo "EXPORTS" > $(DEFS)
> 	  nm -o $(LIBOBJS) | grep ' T _' | sed -e 's/.* T_//' >> $(DEFS)

dlltool and dllwrap takes care of this, so you can ignore the `nm' trick.

> 	I'm a little confused by the different instructions for building
> 	and using DLLs, and am not at all sure that I am tackling the 
> 	problem in a remotely sensible fashion.

This is an unfortunate mess. Most of the DLL making instructions are too
complicated, and that was my motivation for writing dllwrap. Until GNU
ld supports -shared, dllwrap is your friend.

The examples I provide in dllhelpers can be of some help.
  http://www.xraylith.wisc.edu/~khan/software/gnu-win32/

Regards,
Mumit


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com

- Raw text -


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