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

Linking error with on Ubuntu 18.04, Works on 20.04 #8107

Closed
mrspirytus opened this issue Dec 1, 2020 · 6 comments
Closed

Linking error with on Ubuntu 18.04, Works on 20.04 #8107

mrspirytus opened this issue Dec 1, 2020 · 6 comments

Comments

@mrspirytus
Copy link

mrspirytus commented Dec 1, 2020

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

What operating system (Linux, Windows, ...) and version?
Android
Linux localhost 3.18.20-dev+ #31 SMP PREEMPT Sat Oct 17 10:49:56 PDT 2020 aarch64 Android

What runtime / compiler are you using (e.g., python version or gcc version)
clang version 8.0.0 (tags/RELEASE_800/final)
Target: aarch64-unknown-linux-android
Thread model: posix

What did you do?
protobuf 3.14.0 was build from source using cmake on Ubutnu 20.04 and Android phone.

protoc --version
WARNING: linker: protoc: unused DT entry: type 0x1d arg 0x96663
libprotoc 3.14.0

Steps to reproduce the behavior:

  1. proto file starts with
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
  1. cmake ..
  2. make

Here linker parameters used

/usr/bin/c++   -Wall -pedantic -Wextra -Wunused-parameter -Wformat-security -Wunreachable-code -fdata-sections -ffunction-sections -Wcast-align -Wunused-function -Wempty-body -Wpointer-arith -Wwrite-strings -Wno-date-time -g3 -O0   CMakeFiles/traDaemon.dir/src/traDaemon.cpp.o CMakeFiles/traDaemon.dir/src/main.cpp.o  -o ../../bin/aarch64/bin/traDaemon -Wl,-rpath,/data/projects/traDaemon/build/bin/aarch64/lib:/system/lib64: ../../bin/aarch64/lib/libtraVComlib.so.1.0 ../../bin/aarch64/lib/libabSsllib.so.1.0 ../../bin/aarch64/lib/libabTcplib.so.1.0 /usr/lib/libssl.so /usr/lib/libcrypto.so /system/lib64/liblog.so /usr/local/lib/libprotobuf.a /usr/local/lib/libprotobuf-lite.a ../../bin/aarch64/lib/librtaMsglib.so.1.0 -lpthread 

What did you expect to see

[100%] Linking CXX executable ../../bin/aarch64/bin/traDaemon
/usr/bin/aarch64-linux-android-ld: ../../bin/aarch64/lib/librtaMsglib.so.1.0: undefined reference to `google::protobuf::internal::LookUpEnumValue(google::protobuf::internal::EnumEntry const*, unsigned long, google::protobuf::StringPiece, int*)'
/usr/bin/aarch64-linux-android-ld: ../../bin/aarch64/lib/librtaMsglib.so.1.0: undefined reference to `google::protobuf::internal::InitializeEnumStrings(google::protobuf::internal::EnumEntry const*, int const*, unsigned long, google::protobuf::internal::ExplicitlyConstructed<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > >*)'
/usr/bin/aarch64-linux-android-ld: ../../bin/aarch64/lib/librtaMsglib.so.1.0: undefined reference to `google::protobuf::internal::LookUpEnumName(google::protobuf::internal::EnumEntry const*, int const*, unsigned long, int)'
clang-8: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [src/traDaemon/CMakeFiles/traDaemon.dir/build.make:156: bin/aarch64/bin/traDaemon] Error 1
make[1]: *** [CMakeFiles/Makefile2:962: src/traDaemon/CMakeFiles/traDaemon.dir/all] Error 2
make: *** [Makefile:152: all] Error 2

Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).

Anything else we should know about your project / environment
If I build protobuf on Android phone with shared libraries vs default static I can link just fine. Above linking is only related if protobuf was build static libs only.
On Ubuntu desktop my cmake project can link to both shared and static protobuf libs

Building with static (linking problem)

cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_CXX_FLAGS="-Wno-sign-conversion" -DCMAKE_INSTALL_PREFIX=/usr/local

Building with shared (NO linking problem)

cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_CXX_FLAGS="-Wno-sign-conversion" -DBUILD_SHARED_LIBS=ON LDFLAGS="-llog" -DCMAKE_INSTALL_PREFIX=/usr/local

@mrspirytus mrspirytus changed the title Linking error with static libs on Android but NOT shared libs Linking error with on Ubuntu 18.04, Works on 20.04 Jan 18, 2021
@mrspirytus
Copy link
Author

mrspirytus commented Jan 18, 2021

So today I did try to build my code on Ubuntu 18.04. I did build protobuf 3.14.0 (static libs) on this system and it was installed to /usr/local. I followed the same procedure on Ubuntu 20.04 since I am using my small bash script to automate builds. Both were build using cmake.
Now same source code builds and links on 20.04 but on 18.04 I get a linking error.
Googling around I found a few other people on other projects having the same issue. Well, the protobuf version they used was older.

One thing I noticed is that I did build protobuf forcing c++17 vs default c++11. Below linking looks like complains about c++11?
std::__cxx11::basic_string I will try to rebuild it with c++ and see if this fixes things

Here is a linking error from 18.04

 undefined reference to `google::protobuf::internal::LookUpEnumValue(google::protobuf::internal::EnumEntry const*, unsigned long, google::protobuf::StringPiece, int*)'
 undefined reference to `google::protobuf::internal::LookUpEnumName(google::protobuf::internal::EnumEntry const*, int const*, unsigned long, int)'
undefined reference to `google::protobuf::internal::InitializeEnumStrings(google::protobuf::internal::EnumEntry const*, int const*, unsigned long, google::protobuf::internal::ExplicitlyConstructed<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >*)'

