Bug #145

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

Added by Anonymous over 6 years ago. Updated over 5 years ago.

Status:Closed Start date:
Priority:Normal Due date:
Assignee:Eric Blossom % Done:

0%

Category:-
Target version:release-3.1.2
Resolution:fixed

Description

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

History

Updated by Eric Blossom over 5 years ago

  • Status changed from New to Assigned

implemented choice 4(e) in r7062.

Updated by Eric Blossom over 5 years ago

  • Status changed from Assigned to Closed
  • Resolution set to fixed

Also available in: Atom PDF