CMake issues when linking against Protobuf v22.3 with Abseil dependency
envgap__protocolbuffers__protobuf-12637
Original GitHub issue ↗Opened 2023-05-02
01 / FAILURE SIGNATURE
As reported upstream
No identifying execution failure has been captured.
Not checked yet.
- No curated issue-specific recipe or verified environment fix is available.
02 / ENVIRONMENT RECIPE
- Base commit
Not freshly verified- Manifest
CMakeLists.txt- Reproduce
Awaiting issue-specific recipe- Run under trace
Awaiting a meaningful runtime command
03 / ORIGINAL ISSUE TEXT
protocolbuffers/protobuf #12637 · read the original issue
Hello!
I encountered issues when using Protobuf v22.3 with CMake due to its Abseil dependency. I have documented the steps I took and the issues I faced below.
I built and installed Protobuf v22.3 from source with the following commands:
```
$ cmake -Dprotobuf_BUILD_TESTS=OFF -DABSL_PROPAGATE_CXX_STD=ON -Dprotobuf_BUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=/usr/local ..
$ cmake --build . -j 10
$ sudo cmake --install .
```
Then, in my project's CMakeLists.txt, I added:
`find_package(Protobuf REQUIRED)`
and linked the Protobuf libraries to my target:
`target_link_libraries(${TARGET_NAME} PRIVATE protobuf::libprotobuf protobuf::libprotoc)`
However, when building my project, I faced multiple unresolved symbols related to `utf8-range` and `Abseil`. To resolve these issues, I tried the following:
1. Manually `find_package(utf8_range)` and added `utf8_range::utf8_validity utf8_range::utf8_range` to my target (resolving some errors).
2. Manually added `find_package(absl)` and and linked multiple `absl::*` targets (the [same ones as in the cmake protobuf build script](https://github.com/protocolbuffers/protobuf/blob/482156c0f96dd670b9f1ba4f946e66edeb04535f/cmake/abseil-cpp.cmake#L46-L81)), but still had missing symbols
3. Built Protobuf as a static library and linked against it, but still faced unresolved symbols related to Abseil.
Eventually, I reverted to Protobuf v3.21.12, which has no Abseil dependency while still supporting CMake. With this version, I could build and run my project without any issues using `find_package(Protobuf REQUIRED)`, `target_link_libraries` as before and nothing else.
I believe there should be a more straightforward way to handle the Abseil dependencies when using Protobuf v22.3 with CMake. Also, I still don't understand why a static build of protobuf would require additional imports. Any guidance or improvements in this area would be greatly appreciated.
Thank you!04 / LABELS
Labels from the report text only; not yet run
No supported category has been assigned.
Label rules and the text that matched
[]
Issue-specific recipe and runtime smoke command require review against the complete issue and repository.
Legacy reproduction is generic install-only; match the actual issue failure before admission.