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 to `google::protobuf::internal::SerializeInternal' #4799

Closed
vervaekejonathan opened this issue Jun 20, 2018 · 6 comments
Closed
Assignees

Comments

@vervaekejonathan
Copy link
Contributor

vervaekejonathan commented Jun 20, 2018

Compiling protocolbuffers 3.5.1 for Cortex-M4 processor.

using the following commands:

 ./configure  --host=arm-none-eabi --build=x86_64-unknown-linux-gnu --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --localstatedir=/var --program-prefix= --disable-gtk-doc --disable-doc --disable-docs --disable-documentation --with-xmlto=no --with-fop=no --disable-dependency-tracking --disable-ipv6 --disable-debug --enable-static --enable-shared --with-protoc=/usr/local/bin/protoc CFLAGS=--specs=rdimon.specs CXXFLAGS=--specs=rdimon.specs CC=/github/arm-none-eabi_gcc_6.3.1/arm-none-eabi/bin/arm-none-eabi-gcc CXX=/github/arm-none-eabi_gcc_6.3.1/arm-none-eabi/bin/arm-none-eabi-g++ --without-thread-safety

cd src/

make CFLAGS=--specs=rdimon.specs CXXFLAGS='--specs=rdimon.specs -DLANG_CX11 -DPROTOBUF_WITHOUT_THREAD_SAFETY  -mthumb -mcpu=cortex-m4 -ffunction-sections  -mlong-calls -mcpu=cortex-m4 -Os' CC=/github/arm-none-eabi_gcc_6.3.1/arm-none-eabi/bin/arm-none-eabi-gcc CXX=/github/arm-none-eabi_gcc_6.3.1/arm-none-eabi/bin/arm-none-eabi-g++ libprotobuf-lite.la 

note: you need arm-none-eabi_gcc_6.3.1

This builds with after minor modifications to the Mutex library (replace the implementation with empty functions)

When linking the created libprotobuf-lite.a with my project, the linker complains about the following:

 Error		undefined reference to `google::protobuf::internal::SerializeInternal(unsigned char const*, google::protobuf::internal::FieldMetadata const*, int, google::protobuf::io::CodedOutputStream*)'	XXXX	XXXX\Debug\message_lite.cc	1
 Error		undefined reference to `google::protobuf::internal::SerializeInternalToArray(unsigned char const*, google::protobuf::internal::FieldMetadata const*, int, bool, unsigned char*)'	XXXX	XXXX\Debug\message_lite.cc	1
@acozzette
Copy link
Member

Those two functions are defined in src/google/protobuf/generated_message_util.cc, so I'm not sure why they would be missing. Could you check if they were included in libprotobuf-lite.a? Another thing to note is that SerializeInternal and SerializeInternalToArray are only used for the experimental table-driven serialization, which is not being used yet. So if you just want a quick fix to get things building, you could probably delete those functions and their call sites without breaking any real functionality.

@vervaekejonathan
Copy link
Contributor Author

It seems the function is included in the library (same for SerializeInternalToArray):

/github/arm-none-eabi_gcc_6.3.1/arm-none-eabi/arm-none-eabi/bin/readelf -a libprotobuf-lite.a  | ag SerializeInternal
Relocation section '.rel.text._ZN6google8protobuf8internal17SerializeInternalEPKhPKNS1_13FieldMetadataElPNS0_2io17CodedOutputStreamE' at offset 0x62f0 contains 71 entries:
Relocation section '.rel.ARM.exidx.text._ZN6google8protobuf8internal17SerializeInternalEPKhPKNS1_13FieldMetadataElPNS0_2io17CodedOutputStreamE' at offset 0x6528 contains 2 entries:
Unwind table index '.ARM.exidx.text._ZN6google8protobuf8internal17SerializeInternalEPKhPKNS1_13FieldMetadataElPNS0_2io17CodedOutputStreamE' at offset 0x1f74 contains 1 entries:
0x0 <_ZN6google8protobuf8internal17SerializeInternalEPKhPKNS1_13FieldMetadataElPNS0_2io17CodedOutputStreamE>: 0x8034afb0

@vervaekejonathan
Copy link
Contributor Author

vervaekejonathan commented Jun 21, 2018

I've found the problem, the declaration and definition of SerializeInternal and SerializeInternalToArray is different:

LIBPROTOBUF_EXPORT void SerializeInternal(const uint8* base, const FieldMetadata* table,
                       int num_fields, ::google::protobuf::io::CodedOutputStream* output);

void SerializeInternal(const uint8* base,
                       const FieldMetadata* field_metadata_table,
                       int32 num_fields,
                       ::google::protobuf::io::CodedOutputStream* output) {

should be

LIBPROTOBUF_EXPORT void SerializeInternal(const uint8* base, const FieldMetadata* table,
                       int32 num_fields, ::google::protobuf::io::CodedOutputStream* output);

When changing int to int32 in the declaration, the linker can find the definition and my program compiles!

@acozzette
Copy link
Member

Nice, I'm glad to hear you got it working! If you're interested you can send us a pull request with that fix and I'll merge it.

@vervaekejonathan
Copy link
Contributor Author

here you go!
#4815

@acozzette
Copy link
Member

Thanks!

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