The problem may look familiar but I think it still is somewhat different from the questions asked before on the same topic (although the 'solution' may be the same, i.e. there is no real fix other than to mess with the 3rd party codebase)
Here goes:
A portable C/C++ framework builds on Linux and Windows. It makes use of
the Microsoft C type BOOL that is included in winwindef.h, part of the Windows Platform SDK. the underlying type is 'int', which makes sense if you're defining values '1' as 'TRUE' and '0' as 'FALSE'.
#ifdef __cplusplus extern "C" { #endif ... typedef int BOOL; ... #endif
with a preprocessor branch, for linux BOOL is sensibly typedef'ed as an int (int32_t to be exact) to preserve bytesize congruence between data representations. (I know, this is not sufficient and endedness is swapped, but most code remains simple.)
typedef int32_t BOOL;
This platform code is proprietary ( me as author ) so changes can be made.
When a downstream lib or application wants to include LASlib (a part of LAStools) at https://github.com/LAStools/LAStools/tree/master/LASlib the compiler flags conflicting BOOL types, because LASlib contains a file named 'mydefs.hpp' that, when compiled under Windows uses an int as underlying type, but for linux seems to prefer the C++ 'bool'.
#if defined(_MSC_VER) && (_MSC_VER < 1300) || defined (__MINGW32__)
typedef int BOOL;
#else
typedef bool BOOL;
#endif
I'm not a Microsoftie, but this is completely backwards (see also Using boolean values in C). I can imagine that the linux code produces smaller data fragments with platform branches everywhere but imho that should be left to the compiler. Also, the preprocessor guards aren't something I should manipulate (and would cause mayhem in CMake land) so I'm sort of stuck with this.
So now I'm faced with a dilemma;
- change the LASlib code (which I'm not keen on, it's supposed to be 3rd party)
- pretend that BOOL should be 'bool' in linux for the entire framework, but that means mapping a C++ type construct into a C type, giving up datasize stability, and obviously tomorrow another lib can retype it as a PlanetCookooDevice class type, so it doesn't solve the real problem.
I've read the answers to Typedef redefinition with different types ('signed char' vs 'bool') and BOOL redefinition after including minwindef.h but I feel the issue is more serious.
So, is there some sort of catch-all for conflicting types in the global namespace, or even at 'C' level? LASlib is a C++ header-only lib, but I can't extern "C" the entire thing either.