I also stumbled on this issue that was resolved #4799
Also, something additional I noticed. I was using lite messages and replaced
message.SerializeToArray() with message.SerializeAsString()
After trying to recompile I still got a linking issue but with one message less, witch is SerializeToArray()

The remaining linking errors are google::protobuf::internal::LookUpEnumName() which I am not using directly in my code.

Looks like these symbols are in both files which I am using both to link to

$ nm -C /usr/local/lib/libprotobuf.a  | grep LookUpEnumName
0000000000000140 T google::protobuf::internal::LookUpEnumName(google::protobuf::internal::EnumEntry const*, int const*, unsigned long, int)

$ nm -C /usr/local/lib/libprotobuf-lite.a  | grep LookUpEnumName
0000000000000140 T google::protobuf::internal::LookUpEnumName(google::protobuf::internal::EnumEntry const*, int const*, unsigned long, int)

Anyone experienced this and know what might be the problem? I will try in the meantime rebuild with c++11

EDIT: Forgot to mention versions of compilers
20.04 : g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
18.04: g++ (Ubuntu/Linaro 8.4.0-1ubuntu1~18.04) 8.4.0

@mrspirytus
Copy link
Author

So I just rebuild of 3.14.0 again skipping c++17. So it should be c++11 which is what is default in cmake file
cmake -DCMAKE_BUILD_TYPE=Release -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_CXX_FLAGS="-Wno-sign-conversion" ..

Still having same linking errors in my application

@mrspirytus
Copy link
Author

Next I did rebuild protobuf 3.14.0 with -Dprotobuf_BUILD_SHARED_LIBS=ON and recompiling my app .... WORKS.
Is there anything strange going on with Static?
Any devs can help pointing out where I should look to figure out why static is not linking?

@elharo elharo added the c++ label Aug 31, 2021
@elharo
Copy link
Contributor

elharo commented Aug 31, 2021

seems unlikely to be a protoc bug but reopen if it is. For questions or troubleshooting, please see the protobuf mailing list: https://groups.google.com/forum/#!forum/protobuf or Stack Overflow https://stackoverflow.com/questions/tagged/protocol-buffers

@elharo elharo closed this as completed Aug 31, 2021
@elharo elharo added the protoc label Aug 31, 2021
@JoelLinn
Copy link
Contributor

JoelLinn commented Jan 9, 2022

Having the exact same linker errors (even same symbols) when using i686-w64-mingw32-g++-posix from Ubuntu 21.10

@fowles
Copy link
Contributor

fowles commented Jan 10, 2022

@JoelLinn what version of protobuf are you tryied to build?

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

4 participants