With the attached, it becomes possible to use a MinGW produced DLL with
an MSVC application, and vice versa. Currently, this is not possible.
To cut a long story short, setting our calling convention to WINAPI
(__stdcall for x86_32) and also supporting x86_64 (the latter reverting
WINAPI to __cdecl) creates a whole stream a problems with regards to
interchangeability, some of which are detailed at [1]. Basically, every
compiler uses its own decoration and doesn't seem to give much of a damn
about how this may create problem.
The only way I found to obtain interchangeability is to rely on MinGW
and the GNU tools to produce a DLL that is also compatible with MSVC, by
creating an import lib that adds aliases (see the .def file) and also
kills the at decoration. This however requires re-generating the DLL
after libtool has had its way with it, but that's not exactly a big deal.
Note that unlike what we had in -pbatard, this patch drops the automated
generation of the .def when invoking autogen. The reason is that the
method used in -pbatard is pretty blind (add all the @0, @4, @8...
aliases, with the expectation that one of these will match) whereas,
once we have Jenkins operational and MinGW generation support, we should
be able to use the better alternate method of parsing the original MinGW
generated DLL using a short script (see [2]) to compare with the
existing .def, and fail the build while providing the exact details of
what needs to be added to the .def file for a new API call.
Using this method, we should ensure that the .def only has the aliases
we need.
Finally, be aware that this patch marks the end of the -pbatard branch
(at long last!). There's only one very minor patch that I plan to pick
up from there to bridge the gap, but I am not planning to bring any more
update to -pbatard at this stage and will flag it as discontinued, just
like HID. Unfortunately, this means that unless somebody can make the
case for CMake support, which exists in -pbatard but not in mainline,
potential CMake users will lose the good work that was done by Vitali.
From now on, the only private branch I may spend time on will be
hotplug, though most of that effort is likely to be spent on moving away
from a -pbatard branch and into a mainline branch.
Regards,
/Pete
[1] http://wyw.dcweb.cn/stdcall.htm
[2]
http://libusbx.git.sourceforge.net/git/gitweb.cgi?p=libusbx/libusbx;a=commit;h=b88ce7d2450a2d77b84cca5ffe6bcb449a5ae05b
>From 5a82b9dd6268deb7c45e1dd89d2867d57ba87fbc Mon Sep 17 00:00:00 2001
From: Pete Batard <[email protected]>
Date: Wed, 6 Jun 2012 13:44:31 +0100
Subject: [PATCH] Windows: Enable MinGW and MSVC DLL interchangeability
* Because we use the WINAPI calling convention, the def file MUST have the @n
aliases. There is no way around this as MinGW's .o use decoration always
for __stdcall, which can't be turned off.
* dlltool must therefore be invoked to create a proper import lib from the .def,
using the --kill-at option.
* To do that, a CREATE_IMPORT_LIB autotools variable is introduced.
* Note: the .def file is currently maintained manually.
---
configure.ac | 2 ++
libusb/Makefile.am | 9 +++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac
index b305f68..9377c6b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -71,6 +71,7 @@ case $host in
AC_MSG_RESULT([Windows])
backend="windows"
threads="windows"
+ create_import_lib="yes"
;;
*-cygwin*)
AC_MSG_RESULT([Cygwin (using Windows backend)])
@@ -128,6 +129,7 @@ AM_CONDITIONAL(OS_DARWIN, test "x$backend" = xdarwin)
AM_CONDITIONAL(OS_OPENBSD, test "x$backend" = xbsd)
AM_CONDITIONAL(OS_WINDOWS, test "x$backend" = xwindows)
AM_CONDITIONAL(THREADS_POSIX, test "x$threads" = xposix)
+AM_CONDITIONAL(CREATE_IMPORT_LIB, test "x$create_import_lib" = "xyes")
if test "$threads" = posix; then
AC_DEFINE(THREADS_POSIX, 1, [Use POSIX Threads])
fi
diff --git a/libusb/Makefile.am b/libusb/Makefile.am
index 0e7fc88..4a6859e 100644
--- a/libusb/Makefile.am
+++ b/libusb/Makefile.am
@@ -1,3 +1,5 @@
+all: libusb-1.0.la libusb-1.0.dll
+
lib_LTLIBRARIES = libusb-1.0.la
LINUX_USBFS_SRC = os/linux_usbfs.c
@@ -30,6 +32,13 @@ OS_SRC = $(WINDOWS_USB_SRC)
libusb-1.0.rc: version.h
endif
+libusb-1.0.dll:
+if CREATE_IMPORT_LIB
+# Rebuild the import lib from the .def so that MS and MinGW DLLs can be
interchanged
+ $(AM_V_GEN)$(DLLTOOL) $(DLLTOOLFLAGS) --kill-at --input-def
$(srcdir)/libusb-1.0.def --dllname $@ --output-lib .libs/[email protected]
+endif
+
+
if THREADS_POSIX
THREADS_SRC = os/threads_posix.h os/threads_posix.c
else
--
1.7.10.msysgit.1
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
libusbx-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libusbx-devel