c-strtof, c-strtod, c-strtold: Make multithread-safe.
[gnulib.git] / doc / ld-output-def.texi
blob3e142fac7b521479250df1320bc7e3a97ef109d9
1 @node Visual Studio Compatibility
2 @section Visual Studio Compatibility
3 @cindex DEF files
4 @cindex LD DEF files
6 The @code{lib-msvc-compat} module detects whether the linker supports
7 @code{--output-def} when building a library.  That parameter is used
8 to generate a DEF file for a shared library (DLL).  DEF files are
9 useful for developers that use Visual Studio to develop programs that
10 links to your library.  See the GNU LD manual for more information.
12 There are other ways to create a DEF file, but we believe they are all
13 sub-optimal to using @code{--output-def} during the build process.
14 The variants we have considered include:
16 @itemize @bullet
17 @item Use DUMPBIN /EXPORTS.
18 This is explained in
19 @url{https://docs.microsoft.com/en-us/cpp/build/reference/dash-exports}.
20 The tool does not generate DEF files directly, so its output needs to
21 be post processed manually:
22 @smallexample
23 $ @{ echo EXPORTS; \
24     dumpbin /EXPORTS libfoo-0.dll | tail -n+20 | awk '@{ print $4 @}'; \
25   @} > libfoo-0.def
26 $ lib /def:libfoo-0.def
27 @end smallexample
29 @item Use IMPDEF.
30 There is a tool called IMPDEF
31 that can generate DEF files.  However, it is not part of a standard
32 Visual Studio installation.  Further, it is documented as being an
33 unreliable process.
35 @item Use DLLTOOL.
36 The dlltool is part of the MinGW suite, and thus not part of a
37 standard Visual Studio installation.  The documentation for the IMPDEF
38 tool claims that DLLTOOL is the wrong tool for this job.  Finally,
39 DLLTOOL does not generate DEF files directly, so it requires
40 post-processing of the output.
42 @end itemize
44 If you are using libtool to build your shared library, here is how to
45 use this module.  Import @code{lib-msvc-compat} to your project, and
46 then add the following lines to the @code{Makefile.am} that builds the
47 library:
49 @smallexample
50 if HAVE_LD_OUTPUT_DEF
51 libfoo_la_LDFLAGS += -Wl,--output-def,libfoo-$(DLL_VERSION).def
52 libfoo-$(DLL_VERSION).def: libfoo.la
53 defexecdir = $(libdir)
54 defexec_DATA = libfoo-$(DLL_VERSION).def
55 DISTCLEANFILES += $(defexec_DATA)
56 endif
57 @end smallexample
59 The @code{DLL_VERSION} variable needs to be defined.  It should be the
60 shared library version number used in the DLL filename.  For Windows
61 targets you compute this value from the values you pass to Libtool's
62 @code{-version-info}.  Assuming you have variables @code{LT_CURRENT}
63 and @code{LT_AGE} defined for the @code{CURRENT} and @code{AGE}
64 libtool version integers, you compute @code{DLL_VERSION} as follows:
66 @smallexample
67 DLL_VERSION=`expr $@{LT_CURRENT@} - $@{LT_AGE@}`
68 AC_SUBST(DLL_VERSION)
69 @end smallexample