From 201c710dcd1b843367f85055811c502c343c63b4 Mon Sep 17 00:00:00 2001 From: Yuriy Chernyshov Date: Mon, 19 Jul 2021 14:14:42 +0300 Subject: [PATCH] Fix undefined symbol error around SharedCtor() Apparently, #8532 was incorrect if applied to 3.17.x branch. 3.17.x changed code generation to mark `SharedCtor()` and `SharedDtor()` as inline in .pb.cc. It looks like we have a compile-time undefined behavior in C++ now. As cppreference.com [says](https://en.cppreference.com/w/cpp/language/inline): _The definition of an inline function <...> must be reachable in the translation unit where it is accessed (not necessarily before the point of access)._ As protobuf allows custom plugins to generate custom code, there is no limitation on where SharedCtor couble be possible referenced from. In our case we have SharedCtor invoked from corresponding `.pb.h` code, thus triggering: ``` ld: error: undefined symbol: package::Message::SharedCtor()` >>> referenced by file.pb.h:$$$$ ``` If this patch is not applicable, I can take a look into changing the code generation, but doing this will be harder then removing _inline_. --- src/google/protobuf/compiler/cpp/cpp_message.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc index 79ed8aaa27cb..ff8b30834e89 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message.cc +++ b/src/google/protobuf/compiler/cpp/cpp_message.cc @@ -2381,7 +2381,7 @@ std::pair MessageGenerator::GenerateOffsets( void MessageGenerator::GenerateSharedConstructorCode(io::Printer* printer) { Formatter format(printer, variables_); - format("inline void $classname$::SharedCtor() {\n"); + format("void $classname$::SharedCtor() {\n"); std::vector processed(optimized_order_.size(), false); GenerateConstructorBody(printer, processed, false);