google / flatbuffers

FlatBuffers: Memory Efficient Serialization Library

Home Page:https://flatbuffers.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

‘VerifyNestedFlexBuffer’ is not a member of ‘flexbuffers’ [C++, gcc 11.2.0, Arch Linux, Flatbuffers v2.0.6]

technobaboo opened this issue · comments

As it says in the title, after using flatc to rebuild the flatbuffer schemas that include flexbuffers (https://github.com/StardustXR/libstardustxr/blob/main/src/common/flatbuffers/message.fbs#L9) the error below occurs:

In file included from ../src/fusion/types/data/../../../common/messenger.hpp:9,
                 from ../src/fusion/types/data/../../messenger.hpp:3,
                 from ../src/fusion/types/data/../../fusion_internal.hpp:3,
                 from ../src/fusion/types/data/receiver.cpp:5:
../src/fusion/types/data/../../../common/flatbuffers/message.hpp: In member function ‘bool StardustXR::Message::Verify(flatbuffers::Verifier&) const’:
../src/fusion/types/data/../../../common/flatbuffers/message.hpp:76:25: error: ‘VerifyNestedFlexBuffer’ is not a member of ‘flexbuffers’
   76 |            flexbuffers::VerifyNestedFlexBuffer(data(), verifier) &&
      |

This issue never happened in 2.0.5.

Looks like you need to include flatbuffers.h, see comment:

#ifdef FLATBUFFERS_H_
// This is a verifier utility function that works together with the
// FlatBuffers verifier, which should only be present if flatbuffer.h
// has been included (which it typically is in generated code).
inline bool VerifyNestedFlexBuffer(const flatbuffers::Vector<uint8_t> *nv,
flatbuffers::Verifier &verifier) {
if (!nv) return true;
return verifier.Check(flexbuffers::VerifyBuffer(
nv->data(), nv->size(), verifier.GetFlexReuseTracker()));
}
#endif

That's the weird part, this is inside the c++ file that flatc generated by using the command

flatc -c *.fbs --gen-mutable --filename-suffix "" --filename-ext "hpp"

(see https://github.com/StardustXR/libstardustxr/blob/main/src/common/flatbuffers/message.hpp#L4-L8)

It includes the file, but still errors. Weirder still, this only ever occurs on v2.0.6 and not when reverting the flatbuffers version back to 2.0.5

If you remove the #ifdef FLATBUFFERS_H_ part does it work? I don't see anything obvious on why it isn't being linked in.

Looks like flexbuffers.h somehow got included manually before the generated code. Can you scan where you include flexbuffers.h and see what happens if you remove/move it to below the generated code include?

Yeah, let's leave this open for now, I'll need to look into how to do this correctly.

The problem is we ideally want to keep these headers independent.

One solution may be to just add a copy of that function to the generated code.

@technobaboo can you try out the linked PR to see if it works for you?

commented

I am having this issue.

This is merged now, so do you have the latest code?