summaryrefslogtreecommitdiff
path: root/doc/ld-output-def.texi
blob: 526ccb042bf629ca5b24c365874e33a2dbbbe063 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
@node Visual Studio Compatibility
@section Visual Studio Compatibility
@cindex DEF files
@cindex LD DEF files

The @code{lib-msvc-compat} module detects whether the linker supports
@code{--output-def} when building a library.  That parameter is used
to generate a DEF file for a shared library (DLL).  DEF files are
useful for developers that use Visual Studio to develop programs that
links to your library.  See the GNU LD manual for more information.

There are other ways to create a DEF file, but we believe they are all
sub-optimal to using @code{--output-def} during the build process.
The variants we have considered include:

@itemize @bullet
@item Use DUMPBIN /EXPORTS.
This is explained in @url{http://support.microsoft.com/kb/131313/en-us}.
The tool does not generate DEF files directly, so its output needs to
be post processed manually:
@smallexample
$ @{ echo EXPORTS; \
    dumpbin /EXPORTS libfoo-0.dll | tail -n+20 | awk '@{ print $4 @}'; \
  @} > libfoo-0.def
$ lib /def:libfoo-0.def
@end smallexample

@item Use IMPDEF.
There is a tool called IMPDEF
(@url{http://sei.pku.edu.cn/~caodg/course/c/reference/win32/tools/dlltool.html})
that can generate DEF files.  However, it is not part of a standard
Visual Studio installation.  Further, it is documented as being an
unreliable process.

@item Use DLLTOOL.
The dlltool is part of the MinGW suite, and thus not part of a
standard Visual Studio installation.  The documentation for the IMPDEF
tool claims that DLLTOOL is the wrong tool for this job.  Finally,
DLLTOOL does not generate DEF files directly, so it requires
post-processing of the output.

@end itemize

If you are using libtool to build your shared library, here is how to
use this module.  Import @code{lib-msvc-compat} to your project, and
then add the following lines to the @code{Makefile.am} that builds the
library:

@smallexample
if HAVE_LD_OUTPUT_DEF
libfoo_la_LDFLAGS += -Wl,--output-def,libfoo-$(DLL_VERSION).def
defexecdir = $(bindir)
defexec_DATA = libfoo-$(DLL_VERSION).def
DISTCLEANFILES += $(defexec_DATA)
endif
@end smallexample

The @code{DLL_VERSION} variable needs to be defined.  It should be the
shared library version number used in the DLL filename.  For Windows
targets you compute this value from the values you pass to Libtool's
@code{-version-info}.  Assuming you have variables @code{LT_CURRENT}
and @code{LT_AGE} defined for the @code{CURRENT} and @code{AGE}
libtool version integers, you compute @code{DLL_VERSION} as follows:

@smallexample
DLL_VERSION=`expr $@{LT_CURRENT@} - $@{LT_AGE@}`
AC_SUBST(DLL_VERSION)
@end smallexample