This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: "Application Error" Problem with DLLs, C++, egcs, NT


Paul Henshaw <paul.henshaw@jrc.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@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]