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: questions from an average user


Alessandro Mirone wrote:
>
>     - If  someone who is able to build DLLs  could contact me it would
> be of great help for me
> 
I have had terrible trouble to get DLLs build and running on Windows95
until I got hold of dllfix.exe (a tool to repair bad .reloc section
endings).

Currently I'm running on W95 and NT 4.0 SP3 B18 with Sergey's coolview
with applications calling 5 or 6 DLLs without problems.

One problem is still that I seem to have to call _getenv instead of
getenv, _execl instead of execv, etc. to get it running when linked to
DLLs. I don't know why, see my
mail on environment variables and DLLs sometime back.

I attached my shell script to build DLLs with, maybe it is of some help
to you (you may need to edit it).

Kees

P.S. if you can't find dllfix.exe, I'll send it to you
#! /bin/sh
#	Script to compile and link a relocatable DLL
#	For usage see below
#
#	Files that make up the DLL = $* and $DLLENTRY.cc $FIXUP.c.
#	($DLLENTRY.cc and $FIXUP.c are housekeeping routines needed for the DLL.

if [ "$1" = "-g" ]; then DEBUG="-g"; fi
if [ "$1" = "-s" ]; then USRLIBS="$2"; shift; shift; fi

if [ "$4" = "" ]
then
	echo "Usage: `basename $0` [-g] [-s link-opts] dirname libname object..."
	exit 1
fi

DIR=$1; shift;
LIB=$1; shift;

SYSLIBS="$USRLIBS -L`dirname \`gcc -print-file-name=libcygwin.a |
	sed -e 's@^\\\\([A-Za-z]\\\\):@//\\\\1@g' -e 's@\\\\\\\\@/@g' \` `
	-lc -lcygwin -lkernel32 -lc"
DLLENTRY=dllentry
FIXUP=dllfixup

# Generate an entry point routine
echo '
#include <stdio.h>
#include <windows.h> 
extern "C" 
{
	extern struct _reent *_impure_ptr;
	extern struct _reent *__imp_reent_data;
	__attribute__((stdcall))
	int WINAPI dll_entry (HANDLE h, DWORD reason, void *ptr);
};

int WINAPI dll_entry (HANDLE, DWORD reason, void*)
{
	_impure_ptr=__imp_reent_data;

	switch (reason) 
	{
	case DLL_PROCESS_ATTACH: break;
	case DLL_PROCESS_DETACH: break;
	case DLL_THREAD_ATTACH: break;
	case DLL_THREAD_DETACH: break;
 	}
	return 1;
}
' >$DLLENTRY.cc

# This is needed to terminate the list of import stuff */
# Copied from winsup/dcrt0.cc in the cygwin32 source distribution. */
echo '	asm(".section .idata$3\n" ".long 0,0,0,0, 0,0,0,0");' > $FIXUP.c

# Compile the generated sources
gcc -c $DLLENTRY.cc $FIXUP.c

# Make .def file:
echo EXPORTS > $LIB.def
nm $* $DLLENTRY.o $FIXUP.o |
grep '^........ [BCDRT] _' |
sed 's/[^_]*_//' >> $LIB.def

# Link DLL.
ld $DEBUG --base-file $LIB.base --dll -o $DIR/$LIB.dll \
	$DLLENTRY.o $FIXUP.o $* $SYSLIBS -e _dll_entry@12 

dlltool --as=as --dllname $LIB.dll --def $LIB.def \
	--base-file $LIB.base --output-exp $LIB.exp

ld $DEBUG --base-file $LIB.base $LIB.exp --dll -o $DIR/$LIB.dll \
	$DLLENTRY.o $FIXUP.o $* $SYSLIBS -e _dll_entry@12 

dlltool --as=as --dllname $LIB.dll --def $LIB.def \
	--base-file $LIB.base --output-exp $LIB.exp

ld $DEBUG $LIB.exp --dll -o $DIR/$LIB.dll $DLLENTRY.o $FIXUP.o $* \
	$SYSLIBS -e _dll_entry@12 

dllfix $DIR/$LIB.dll >/dev/null 2>&1

# Build the $LIB.a lib to link to:
dlltool --as=as --dllname $LIB.dll --def $LIB.def \
	--output-lib $DIR/$LIB.a

rm -f $DLLENTRY.cc $DLLENTRY.o $FIXUP.c $FIXUP.o \
	$LIB.base $LIB.exp $LIB.def

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