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

missing abseil symbols when linking libprotobuf to application #19494

Closed
gmabey opened this issue Dec 3, 2024 · 8 comments
Closed

missing abseil symbols when linking libprotobuf to application #19494

gmabey opened this issue Dec 3, 2024 · 8 comments
Assignees
Labels

Comments

@gmabey
Copy link

gmabey commented Dec 3, 2024

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

What operating system (Linux, Windows, ...) and version?
Linux Ubuntu 22.04

What runtime / compiler are you using (e.g., python version or gcc version)
gcc 11.4.0
cmake 3.22.1

What did you do?
I built protobuf from source:

git checkout v3.29.0 --recurse-submodules
cd protobuf && mkdir build && cd build
cmake .. -DCMAKE_CXX_STANDARD=20 -DABSL_PROPAGATE_CXX_STD=ON -DCMAKE_INSTALL_PREFIX=/tmp/protobuf_install
cmake --build . -j 5
cmake --install .

which goes smoothly. However, when following the instructions on how to link an application to it, there are unresolved symbols.

What did you expect to see
Composing the very simplest of main.cpp files and using this CMakeLists.txt should successfully link -- according to the documentation that I've read at https://github.com/protocolbuffers/protobuf/blob/main/cmake/README.md

CMakeLists.txt

cmake -DCMAKE_PREFIX_PATH=/tmp/protobuf_install ..

What did you see instead?
Tons of unresolved symbol errors:
errs.txt

Anything else we should know about your project / environment
I think this is related to #19375 and #18933 but I created this issue because I wanted to establish this poor behavior on yet another version/OS combination.

There is a solution to this on StackOverflow: https://stackoverflow.com/questions/75667971/how-do-i-properly-link-the-google-protocol-buffers-library-with-my-application-a

I suspected it was something like that, but I thought that it was unthinkable that the protobuf authors would leave such a ragged edge on their otherwise smooth and silky interfaces.
However, it may be that the cmake build instructions have been neglected recently, like ever since abseil was introduced as a dependency (man_shrug).

I expected (and looked for, but did not find) a cmake variable that could be inserted into my target_link_libraries() line that would include all needed libraries in order for my application to link properly, and that's what I would recommend be done to improve this situation.
That is, if the cmake variable protobuf::libprotobuf simply included those 3 abseil libraries instead of just libprotobuf.a then it would be easily maintainable for application writers if more abseil libs were to become required.

Other thoughts:
If this really has been an issue since abseil was introduced as a dependency, then I have to wonder what isn't getting coverage in the release process for it to have gone untreated for this long.
I suspect that the bazel builds get the bulk of the attention from developers, but I naively suspect that there are more cmake users than bazel users out there.

@gmabey gmabey added the untriaged auto added to all issues by default when created. label Dec 3, 2024
@gmabey gmabey changed the title missing abseil symbols when linking libprotobuf to aplication missing abseil symbols when linking libprotobuf to application Dec 3, 2024
@bojle
Copy link

bojle commented Dec 7, 2024

i've resorted to using version 21.12 (which does not have any abseil dependence) as i didn't like the hacks that've been suggested as the fix.

@amlamarra
Copy link

Same here. I can't believe how many variations of this problem have been reported and how many of the "fixes" I've tried that didn't work.

@chenjie199234
Copy link

be stucked on v21.12

@shaod2 shaod2 added cmake and removed untriaged auto added to all issues by default when created. labels Dec 10, 2024
@acozzette
Copy link
Member

Adding this line to your CMakeLists.txt file should fix it: find_package(Protobuf CONFIG REQUIRED) According to @mkruskal-google, the underlying problem is that CMake ships an old version of our package config that doesn't know about the Abseil dependency.

@gmabey
Copy link
Author

gmabey commented Dec 16, 2024

Yes, that does fix all of my problem, thank you!
I had most of that line, just not the CONFIG word, so close.
So, I'm going to summarize that the underlying issue was my lack of cmake proficiency (which I thought I was pretty good at).
I have verified that this works on windows and ubuntu 22.04 -- and when protobuf has been compiled as shared libraries as well as static.

@Nullarity
Copy link

Well, I still have the same problem trying to build my project for arm64-android. I have practically the same working environment. find_package(Protobuf CONFIG REQUIRED) doesn't work for me, nor does targeting abseil libraries directly. In my case, it can't find absl::lts_20240722::cord_internal::cordz_next_sample.

@gmabey
Copy link
Author

gmabey commented Jan 4, 2025

@Nullarity Did you compile protobuf+abseil from source, or are you trying to use packages provided for arm64-android?

@Nullarity
Copy link

@gmabey I tried to use vcpkg; no luck. Right now, I'm trying to build abseil for Android, and this is quite a quest too. In the documentation, they say c++ 14, but when I try to build it, it fails on some 'consteval' expressions, which are c++ 20 features. Messy stuff.

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

7 participants