该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
How to create a def file for a dllThere are several methods that can
be tried in order to create a definition file (.def) when one is not supplied.
One option is the tool, pexports which is provided in the MinGW
Utilities package, mingw-utils. See the Downloads page for the Current
version. If your dll has functions that use the Pascal calling convention,
you'll need to use the -o option.
Another option is the tool, impdef. More instructions on how to create
def files from dlls, a copy of impdef and more information on how to use it
are available at Colin Peters' site. See the Tutorials section.
Other compilers may also supply versions of the impdef program that can be
used to create a .def file which will work with any compiler. If you have
another version of impdef from another compiler, you may wish to try it.
Some handle the Pascal calling convention better than others. Borland has a
version of impdef and other compiler utilities available for download at
their Borland Community web site. Their Borland C++ version 5.5 compiler
includes several utilities to help convert between standard formats, their
formats and Microsoft's formats.
Another option is to use nm which comes with the MinGW distribution.
This option will not work for all dlls. Problems may occur if the dll is
stripped or compiled as 16 bit. To use this technique, you'll need to filter
the output from nm to create a def file. This can be done by hand in an
editor or automated using tools like Perl (Practical Extraction and Report
Language) or grep (global regular expression print) and sed (stream editor).
Even with the automated methods, you may have to make some changes by hand
if the Pascal calling convention is used by the dll. See Colin Peters' site
for more details on this case. (Versions of sed and grep are available from
various sites including archives that host gnuish MSDOS and archives such as
Virtually Un*x that contain Win32 ports of common Unix tools and from the
self-hosting MinGW port distribution. The ActiveState version of Perl works
well on Win32 platforms.) Here are examples of possible filtering
techniques.
This example uses grep and sed. If you have a dll named file.dll that
you wish to create a def file for named file.def, try the following:
echo EXPORTS > file.def
nm file.dll | grep ' T _' | sed 's/.* T _//' >> file.def
To create a library file named file.a
from the dll and def file, type: dlltool --def file.def --dllname file.dll --output-lib file.a
This example uses Perl. Copy the following Perl script to a file
called dll.pl and use it: open (OUTFILE,">dll.def");
print OUTFILE "EXPORTS\n";
open (INFILE,"dll.fil");
while()
{
if ($_ =~ /T _/)
{
$line = $_;
$line =~ s/.* T _//;
print OUTFILE $line;
}
}
close (INFILE);
close (OUTFILE);
If you have a dll file named file.dll. At
the command line, type: nm file.dll > dll.fil
perl dll.pl
A def file named dll.def will be created.
You can rename this as needed. You'll also probably want to delete dll.fil
when you're finished with this process.
If you don't have any of these tools on your system, you can still use
nm to create a def file and edit it by hand through an editor. For example: nm file.dll > dll.fil
find " T _" dll.fil > dll.def
Replace the line at the top of dll.def that
was created by the find program and shows a file name with a line that says
EXPORTS. Set your editor to search for T _ and erase it and
anything on the line before it, leaving only the routine names in the file.
If the previous options don't work, you can still try to create a def
file using the output from the objdump program (from the MinGW
distribution). Here's an example.
objdump -p file.dll > dll.fil
Search for [Ordinal/Name Pointer]
Table in dll.fil and use the list of functions following it to create
your def file.