From: wcn@cs.brown.edu (Wen-Chun Ni)
Subject: Re: GCC and DLL's
Organization: Brown University Department of Computer Science
Date: Mon, 25 Jan 1993 19:46:20 GMT

In article <1993Jan25.153958.4298@VFL.Paramax.COM> rickt@rmtc.paramax.com (Rick Thompson [RMTC/ISP]) writes:
>
>Hello,
>
>I've just obtained GCC from hobbes and was wondering if I can create dll's with
>it?  Regular exe's went fine.  If it is possible can someone send me an example
>make file or whatever you think appropriate?
>
>

I asked the question a couple of days before, but nobody replied. I went
ahead and tried it myself. Up to now, almost all testable DLL samples in
the redbook and November PDK are compiled and ran without problems.
Several points should be noted:

	* Look at the manual entry of emxomfld in /emx/doc/emxdev.doc.
	  Also check the section about how to create a DLL.
	* Compile the program with
		gcc -Zdll -c foo.c
	  It is better to add -Zmt to use the run-time DLL.
	  Also you may want
		gcc -Zdll -Zomf -c foo.c
 	  to produce foo.obj, rather than foo.o.
	* If you directly use link386, do remember to include
	   /emx/lib/dll0.obj in the object file section.
	   libc.lib, libgcc.lib, libemx1.lib, libemx2.lib, and libos2.lib
	   are possibly the minimal set of libraries you want to
	   load if you use link386.
	   A good example is 
	    link386 \emx\lib\dll0.obj foo.obj, foo.dll, 	\
		  $(ALL_THE_LIBS), foo;
	   I don't remember those cryptic link386 flags, check it
	   yourself.
  	* You don't need PDK to get a running DLL but it's recommended.

The following is my version of Makefile for pwfolder in the redbooks.
Enjoy it!

#****************************************************************************
#  Dot directive definition area (usually just suffixes)
#****************************************************************************

.SUFFIXES: .c .o .obj .dll .csc .sc .h .ih .ph .psc .rc .res

#****************************************************************************
#  Environment Setup for the component(s).
#****************************************************************************


#
# Compiler/tools Macros
#

CFLAGS     = -O -c -Zdll -Zmt
CC         = gcc 
LINK       = link386
LDFLAGS    = /noi /map /nol /nod /exepack /packcode /packdata /align:16
LIBS       =  libc+libgcc+libemx1+libemx2+libos2

#****************************************************************************
# Set up Macros that will contain all the different dependencies for the
# executables and dlls etc. that are generated.
#****************************************************************************

OBJS= pwfolder.obj \emx\lib\dll0.obj

#****************************************************************************
#   Setup the inference rules for compiling source code to
#   object code.
#****************************************************************************

.c.obj:
        $(CC) $(CFLAGS) -c $<
	emxomf $*.o

.csc.ih:
	sc $<

all: pwfolder.dll

pwfolder.obj: $*.c $*.ih $*.h  $*.sc

pwfolder.dll: $(OBJS) pwfolder.res
         $(LINK) $(LDFLAGS) $(OBJS),$@,,$(LIBS),$*;
         rc $*.res $*.dll

pwfolder.res: pwfolder.rc
         rc -r $*.rc $*.res

Wen-Chun Ni, wcn@cs.brown.edu
-------------------------------------------------------------------
  "Great spirits have always encountered violent opposition 
	from mediocre minds..."    -- Albert Einstein
Newsgroups: comp.os.os2.programmer