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

The Protobuf C++ library has NDR problems: When linking against protobuf compiled with -DNDEBUG, application code must also be compiled with -DNDEBUG #10283

Closed
mortie opened this issue Jul 20, 2022 · 1 comment
Labels

Comments

@mortie
Copy link

mortie commented Jul 20, 2022

What version of protobuf and what language are you using?
Version: v21.2
Language: C++

What operating system (Linux, Windows, ...) and version? MacOS 12.4

What runtime / compiler are you using (e.g., python version or gcc version) Clang 14.0.6

What did you do?
Steps to reproduce the behavior:

  1. Install a Protobuf library compiled with -DNDEBUG (this is the default)
  2. Write some application code which somehow uses metadata_lite's InternalMetadata class (The code generated by protoc will do this)
  3. Compile your application code without -DNDEBUG, and link with the protobuf library

What did you expect to see

I expect this to work.

What did you see instead?

The linker complains that it can't find the symbol for InternalMetadata::~InternalMetadata. This is because when -DNDEBUG is defined, the destructor is defined in the header and no symbol for it gets produced as part of the library, whereas without -DNDEBUG, the destructor is just declared in the header and declared in a source file.

Ideally, I should be able to compile my application code in debug mode while using a protobuf library compiled in release mode. But if not, the documentation and getting started guides should be changed to make it extremely clear that you must compile your application code with -DNDEBUG, or maybe -DNDEBUG should even be added to the packageconfig files.

Here's the linker error produced when compiling my application code in debug mode:

Undefined symbols for architecture arm64:
  "google::protobuf::internal::InternalMetadata::~InternalMetadata()", referenced from:
      google::protobuf::MessageLite::~MessageLite() in connection_state.pb.cc.o
@mortie mortie added the untriaged auto added to all issues by default when created. label Jul 20, 2022
@mortie
Copy link
Author

mortie commented Jul 20, 2022

Actually, closing this as a duplicate. When I checked yesterday there was no open issue about this problem but since then, #9947 and #10271 happened. Looks like there's good progress on this.

@mortie mortie closed this as completed Jul 20, 2022
@fowles fowles added c++ and removed untriaged auto added to all issues by default when created. labels Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants