Ticket #145 (defect)

Opened 2 years ago

Last modified 1 year ago

libusb-win32 0.1.12 triggers Windows std::min/max problem

Status: closed (fixed)

Reported by: dward Assigned to: eb
Priority: normal Milestone: release-3.1.2
Component: usrp Version: 3.0.3
Keywords: windows cygwin usrp libusb Cc: don2387ward@sprynet.com

Version 0.1.12 of libusb-win32 (now the current version in Cygwin) causes the compile of usrp_basic.cc to fail with several errors like:

usrp_basic.cc: In constructor `usrp_basic_rx::usrp_basic_rx(int, int, int, std::string, std::string)':
usrp_basic.cc:481: error: expected unqualified-id before '(' token

The errors occur on references to std::min() and std::max().

The problem is that usb.h now includes <windows.h> which defines min() and max() macros that conflict with std::min() and std::max(). This is a known, long-standing problem with Windows (see http://www.devx.com/tips/Tip/14540 and http://www.tutorials-blog.com/cpp/Where-stdmin/).

Some possible solutions are

  1. Don't use std::min or std::max (do this and MS will have won :-)
  2. Use alternative names defined in <windows.h> (see above)
  3. Use (e.g.) std::min<int> and std::max<int> (better than above?)
  4. Define NOMINMAX before #include <windows.h> (to make windows.h conform). This could be done by (a) setting CFLAGS (overrides flags set in configure), (b) setting CXX, (c) modifying the files that include windows.h and use min or max (currently only a few files in usrp), (d) modifying usb.h, or (e) adding #define NOMINMAX to config.h (only if HAVE_WINDOWS_H is defined).

Suggestions on the Right Way to address this are actively solicited. (My first choice is 4(e); second choice is 4(b).)

Change History

07/26/07 09:37:45: Modified by jcorgan

  • owner deleted.

07/26/07 09:39:06: Modified by jcorgan

  • owner set to nobody.

12/03/07 12:18:26: Modified by eb

  • owner changed from nobody to eb.
  • status changed from new to assigned.

implemented choice 4(e) in r7062.

12/04/07 16:28:25: Modified by eb

  • status changed from assigned to closed.
  • resolution set to fixed.

12/04/07 16:29:15: Modified by eb

  • milestone changed from to-be-decided to release-3.1.2.