Subject: Re: DLL: How to generate .def from UNIX src
From: [email-masked] (Jason Tishler)

27 Jan 1997 07:21:47 -0800
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
References: <[email-masked]>
Reply-To: [email-masked]
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="------------13D263A96B02"
X-Mailer: Mozilla 3.0Gold (WinNT; I)
Original-To: Valery Fine <[email-masked]>
Original-CC: [email-masked]
Original-Sender: [email-masked]

This is a multi-part message in MIME format.

--------------13D263A96B02
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

>   Does any body there can point me how one can generate a def files 
> from the source (C/C++) to make DLL's?

I wrote a perl script that automatically generates the DLL definition
file needed to build a C++ DLL.  Perhaps it will meet your needs or at
least be a good starting point.

USAGE:
=====

The following is the command line syntax for symbols.pl:

symbols.pl [-i IgnoreFile] [-m|-l] [-o OutputFile] [-t TemplateFile] files ...
where:
    -i => specifies ignorable regular expression file (one per line)
    -m => map of C++ names to C name-decorated names
    -l => list of C name-decorated names (default)
    -o => specifies output filename
    -t => specifies template filename

The following demonstrates how I could use symbols.pl to create my
defintion file called NtService.def:

perl -S symbols.pl -i NtService.ignore -t NtService.template -o NtService.def NtService.obj

OPTIONS:
=======

The -i option specifies a file of regular expressions (one per line) that
match symbols that you do NOT want to export.  For example, here is my
NtService.ignore:

--- begin of NtService.ignore ---
allocator
basic_string
char_traits
list
--- end of NtService.ignore ---

Which shows that I want to ignore some symbols from the Standard Template
Library.

The -m and -l (default) options toggle between the map and list formats.
The map format is just a tab separated list of the C++ names onto the
name-decorated names -- it is intended to be human readable.  The list
format just lists the name-decorated names -- it is intended to be used
to construct a DLL definition file.

The -o option specifies the output file name.  If not specified, then the
output goes to standard output.

The -t option specifies the template file which is just prepended to the
output stream.  For example, here is my NtService.template:

--- begin of NtService.template ---
;
; $Id: NtService.template,v 1.1 1997/01/10 20:13:26 jt Exp $
;

; NtService.def : Declares the module parameters for the DLL.

LIBRARY      "NtService"
DESCRIPTION  'NtService Windows Dynamic Link Library'

EXPORTS
--- end of NtService.template ---

MSVC++ Setup:
====== =====

1. Add an .obj file to your project

2. Under "Build/Setting.../Custom Build/Win32 Debug" for the above .obj
file add the following:

    Description:      Performing Custom Exported Symbol Definition Step

    Build command(s): perl -S symbols.pl -i $(ProjDir)\NAME.ignore -t $(ProjDir)\NAME.template -o $(ProjDir)\NAME.def $(InputDir)\*.obj

    Output file(s):   $(ProjDir)\NAME.def

where:
    NAME is a name of your choice

3. Under "Build/Setting.../Custom Build/Win32 Release" for the above .obj
file select "Exclude file from build."

4. Under "Tools/Options.../Directories/Executable files" add the path to
perl.

CAVEATS:
=======

1. symbols.pl needs a later version of perl for Win32 than the one
supplied in the NT Resource Kit.  I can supply an older version of
symbols.pl that works with the Resource Kit's version of perl, if
necessary.

2. Debug build must be built before Release builds (to (re)generate the
definition file).

3. Debug builds will always rebuild the definition file and relink the
DLL even if there were no changes to the source.

MISC:
====

1. symbols.pl is attached.

2. perl for Win32 can be found at ActiveWare (http://www.activeware.com/).

2. Do you know how to tell MSVC++ in "Build/Setting.../Custom Build" to
use multiple input files to build one output file?

3. Please provide feedback on bugs, enhancements, etc.

Enjoy,
Jason

-- 
Jason Tishler                        Phone: +1 (212) 989-4455 ext. 120
Box Hill Systems Corporation         Fax:   +1 (212) 989-6817
161 Avenue of the Americas           Email: [email-masked]
New York, NY 10013 USA               WWW:   http://www.boxhill.com

--------------13D263A96B02
Content-Type: application/x-perl; name="symbols.pl"
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename="symbols.pl"

--------------13D263A96B02--

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