MIME-Version: 1.0 Content-Location: file:///C:/706BB24E/dllconstruction.htm Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="us-ascii" Building DLLs with Vector Pascal

Building DLLs with Vector Pascal

 =

You= must first install cygwin with the mingw libraries and the dlltools program=

 

Exa= mple make file to build a dll

---= -----------------------------------

 

CFLAGS=3D-mno-cygwin

# specify that cygwin gcc is to rely on the windows built in C libraries=

 

all: usedll.exe exampledll.dll

      usedll=

 

exampledll.s: exampledll.pas

      vpc-cygwin exampledll -S -Aexampledll.s

#    use the special cygwin version of the vpc compiler

 

exampledll.o: exampledll.s

      gcc $(CFLAG= S) -DBUILD_DLL   -c exampled= ll.s

 

rtl.o: rtl.c

      gcc $(CFLAG= S) -DBUILD_DLL   -c rtl.c

# compile it in a form suitable for use in a dll

 

rtl.c: ../../mmpc/rtl.c

      cp ../../mmpc/rtl.c rtl.c

# get a copy of the pascal run time library

 

exports.o: exampledll.a

       

 

exampledll.a: exampledll.def makefile

      dlltool -v<= span style=3D'mso-spacerun:yes'>    -e exports.o -l exampledll.a  -d exampledll.de= f -D exampledll.dll exampledll.o  r= tl.o

#     Note that you mus= t use the -D option to tell dlltool the name of the dll you will build=

#     this also reads = in the .def file it produces exampledll.a with which

#     you statically l= ink your c program ( it contains stubs to the real dynamic fns )

 

 

exampledll.dll: exports.o rtl.o exampledll.o

      gcc $(CFLAG= S) -shared exports.o rtl.o exampledll.o =   -o exampledll.dll 

# build the dll using the export spec produced by dlltool

 

usedll.o: usedll.c

      gcc $(CFLAG= S) -c usedll.c

# compile the c program to an object file

 

usedll.exe: usedll.o exampledll.a

      gcc $(CFLAG= S) usedll.c exampledll.a -o usedll

# link the c program with the exampledll stub library

 

 

-----------------------

Here is the C program that uses the dl= l

 

#include<stdio.h><= /o:p>

main(argc, argv)

{

printf("start\n");<= o:p>

dllinit();<= /p>

exampledll_exampleproc();/* n= ote that we must prefix the entry name by the library name */=

}

---------------------------

Here is the Vector Pascal DLL

-----------------------------=

library exampledll;

interface

   procedure exampleproc;<= /o:p>

implementation

  procedure exampleproc;<= /span>

  begin

    writeln(' procedure in= dll called');

  end;

 

 

end.

 

--------------------=

Here is the .def file

 

EXPORTS

exampledll_exampleproc

dllinit