Sunday, August 29, 2010

MinGW Win32 installation to build libusb-1.0 Windows Backend

libusb-1.0 Windows backend currently supports Cygwin, MinGW and MinGW-w64, MSVC and WDK as the building tool. Cygwin, MSVC and WDK are more straightforward to install under Windows. But MinGW and MinGW-w64 are less straightforward.

One way to solve this issue is to use cross-compile under Linux. Leading Linux distros have MinGW and even MinGW-w64 packages. And the auto-tools (automake, autoconf, libtool) are normally installed under Linux. For MinGW-w64 build, one think to take note is that you probably need to update the libtool to 2.2.8 and later. Ubuntu 10.04 still ships an older version of libtool which does not recognize 64bit library properly.

Native build with MinGW/MSys from is really not that difficult once you have the base system and auto-tools installed. Pete Batard has a blog entry talking about the setup.

I just checked again and now it seems MinGW people has recognized the problem and come up with a new automatic installer for the MinGW/Msys base system installation. The name is mingw-get. It is currently in alpha but rather usable. I just used it to set up a new MinGW/MSys base system under Windows 7 32bit.

mingw-get can be downloaded from MinGW Sourceforge site.

Once you have the base system, you need to install auto-tools for MinGW (not the MSys version). The auto-tools may need some MSys dependency packages as well (eg: perl, crypt, etc). After that, it is quite simple to build libusb-1.0 Windows backend.

As for MinGW-w64 64bit build, it is similar. You can download the 32bit MSys base system and MinGW-w64 64bit Windows binary snapshots from its Sourceforge website.

Alternatively, you can get 64bit binary from the following website (only for 64bit Windows).

After that, you still need to get 32bit auto-tools installed. I recommend you to use the ones from and not the ones from MinGW-w64 sites as I have encountered problems with them.

If you are more adventurous, you can try the multilib option to build 32bit and 64bit using the same toolchain. Pete has a blog entry for this. I have not tried this and will probably not try this myself.

There is an existing package WPG System64 which include multilib based MinGW-w64 and all the tools (and more) to build libusb-1.0 Windows backend. However, we found out that the MinGW-w64 compiler included is a bit outdated that the output is not compatible with the current MinGW-w64 compile. So it is not recommended any more.


Thanh Cong Bui said...

Hi Xiaofan, would you please help me, plz?
I try to use Zadig to make install file for my device (Mode Extract file (Don't Install)), but it can't run. I have read some topic, and I thinked I need to use Inno Setup to make my install file standalone. So I modified example file in libwdi folder. I modified this line :
Parameters: " --inf ""3T_ROBOTICS_GROUP_TEST_CARD.inf"" --type 0 --cert """" --progressbar={wizardhwnd};
But it still not work.

Sorry for my bad English
Thank you for your time,

Xiaofan said...

Please use libusb-win32 or libusb mailing list for better help. I am not an expert in libwdi. Thanks.

Kannan said...

I tried to compile libusb 1.0 in windows using minGw i've installed basic setup and libtools for building the library, it get the following error when i run

"libtoolize: cannot list files in "c:\Program Files\Libtool\share\libtool"

is ter any tutorial explaining platform setup and compilation procedure