-
Notifications
You must be signed in to change notification settings - Fork 15.5k
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
CMake issues when linking against Protobuf v22.3 with Abseil dependency #12637
Comments
I had the exact same issue. I spent a few hours battling the linker and came up with this:
not pretty. |
Seems like a dup of #12292 see #12292 (comment) You need to use |
Are there instructions for using protobufs without cmake or Bazel? |
Makes sense! Can the point of this issue be to add this to the documentation somewhere? I didn't see much docs on using protobuffs with cmake. From chat:
|
Maybe this example helps? https://github.com/protocolbuffers/protobuf/blob/main/examples/Makefile It uses |
Thanks. Will try it. But for the record I did try the pkg config shipped with protobuf and it didn't not include any of the abseil libraries. Possible I did it wrong of course. |
I think it is likely that you did nothing wrong, but ran into #12439, or #12698, or some other problem. If you have a repro that would help the Protobuf team. |
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment. This issue is labeled |
This is horrible! How is adding a new dependency like that breaking builds everywhere good software practice? |
Solution that worked for me on MinGW:
Basically downgrade to a version with the old dependencies. I will migrate to capnproto whenever this is no longer possible. |
This uses the config version of FindPackage. But we have to sue the module compatibiltiy, because the build commands of config version are totally different and undocumented. see protocolbuffers/protobuf#12637 (comment) see https://stackoverflow.com/a/56896032/620382
This uses the config version of FindPackage. But we have to sue the module compatibiltiy, because the build commands of config version are totally different and undocumented. see protocolbuffers/protobuf#12637 (comment) see https://stackoverflow.com/a/56896032/620382
For anyone stumbling upon this.. This should work with more recent versions of protobuf:
|
Where to add that code? I placed it in CMakeLists.txt near the end after And it just returned errors during $cmake -D BUILD_SHARED_LIBS=ON -D protobuf_BUILD_TESTS=ON -D utf8_range_ENABLE_INSTALL=ON . This was on version 25.1 on a Debian flavour linux My main problem is that cmake is not generating protobuf-targets.cmake and then not linking utf-8_range. Been trying to resolve this issue for 3 days now. Tried so many different versions, and edited files, but not getting anywhere. Anyone know why the script would not create that file? |
This should be getting generated in both the binary directory (during a build with |
That's how it should be, but Linux distros don't ship This Works For Me™:
# No changes here, keep using CMake module + protobuf_generate_*
find_package(Protobuf REQUIRED)
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS foo.proto bar.proto)
...
# Make it link with recent Protobuf
string(REGEX REPLACE "^[0-9]+\.([0-9]+\.[0-9]+)$" "\\1.0" proto_libver "${Protobuf_VERSION}")
if(proto_libver VERSION_GREATER_EQUAL "22")
find_package(PkgConfig REQUIRED)
pkg_check_modules(protobuf REQUIRED IMPORTED_TARGET protobuf=${proto_libver})
target_link_libraries(myapp PRIVATE PkgConfig::protobuf)
else()
target_link_libraries(myapp PRIVATE protobuf::libprotobuf)
endif() The regex converts the Protobuf version from the headers (e.g., Footnotes |
I have the same problem and ended up downgrading, too. Downgrading fixed the issue, but something tells me that some other issue with protobuf will pop up eventually. |
Since Google led me here, let me share this: #15604 (comment) Hope it might help. |
abseil-cpp 是一坨狗屎,加在工程里面一堆问题。 |
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment. This issue is labeled |
The current version can't work with CMake's own |
This is still broken. It's still "impossible" to use static linking with protobuf using official package. |
Unfortunately this is kind of awkward with CMake in general. One potential solution would be to honor the
Another option would be to just expose a
|
I think you truncated some of the output, can you copy it into a gist and past the link? |
Sorry, I have switched to an older version of protobuf, and the error is gone now. Thanks for the reply. |
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment. This issue is labeled |
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please reopen it. This issue was closed and archived because there has been no new activity in the 14 days since the |
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:
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
andAbseil
. To resolve these issues, I tried the following:find_package(utf8_range)
and addedutf8_range::utf8_validity utf8_range::utf8_range
to my target (resolving some errors).find_package(absl)
and and linked multipleabsl::*
targets (the same ones as in the cmake protobuf build script), but still had missing symbolsEventually, 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!
The text was updated successfully, but these errors were encountered: