Visual Studio Compatibility
===========================

The lib-msvc-compat module detects whether the linker supports --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 --output-def during the build process. The variants we have considered include:

  * Use DUMPBIN /EXPORTS. The tool does not generate DEF files directly, so its output needs to be post processed manually.  The tool is documented to potentially not work with non-MS development tools (http://support.microsoft.com/kb/131313/en-us), which is the case when MinGW is used to build the library.

  * Use IMPDEF. There is a tool called IMPDEF (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.

  * 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.

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

     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

The 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 -version-info.  Assuming you have variables LT_CURRENT and LT_AGE defined for the CURRENT and AGE libtool version integers, you compute DLL_VERSION as follows:

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