small icon indicating copy to clipboard operation
small copied to clipboard

Issue integrating with Windows SDK

Open onneva opened this issue 4 years ago • 1 comments

Bug category

  • [x] bug - compilation error
  • [ ] bug - compilation warning
  • [ ] bug - runtime error
  • [ ] bug - runtime warning
  • [ ] bug - logic error

Describe the bug When trying to integrate 'small' with Windows, if you include <windows.h> in your project, it has defined small to be char. See:

https://stackoverflow.com/questions/27793470/why-does-small-give-an-error-about-char

Steps to Reproduce

Using MSVC, include <windows.h> and then include <small/vector.h> - a compiler error will occur

Platform

  • [ ] cross-platform issue - linux
  • [x] cross-platform issue - windows
  • [ ] cross-platform issue - macos

Environment Details:

  • OS: Windows
  • OS Version: Windows 10
  • Compiler: MSVC 16.11
  • Compiler version:

Additional context

onneva avatar Oct 01 '21 04:10 onneva

That's correct. For instance, the code in this library that includes windows.h undefines this macro:

https://github.com/alandefreitas/small/blob/9795e1f60eab809b200fc26ad3e7d05fef3cac42/source/small/detail/algorithm/console_unicode_guard.h#L19

Another solution would be to use boost.winapi inside the library to avoid including windows.h at all. That would involve a new dependency though.

In both cases, if you include windows.h before the containers are included, you would have to undefine this small macro yourself. It seems like just one more case of conflict with the macros in windows.h that happen all the time, like the MINMAX macros, that are in conflict even with std::max/std::min.

If you include windows.h before other libraries, I don't see any other possible solution to that other than not letting windows.h define these macros or undefine any macros windows.h defines.

alandefreitas avatar Oct 01 '21 14:10 alandefreitas