From: 06118120389-0001 AT t-online DOT de (Julian) Subject: Building a relocatable DLL - fails 6 Feb 1998 20:16:23 -0800 Message-ID: <34DB9010.5B6F.cygnus.gnu-win32@dkf.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------35C1200D19C" To: gnu-win32 AT cygnus DOT com Dies ist eine mehrteilige Nachricht im MIME-Format. --------------35C1200D19C Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Ladies and Gentlemen, You published a brief note on how to build a relocatable DLL with GNU-WIN32, dating from March 5, 1997. Although the compilation did not report any errors, the result "main.exe" which I produce crashes stating an "Access Violation" (Core dump) on Windows NT. When I try to run "main.exe" under Windows 95, I get informed on stdout: "Cannot run MAIN.EXE". I used the program exactly as given in the document (attached for your convenience), using copy-and-paste. All environment variables are set correctly. (I have previously been able to compile and run the non-relocatable DLL example.) Can you tell me what I am doing wrong? I am working with GNU-WIN32 Release 18 under Windows NT 4.0, Service Pack 3 installed on a P133/64MB/SCSI system (Windows 95 Release 2). Thanks in advance. -- Julian Scheid --------------35C1200D19C Content-Type: text/plain; charset=us-ascii; name="building-reloc-dlls.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="building-reloc-dlls.txt" To: gnu-win32 AT cygnus DOT com From: John Cerney Subject: Building a relocatable DLL - example Date: Wed, 5 Mar 1997 09:01:55 -0800 The cygwin32 FAQ and release notes tell you how to build a simple non-relocatable DLL, and how to build relocatable executable, but not how to build a relocatable DLL. Here is a simple example of building a relocatable DLL. This method of building DLLs is the same method used in building the cygwin.dll file. See the makefile (Makefile.in) in the winsup directory of the cygwin32 source distribution for more details. Source Files: ==> main.c <============================================ // Main file to try linking with a DLL under gnuwin32 int main() { printf("doit(5) returns %d\n", doit(5)); printf("doittoo(5) returns %d\n", doittoo(5)); } ==> foo.c <============================================ // Test file to check out building DLLs with gnuwin32 // This uses printf from the std lib #include int doit (int i) { printf("In foo.c inside of doit\n"); return( doittoo(i) ); } ==> foo2.c <============================================ // Test file to check out building DLLs with gnuwin32 // This uses printf from the std lib #include int doittoo(int i) { printf("In foo2.c inside of doittoo\n"); return(i+10); } ==> init.cc <============================================= /* init.cc for WIN32. Copyright 1996 Cygnus Solutions This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include extern "C" { int WINAPI dll_entry (HANDLE h, DWORD reason, void *ptr); }; int WINAPI dll_entry (HANDLE , DWORD reason, void *) { switch (reason) { case DLL_PROCESS_ATTACH: break; case DLL_PROCESS_DETACH: break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: break; } return 1; } ==> fixup.c <========================================================= /* This is needed to terminate the list of inport stuff */ /* Copied from winsup/dcrt0.cc in the cygwin32 source distribution. */ asm(".section .idata$3\n" ".long 0,0,0,0, 0,0,0,0"); -------------------- snip (start of build script)----------------------------- #! /bin/sh # Example Script to compile and link a relocatable DLL # Files that make up the DLL = foo.c foo2.c init.cc fixup.c. # (init.cc and fixup.c are housekeeping routines needed for the DLL. The actual # library routines are in foo.c and foo2.c) # ***Fill in your path to libcygwin.a here (with no trailing slash)*** LIBPATH=/gnuwin32/H-i386-cygwin32/i386-cygwin32/lib # Compile source files: gcc -c foo.c gcc -c foo2.c gcc -c init.cc gcc -c fixup.c # Make .def file: echo EXPORTS > fooB.def nm foo.o foo2.o init.o fixup.o | grep '^........ [T] _' | sed 's/[^_]*_//' >> fooB.def # Link DLL. ld --base-file fooB.base --dll -o fooB.dll foo.o foo2.o init.o fixup.o \ $LIBPATH/libcygwin.a -e _dll_entry AT 12 dlltool --as=as --dllname fooB.dll --def fooB.def --base-file fooB.base --output-exp fooB.exp ld --base-file fooB.base fooB.exp --dll -o fooB.dll foo.o foo2.o init.o fixup.o \ $LIBPATH/libcygwin.a -e _dll_entry AT 12 dlltool --as=as --dllname fooB.dll --def fooB.def --base-file fooB.base --output-exp fooB.exp ld fooB.exp --dll -o fooB.dll foo.o foo2.o init.o fixup.o\ $LIBPATH/libcygwin.a -e _dll_entry AT 12 # Build the fooB.a lib to link to: dlltool --as=as --dllname fooB.dll --def fooB.def --output-lib fooB.a # Linking with main gcc main.c fooB.a -o main.exe --------------35C1200D19C-- - For help on using this list (especially unsubscribing), send a message to "gnu-win32-request AT cygnus DOT com" with one line of text: "help".