Subject: Building a relocatable DLL
From: [email-masked] (Mauricio Felix Vasconcellos)

27 May 1998 08:49:36 -0700
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
To: [email-masked]
Cc: [email-masked]

	I am having some problems to build a relocatable DLL from the guide/sample that you gave to me.

	First, I am using the Mingw32 version of C compiler, instead of Cygwin.  Because of that I do not know if my fixup.c program is working how it should be, because it is written for Cygwin.  But, at the moment, my big problem is with sed.exe that when i call it , it appears a message of unknow command.

	The program sed.exe is at c:\mingw32\bin how it should be and my path is like you tought me to do in the instalation.

	I need from you some help to solve this problem for me because i am trying hard to create this relocatable DLL but i am not been successful.

				Thanks, Mauricio

	Below, it comes the copy of the guide that you gave to me.

To: [email-masked]
From: John Cerney <[email-masked]>
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 <stdio.h>

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 <stdio.h>

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 <windows.h> 

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@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@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@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

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".