flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

[c++] idl.h ERROR enum conflicts with windows define

Open zsd4yr opened this issue 11 months ago • 6 comments

https://github.com/google/flatbuffers/commit/f8380178600ff8255cc47694bddb321b2a9f648b https://github.com/wine-mirror/wine/blob/f2eebf36266fa0c3809472701763a6e468cd5ba3/include/wingdi.h#L1598

The result is a compile error if you reference both 1>/sdk/flatbuffers/24.3.25/include\flatbuffers/idl.h(636,49): error : expected identifier 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um\wingdi.h(118,29): message : expanded from macro 'ERROR'

zsd4yr avatar Jan 14 '25 20:01 zsd4yr

Same for me on a MSYS2 windows machine. When windows.h is imported and idl.h there is a conflict. I had to do something like:

#define FLATBUFFER_VERSION_INT (FLATBUFFERS_VERSION_MAJOR * 10000 + FLATBUFFERS_VERSION_MINOR * 100 + FLATBUFFERS_VERSION_REVISION)
#if FLATBUFFER_VERSION_INT > 230121
#define FLATBUFFER_ERROR_8483
#endif

#ifdef FLATBUFFER_ERROR_8483
#define FLATBUFFER_ERROR_VAR_BACKUP ERROR
#undef ERROR
#endif

before idl.h is included.

Very ugly hack but it works. Note that it undefines ERROR from the windows include which might be a bad idea. I wonder why this issue wasn't reported much earlier because that change is from 2023.

GMellar avatar Mar 11 '25 14:03 GMellar

This issue is stale because it has been open 6 months with no activity. Please comment or label not-stale, or this will be closed in 14 days.

github-actions[bot] avatar Sep 09 '25 20:09 github-actions[bot]

not-stale

zsd4yr avatar Sep 09 '25 20:09 zsd4yr

I have pushed a branch here, would one of you all be willing to test it?

jtdavis777 avatar Nov 21 '25 14:11 jtdavis777

Hey @jtdavis777 would you mind making a PR so I can see the diff?

zsd4yr avatar Nov 27 '25 02:11 zsd4yr

I've opened the PR but realized I may have been a bit overzealous with my fix direction. Handling this in the preprocessor may be the better fix as what I've written may break other code bases.

jtdavis777 avatar Nov 27 '25 02:11 jtdavis777