Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined reference in inheritance.h in debug mode #735

Closed
xczdbb opened this issue Nov 28, 2017 · 6 comments
Closed

undefined reference in inheritance.h in debug mode #735

xczdbb opened this issue Nov 28, 2017 · 6 comments

Comments

@xczdbb
Copy link

xczdbb commented Nov 28, 2017

Learning from the example, my code looks like:

void DoSomething(
            bond::ext::gRPC::unary_call<
                bond::bonded<MyRequest>,
                bond::Void> call) override
        {
            auto request = call.request().Deserialize();
            //...
            call.Finish(bond::Void());
        }

When my project is compiled in Debug mode:

cmake -DCMAKE_BUILD_TYPE=Debug

I will get error messages when make:

CMakeFiles/server.dir/host/server.cpp.o: In function `_ZN4bond6detail17ParserInheritanceIRNS_19CompactBinaryReaderINS_11InputBufferEEENS_13DynamicParserIS5_EEE4ReadINS_4Void6SchemaENS_10SerializerINS_19CompactBinaryWriterINS_20CompactBinaryCounter4typeEEENS_16BuiltInProtocolsEEEEEN5boost12disable_if_cIXgtsr15hierarchy_depthIT_EE5valuesr14expected_depthIT0_EE5valueEbE4typeERKSL_RKSM_':
/usr/local/include/bond/core/detail/inheritance.h:99: undefined reference to `bond::Void::Schema::metadata'

Switching between Clang3.8 and GNU5.4 will not help. But everything is working fine in Release mode:

cmake -DCMAKE_BUILD_TYPE=Release //or simply cmake without the build type arg

Am I missing something?

@ara-ayvazyan
Copy link
Contributor

From the error message it seems like you're missing a dependency on bond static library?

@xczdbb
Copy link
Author

xczdbb commented Nov 29, 2017

@ara-ayvazyan But it's working in release mode. I don't see any dependency difference between debug and release.

@chwarr
Copy link
Member

chwarr commented Nov 29, 2017

It looks like the generated _grpc.h header may be missing a #include <bond/core/bond_reflection.h> when events or no-argument functions are being used.

Potential work around: add this before your include of the relevant generated _grpc.h headers:

#include <bond/core/bond_reflection.h>

After including this header your executable will have a dependency on libbond.a/bond.lib. That's where the metadata for types like bond::Void is compiled.

As for why it works in release but not in debug, that could be due to the optimizer determining that some section of code/template doesn't actually get executed/expanded and skipping it. There's one NDEBUG in the codebase (in value.h:851), but it doesn't look relevant here.

chwarr added a commit to chwarr/bond that referenced this issue Nov 29, 2017
When a service contains events or parameterless methods, the generated
code uses bond::Void as the request/result type. To serialize
bond::Void, bond_reflection.h needs to be included.

The generated service code now includes bond_reflection.h if any service
contains an event or a parameterless method.

Fixes microsoft#735
chwarr added a commit to chwarr/bond that referenced this issue Nov 29, 2017
When a service contains events or parameterless methods, the generated
code uses bond::Void as the request/result type. To serialize
bond::Void, bond_reflection.h needs to be included.

The generated service code now includes bond_reflection.h if any service
contains an event or a parameterless method.

Fixes microsoft#735
@chwarr
Copy link
Member

chwarr commented Nov 29, 2017

Can you try my proposed improvement?
This may improve the error message, but linking with libbond.a will still be required.

It's in the branch chwarr/grpc-include-reflection of my fork of Bond: https://github.com/chwarr/bond.git:

git checkout -b chwarr/grpc-include-reflection master
git pull https://github.com/chwarr/bond.git chwarr/grpc-include-reflection

@xczdbb
Copy link
Author

xczdbb commented Nov 29, 2017

@chwarr Your PR fixes the issue. Thanks.

@chwarr
Copy link
Member

chwarr commented Dec 5, 2017

Really, it fixes the issue completely? Hrm... I was just expecting a more informative compiler error.

Can you share the linker command line that was invoked when you built with my proposed fix? (I'm trying to see whether or not libbond.a was linked in. If it was linked in, that's what I expect is the real fix. If it wasn't linked in and this still fixed it, something else is going on that I want to dig into.)

ara-ayvazyan pushed a commit that referenced this issue Dec 6, 2017
When a service contains events or parameter-less methods, the generated
code uses `bond::Void` as the request/result type. To serialize
`bond::Void`, bond_reflection.h needs to be included.

The generated service code now includes bond_reflection.h if any service
contains an event or a parameter-less method.

Fixes #735
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants