protobuf
protobuf copied to clipboard
CMake issues when linking against Protobuf v22.3 with Abseil dependency
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:
- Manually
find_package(utf8_range)
and addedutf8_range::utf8_validity utf8_range::utf8_range
to my target (resolving some errors). - Manually added
find_package(absl)
and and linked multipleabsl::*
targets (the same ones as in the cmake protobuf build script), but still had missing symbols - 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!