Closed ToKiNoBug closed 1 year ago
This signals that our Abseil dependency isn't being properly linked in. If you have a system installation at the wrong version that could explain it
This signals that our Abseil dependency isn't being properly linked in. If you have a system installation at the wrong version that could explain it
I'm sorry but I have only one protobuf, it is installed at the compiler's prefix. So find_package must have found the correct one, but some absl libs are not linked to my executable. I have tried manually adding many absl libs links to executable, but I still failed. Do you know which library in absl should be linked?
I can confirm this issue. getting abseil log related linking issues with both MinGW and Visual Studio 2022. I worked around it with by manually specifying the abseil libraries in target_link_libraries, see: https://github.com/strawberrymusicplayer/strawberry/blob/69658f20222a2f87af3b025032def7b35730f76d/ext/libstrawberry-tagreader/CMakeLists.txt#L53
Here is the linking issue with Visual Studio 2022:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "public: __cdecl absl::lts_20230125::log_internal::LogMessageFatal::LogMessageFatal(char const *,int,class absl::lts_20230125::string_view)" (??0LogMessageFatal@log_internal@lts_20230125@absl@@QEAA@PEBDHVstring_view@23@@Z) referenced in function "public: bool __cdecl spb::tagreader::Message::has_is_media_file_request(void)const " (?has_is_media_file_request@Message@tagreader@spb@@QEBA_NXZ) C:\Data\Projects\strawberry\strawberry\out\build\x64-debug\strawberry C:\Data\Projects\strawberry\strawberry\out\build\x64-debug\tagreaderworker.cpp.obj 1
Error LNK2001 unresolved external symbol "public: __cdecl absl::lts_20230125::log_internal::LogMessageFatal::LogMessageFatal(char const *,int,class absl::lts_20230125::string_view)" (??0LogMessageFatal@log_internal@lts_20230125@absl@@QEAA@PEBDHVstring_view@23@@Z) C:\Data\Projects\strawberry\strawberry\out\build\x64-debug\strawberry C:\Data\Projects\strawberry\strawberry\out\build\x64-debug\libstrawberry-tagreader.lib(tagreadermessages.pb.cc.obj) 1
Error LNK2019 unresolved external symbol "public: __cdecl absl::lts_20230125::log_internal::LogMessageFatal::~LogMessageFatal(void)" (??1LogMessageFatal@log_internal@lts_20230125@absl@@QEAA@XZ) referenced in function "public: bool __cdecl spb::tagreader::Message::has_is_media_file_request(void)const " (?has_is_media_file_request@Message@tagreader@spb@@QEBA_NXZ) C:\Data\Projects\strawberry\strawberry\out\build\x64-debug\strawberry C:\Data\Projects\strawberry\strawberry\out\build\x64-debug\tagreaderworker.cpp.obj 1
Error LNK2001 unresolved external symbol "public: __cdecl absl::lts_20230125::log_internal::LogMessageFatal::~LogMessageFatal(void)" (??1LogMessageFatal@log_internal@lts_20230125@absl@@QEAA@XZ) C:\Data\Projects\strawberry\strawberry\out\build\x64-debug\strawberry C:\Data\Projects\strawberry\strawberry\out\build\x64-debug\libstrawberry-tagreader.lib(tagreadermessages.pb.cc.obj) 1
Error LNK2019 unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * __cdecl absl::lts_20230125::log_internal::MakeCheckOpString<void const *,void const *>(void const *,void const *,char const *)" (??$MakeCheckOpString@PEBXPEBX@log_internal@lts_20230125@absl@@YAPEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEBX0PEBD@Z) referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * __cdecl absl::lts_20230125::log_internal::Check_NEImpl<class spb::tagreader::IsMediaFileRequest const *,class spb::tagreader::IsMediaFileRequest *>(class spb::tagreader::IsMediaFileRequest const * const &,class spb::tagreader::IsMediaFileRequest * const &,char const *)" (??$Check_NEImpl@PEBVIsMediaFileRequest@tagreader@spb@@PEAV123@@log_internal@lts_20230125@absl@@YAPEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBQEBVIsMediaFileRequest@tagreader@spb@@AEBQEAV567@PEBD@Z) C:\Data\Projects\strawberry\strawberry\out\build\x64-debug\strawberry C:\Data\Projects\strawberry\strawberry\out\build\x64-debug\libstrawberry-tagreader.lib(tagreadermessages.pb.cc.obj) 1
Error LNK1120 3 unresolved externals C:\Data\Projects\strawberry\strawberry\out\build\x64-debug\strawberry C:\Data\Projects\strawberry\strawberry\out\build\x64-debug\strawberry-tagreader.exe 1
Here is how I build protobuf with abseil for Visual Studio:
https://github.com/strawberrymusicplayer/strawberry-msvc/blob/5f4f9a33193b051a97e19a16eee32b47b961d049/build.bat#L1288
Similar in GitHub Actions:
https://github.com/strawberrymusicplayer/strawberry-msvc-dependencies/blob/643245abdd06f90e433d5134dce8aafcc1fc6d0c/.github/workflows/build.yml#L2308
I use -Dprotobuf_ABSL_PROVIDER="module"
For MinGW I build Protobuf with -Dprotobuf_ABSL_PROVIDER='package'
.
I can confirm this issue. getting abseil log related linking issues with both MinGW and Visual Studio 2022. I worked around it with by manually specifying the abseil libraries in target_link_libraries, see: https://github.com/strawberrymusicplayer/strawberry/blob/69658f20222a2f87af3b025032def7b35730f76d/ext/libstrawberry-tagreader/CMakeLists.txt#L53
Here is the linking issue with Visual Studio 2022:
Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "public: __cdecl absl::lts_20230125::log_internal::LogMessageFatal::LogMessageFatal(char const *,int,class absl::lts_20230125::string_view)" (??0LogMessageFatal@log_internal@lts_20230125@absl@@QEAA@PEBDHVstring_view@23@@Z) referenced in function "public: bool __cdecl spb::tagreader::Message::has_is_media_file_request(void)const " (?has_is_media_file_request@Message@tagreader@spb@@QEBA_NXZ) C:\Data\Projects\strawberry\strawberry\out\build\x64-debug\strawberry C:\Data\Projects\strawberry\strawberry\out\build\x64-debug\tagreaderworker.cpp.obj 1 Error LNK2001 unresolved external symbol "public: __cdecl absl::lts_20230125::log_internal::LogMessageFatal::LogMessageFatal(char const *,int,class absl::lts_20230125::string_view)" (??0LogMessageFatal@log_internal@lts_20230125@absl@@QEAA@PEBDHVstring_view@23@@Z) C:\Data\Projects\strawberry\strawberry\out\build\x64-debug\strawberry C:\Data\Projects\strawberry\strawberry\out\build\x64-debug\libstrawberry-tagreader.lib(tagreadermessages.pb.cc.obj) 1 Error LNK2019 unresolved external symbol "public: __cdecl absl::lts_20230125::log_internal::LogMessageFatal::~LogMessageFatal(void)" (??1LogMessageFatal@log_internal@lts_20230125@absl@@QEAA@XZ) referenced in function "public: bool __cdecl spb::tagreader::Message::has_is_media_file_request(void)const " (?has_is_media_file_request@Message@tagreader@spb@@QEBA_NXZ) C:\Data\Projects\strawberry\strawberry\out\build\x64-debug\strawberry C:\Data\Projects\strawberry\strawberry\out\build\x64-debug\tagreaderworker.cpp.obj 1 Error LNK2001 unresolved external symbol "public: __cdecl absl::lts_20230125::log_internal::LogMessageFatal::~LogMessageFatal(void)" (??1LogMessageFatal@log_internal@lts_20230125@absl@@QEAA@XZ) C:\Data\Projects\strawberry\strawberry\out\build\x64-debug\strawberry C:\Data\Projects\strawberry\strawberry\out\build\x64-debug\libstrawberry-tagreader.lib(tagreadermessages.pb.cc.obj) 1 Error LNK2019 unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * __cdecl absl::lts_20230125::log_internal::MakeCheckOpString<void const *,void const *>(void const *,void const *,char const *)" (??$MakeCheckOpString@PEBXPEBX@log_internal@lts_20230125@absl@@YAPEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEBX0PEBD@Z) referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * __cdecl absl::lts_20230125::log_internal::Check_NEImpl<class spb::tagreader::IsMediaFileRequest const *,class spb::tagreader::IsMediaFileRequest *>(class spb::tagreader::IsMediaFileRequest const * const &,class spb::tagreader::IsMediaFileRequest * const &,char const *)" (??$Check_NEImpl@PEBVIsMediaFileRequest@tagreader@spb@@PEAV123@@log_internal@lts_20230125@absl@@YAPEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBQEBVIsMediaFileRequest@tagreader@spb@@AEBQEAV567@PEBD@Z) C:\Data\Projects\strawberry\strawberry\out\build\x64-debug\strawberry C:\Data\Projects\strawberry\strawberry\out\build\x64-debug\libstrawberry-tagreader.lib(tagreadermessages.pb.cc.obj) 1 Error LNK1120 3 unresolved externals C:\Data\Projects\strawberry\strawberry\out\build\x64-debug\strawberry C:\Data\Projects\strawberry\strawberry\out\build\x64-debug\strawberry-tagreader.exe 1
Here is how I build protobuf with abseil for Visual Studio: https://github.com/strawberrymusicplayer/strawberry-msvc/blob/5f4f9a33193b051a97e19a16eee32b47b961d049/build.bat#L1288 Similar in GitHub Actions: https://github.com/strawberrymusicplayer/strawberry-msvc-dependencies/blob/643245abdd06f90e433d5134dce8aafcc1fc6d0c/.github/workflows/build.yml#L2308 I use
-Dprotobuf_ABSL_PROVIDER="module"
For MinGW I build Protobuf with
-Dprotobuf_ABSL_PROVIDER='package'
.
Thanks! I'm glad to see that I'm not the only one who meets this weird issue.
Your code implies that developer should link absl_log_internal_message absl_log_internal_check_op
or abseil_dll
manually. I think it is some kind of bug in protobuf's cmake script, because users have to learn a lot of abseil before learning protobuf.
I suppose that required abseil libs should be linked publicly instead of privately.
Our Abseil dependency is public, so I'm not sure why it isn't getting pulled in transitively. Both of the cmake targets you mentioned are new to Abseil's latest LTS release (20230125.2). This tells me that you have an older version of Abseil installed on your system that's missing these libraries. Setting -Dprotobuf_ABSL_PROVIDER='package'
forces the protobuf build to search for system installations of Abseil, rather than the pinned sub-module we provide
There isn't any older abseil version installed. I'm getting similar log_internal related linking errors in 4 places including cross-compiling on Linux, a clean Windows 10 MSVC physical machine, github actions both MSVC and MinGW cross-compilation, cross-compiling on my own linux machine . Setting protobuf_ABSL_PROVIDER to module doesn't help. I don't use protobuf from git, but compile the latest release, it has just an empty third_party/abseil-cpp/ directory, so I copy over the latest version (20230125.2).
hmm lemme see if I can try to reproduce this then. We test against MSVC in our CI, so I'm not sure what the issue could be here
Just to clarify, the linking errors does not occur when compiling protobuf itself, but occurs when compiling my own program with protobuf, so the linker flags for the abseil libraries aren't passed on for some reason, I spent a few hours looking into it, but could not figure it out.
Can you provide the commands you use to build and install protobuf too? Also, do the missing targets end up in the installation lib
directory?
I am build protobuffer for android.
ld: error: undefined symbol: absl::lts_20230125::Mutex::~Mutex()
referenced by generated_message_reflection.cc:3447 (/opt/protobuf-22.3/src/google/protobuf/generated_message_reflection.cc:3447) generated_message_reflection.cc.o:(google::protobuf::(anonymous namespace)::AssignDescriptorsImpl(google::protobuf::internal::DescriptorTable const, bool)) in archive /opt/protobuf-22.3/build/libprotobuf.a referenced by generated_message_reflection.cc:3447 (/opt/protobuf-22.3/src/google/protobuf/generated_message_reflection.cc:3447) generated_message_reflection.cc.o:(google::protobuf::(anonymous namespace)::AssignDescriptorsImpl(google::protobuf::internal::DescriptorTable const, bool)) in archive /opt/protobuf-22.3/build/libprotobuf.a referenced by generated_message_reflection.cc:3420 (/opt/protobuf-22.3/src/google/protobuf/generated_message_reflection.cc:3420) generated_message_reflection.cc.o:(google::protobuf::(anonymous namespace)::MetadataOwner google::protobuf::internal::OnShutdownDelete<google::protobuf::(anonymous namespace)::MetadataOwner>(google::protobuf::(anonymous namespace)::MetadataOwner)::'lambda'(void const)::__invoke(void const)) in archive /opt/protobuf-22.3/build/libprotobuf.a referenced 9 more times
ld: error: undefined symbol: absl::lts_20230125::base_internal::SpinLockWait(std::__ndk1::atomic
I believe the issue is that something like find_package(protobuf REQUIRED)
uses the embedded FindProtobuf
package from CMake:
https://cmake.org/cmake/help/latest/module/FindProtobuf.html
This package has not been updated to know about the Abseil
dependency. One needs to use:
find_package(protobuf REQUIRED CONFIG)
Hah thank you Carlos! That perfectly explains why our examples directory is building ok but this one isn't :)
Not sure if related, but we are having same problem (tons of undefined reference to
absl::lts_20230125::crc_internal::xxxxx`) in our project which uses Meson to build C++ and abseil-cpp dep using C++17:
https://github.com/versatica/mediasoup/pull/1081#issuecomment-1551532267
Sounds related, the fix here was to specify CONFIG
on the find_package
call for protobuf. The FindProtobuf
function that ships with CMake doesn't include our new dependency on Abseil
So, I am getting the same thing. I have built the 3.23 version of protobuf on a Windows 10 Enterprise and VS 2022 with the 10.0.17763.0 SDK version and toolset 143.
I downloaded the release with empty third_party and downloaded the dependencies and generated a configuration to use dlls. I went for the minimum abseil builds.
When I try to link a library that depends on this stuff, I added the .libs and cannot get this sucker to link without a bunch of errors resembling
1>dvDmCommand.pb.obj : error LNK2001: unresolved external symbol "public: __cdecl absl::lts_20230125::log_internal::LogMessageFatal::LogMessageFatal(char const *,int,class absl::lts_20230125::string_view)" (??0LogMessageFatal@log_internal@lts_20230125@absl@@QEAA@PEBDHVstring_view@23@@Z) 1>dvDmTaskOrganization.pb.obj : error LNK2001: unresolved external symbol "public: cdecl absl::lts_20230125::log_internal::LogMessageFatal::~LogMessageFatal(void)" (??1LogMessageFatal@log_internal@lts_20230125@absl@@QEAA@XZ) 1>dvDmUi.pb.obj : error LNK2001: unresolved external symbol "public: cdecl absl::lts_20230125::log_internal::LogMessageFatal::~LogMessageFatal(void)" (??1LogMessageFatal@log_internal@lts_20230125@absl@@QEAA@XZ)
We do not generate our solution file from CMakefile.lst, so one piece of advice I saw above, doesn't seem like an option.
To me the the dependencies of libprotobuf include the abseil_dll.lib which seemed to me like that was enough, but since all the unreferenced links seem to be abseil stuff, I added the rest of the .libs. Couldn't hurt right? Well, that didn't solve the issue.
I am ready to delete the entire download, and instead clone the repo with the sub-repo dependencies and try it that way.
However, that just doesn't feel to me like that should be the solution. Clearly other people have this issue, so what am I missing here?
After adding CONFIG
to find_package(protobuf REQUIRED)
, it doesn't set any variables such as PROTOBUF_PROTOC_EXECUTABLE
or even PROTOBUF_LIBRARY
anymore, despite finding and loading the abseil, utf8_range and protobuf cmake configuration files, as running cmake with --debug-find
shows. Only when setting protobuf_MODULE_COMPATIBLE=ON
these variables are set, but then I still get the abseil undefined symbol errors.
I'm using protobuf 23.4 on Arch Linux and have been investigating this issue for a few days now. Does anyone know what might be going wrong?
@jkhsjdhjs have you found out any solution? I am facing the exact same problem.
any inputs will help.
@harsh-im Sadly not, didn't have time to look into this issue further.
Are you also on Arch Linux? I thought about it being related to how it is packaged there. On the other hand many other projects build fine with protobuf 23 on Arch Linux, so it seems rather unlikely.
Which project are you trying to build? Maybe it's related to the project/the cmake file and we can find any similarities.
Which CMake version are you using? I have been using 3.26.4 when I had this issue, didn't test with 3.27.1 yet.
Did you try https://github.com/protocolbuffers/protobuf/issues/12292#issuecomment-1529680040
Further, I think this is related to #12746.
@jkhsjdhjs I am trying to link grpc to my c++ library and I am using docker image (ubuntu:latest) from macos. I am using latest cmake version i.e. 3.27.1
Getting following error during build
Did you try #12292 (comment)
Further, I think this is related to #12746.
I am using find_package(Protobuf CONFIG REQUIRED)
I believe the issue is that something like
find_package(protobuf REQUIRED)
uses the embeddedFindProtobuf
package from CMake:https://cmake.org/cmake/help/latest/module/FindProtobuf.html
This package has not been updated to know about the
Abseil
dependency. One needs to use:find_package(protobuf REQUIRED CONFIG)
Hi,
We used to import protobuf with find_package(protobuf REQUIRED)
, adding CONFIG
breaks our current CMakeLists because variables such as Protobuf_INCLUDE_DIRS
or Protobuf_PROTOC_EXECUTABLE
are no longer defined. Is there any plan to update FindProtobuf.cmake
or any documentation available on how to retrieve these variables using CONFIG
mode?
You can pass -DCMAKE_FIND_PACKAGE_PREFER_CONFIG
to cmake and it will use "Config" first.
Otherwise use the following so it's compatible with older versions of Protobuf too.
find_package(Protobuf CONFIG)
if(NOT Protobuf_FOUND)
find_package(Protobuf REQUIRED)
endif()
For the library use protobuf::libprotobuf
, for the executable use protobuf::protoc
.
But I think variables for include and library dirs are not set.
There was also a bug in protobuf-generate.cmake (https://github.com/protocolbuffers/protobuf/issues/12450) Can be worked around it with:
if(NOT protobuf_PROTOC_EXE)
set(protobuf_PROTOC_EXE "protobuf::protoc")
endif()
@jkhsjdhjs I am trying to link grpc to my c++ library and I am using docker image (ubuntu:latest) from macos. I am using latest cmake version i.e. 3.27.1
Getting following error during build
@jonaski can you please help me with this?
Getting following error during build
Hmm, same issue when using
find_package(Protobuf CONFIG)
if(NOT Protobuf_FOUND)
find_package(Protobuf REQUIRED)
endif()
if(NOT PROTOBUF_PROTOC_EXECUTABLE)
set(PROTOBUF_PROTOC_EXECUTABLE "protobuf::protoc")
endif()
Same results also with
find_package(Protobuf CONFIG REQUIRED)
if(NOT PROTOBUF_PROTOC_EXECUTABLE)
set(PROTOBUF_PROTOC_EXECUTABLE "protobuf::protoc")
endif()
and -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON
@jkhsjdhjs are you able to reproduce it?
For the library use
protobuf::libprotobuf
Lol, thanks @jonaski! The following fixes the undefined references problem for me:
set(PROTOBUF_LIBRARY "protobuf::libprotobuf")
I added it after the find_package(Protobuf REQUIRED CONFIG)
call. Passing -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON
to CMake doesn't seem to be necessary.
This even works when omitting CONFIG
from the find_package()
call, so just find_package(Protobuf REQUIRED)
also works with this.
@jkhsjdhjs can you please share the CMakeLists.txt file and the command you used? I am still getting the error.
@jkhsjdhjs You only need to pass CMAKE_FIND_PACKAGE_PREFER_CONFIG
if you are not already using find_package(Protobuf CONFIG)
.
@harsh-im In case it helps, here is my CMake Protobuf setup:
Finding protobuf: https://github.com/strawberrymusicplayer/strawberry/blob/bfb95d503a2679db6ef09d74d6b3057e006d3114/CMakeLists.txt#L119 Setting libraries variable: https://github.com/strawberrymusicplayer/strawberry/blob/bfb95d503a2679db6ef09d74d6b3057e006d3114/ext/libstrawberry-tagreader/CMakeLists.txt#L9 Linking here: https://github.com/strawberrymusicplayer/strawberry/blob/bfb95d503a2679db6ef09d74d6b3057e006d3114/ext/libstrawberry-tagreader/CMakeLists.txt#L52
@harsh-im I suggest you share your CMakeLists file and the complete compile errors within code
instead of a screenshot if you still have issues.
And you don't really have to set a variable (like Protobuf_LIBRARY
or Protobuf_LIBRARIES
), you can just link directly to protobuf::libprotobuf
But it's probably a good idea to set protobuf_PROTOC_EXE
before protobuf_generate
for now, as there was a bug in CMake. if you have users using another version of CMake affected by that bug.
@harsh-im Not sure if it helps, but this is the cmake file that sets up protobuf: https://github.com/p4lang/p4c/blob/7f53a12719478890820e2024652cc5a1a7ae7a69/cmake/Protobuf.cmake And these are the adjustments I did:
diff --git a/cmake/Protobuf.cmake b/cmake/Protobuf.cmake
index 943cf37b0..66d5cd5a4 100644
--- a/cmake/Protobuf.cmake
+++ b/cmake/Protobuf.cmake
@@ -11,7 +11,11 @@ macro(p4c_obtain_protobuf)
set(SAVED_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
endif()
- find_package(Protobuf 3.0.0 REQUIRED)
+ find_package(Protobuf 23.4.0 REQUIRED)
+ if(NOT PROTOBUF_PROTOC_EXECUTABLE)
+ set(PROTOBUF_PROTOC_EXECUTABLE "protobuf::protoc")
+ endif()
+ set(PROTOBUF_LIBRARY "protobuf::libprotobuf")
if(ENABLE_PROTOBUF_STATIC)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${SAVED_CMAKE_FIND_LIBRARY_SUFFIXES})
endif()
But as @jonaski pointed out, I should rather replace the reference to PROTOBUF_LIBRARY
with protobuf::libprotobuf
: https://github.com/p4lang/p4c/blob/7f53a12719478890820e2024652cc5a1a7ae7a69/control-plane/CMakeLists.txt#L99
Seems like this line was the culprit all along. So I can recommend that you check your target_link_libraries()
calls.
@jkhsjdhjs You only need to pass CMAKE_FIND_PACKAGE_PREFER_CONFIG if you are not already using find_package(Protobuf CONFIG).
Ah I see, I thought it was necessary when using both, REQUIRED
and CONFIG
. Thanks for pointing that out!
Since I didn't have to use find_package(Protobuf CONFIG)
, it seems like cmakes' find_protobuf()
has already been fixed in 3.27
?
@jonaski PFA CMakelist file CMakeLists.txt
Error log:
19.45 [ 83%] Building CXX object tests/CMakeFiles/test_nativelib.dir/test_nativelib.cpp.o
19.67 [100%] Linking CXX executable test_nativelib
19.84 /usr/bin/ld: ../libnativelib.so: undefined reference to google::protobuf::internal::ArenaStringPtr::Set(absl::lts_20230125::string_view, google::protobuf::Arena*)' 19.84 /usr/bin/ld: ../libnativelib.so: undefined reference to
google::protobuf::internal::VerifyUTF8(absl::lts_20230125::string_view, char const)'
19.84 /usr/bin/ld: ../libnativelib.so: undefined reference to `absl::lts_20230125::cord_internal::InitializeCordRepExternal(absl::lts_20230125::string_view, absl::lts_20230125::cord_internal::CordRepExternal)'
19.84 collect2: error: ld returned 1 exit status
19.84 gmake[2]: [tests/CMakeFiles/test_nativelib.dir/build.make:98: tests/test_nativelib] Error 1
19.84 gmake[1]: [CMakeFiles/Makefile2:126: tests/CMakeFiles/test_nativelib.dir/all] Error 2
19.84 gmake: *** [Makefile:91: all] Error 2
@jkhsjdhjs I'm on 3.27.1, and the issue is not fixed, upstream issue here: https://gitlab.kitware.com/cmake/cmake/-/issues/25079
If you passed CMAKE_FIND_PACKAGE_PREFER_CONFIG
, CMake caches that, so you need to delete CMakeCache.txt
before running CMake again to make it not use that option anymore.
@jonaski PFA CMakelist file CMakeLists.txt
Error log:
19.45 [ 83%] Building CXX object tests/CMakeFiles/test_nativelib.dir/test_nativelib.cpp.o 19.67 [100%] Linking CXX executable test_nativelib 19.84 /usr/bin/ld: ../libnativelib.so: undefined reference to
google::protobuf::internal::ArenaStringPtr::Set(absl::lts_20230125::string_view, google::protobuf::Arena*)' 19.84 /usr/bin/ld: ../libnativelib.so: undefined reference to
google::protobuf::internal::VerifyUTF8(absl::lts_20230125::string_view, char const)' 19.84 /usr/bin/ld: ../libnativelib.so: undefined reference to `absl::lts_20230125::cord_internal::InitializeCordRepExternal(absl::lts_20230125::string_view, absl::lts_20230125::cord_internal::CordRepExternal)' 19.84 collect2: error: ld returned 1 exit status 19.84 gmake[2]: [tests/CMakeFiles/test_nativelib.dir/build.make:98: tests/test_nativelib] Error 1 19.84 gmake[1]: [CMakeFiles/Makefile2:126: tests/CMakeFiles/test_nativelib.dir/all] Error 2 19.84 gmake: *** [Makefile:91: all] Error 2
I have added the error logs as well
@jkhsjdhjs I'm on 3.27.1, and the issue is not fixed, upstream issue here: https://gitlab.kitware.com/cmake/cmake/-/issues/25079 If you passed
CMAKE_FIND_PACKAGE_PREFER_CONFIG
, CMake caches that, so you need to deleteCMakeCache.txt
before running CMake again to make it not use that option anymore.
Ah yes, sorry! The option was indeed cached.
@jkhsjdhjs @jonaski Please, have a look to the attached CMakeList file
@jonaski PFA CMakelist file CMakeLists.txt
Error log:
19.45 [ 83%] Building CXX object tests/CMakeFiles/test_nativelib.dir/test_nativelib.cpp.o 19.67 [100%] Linking CXX executable test_nativelib 19.84 /usr/bin/ld: ../libnativelib.so: undefined reference to
google::protobuf::internal::ArenaStringPtr::Set(absl::lts_20230125::string_view, google::protobuf::Arena*)' 19.84 /usr/bin/ld: ../libnativelib.so: undefined reference to
google::protobuf::internal::VerifyUTF8(absl::lts_20230125::string_view, char const)' 19.84 /usr/bin/ld: ../libnativelib.so: undefined reference to `absl::lts_20230125::cord_internal::InitializeCordRepExternal(absl::lts_20230125::string_view, absl::lts_20230125::cord_internal::CordRepExternal)' 19.84 collect2: error: ld returned 1 exit status 19.84 gmake[2]: [tests/CMakeFiles/test_nativelib.dir/build.make:98: tests/test_nativelib] Error 1 19.84 gmake[1]: [CMakeFiles/Makefile2:126: tests/CMakeFiles/test_nativelib.dir/all] Error 2 19.84 gmake: *** [Makefile:91: all] Error 2
@harsh-im
Your CMakeLists looks fine as far as I can tell, and I don't think those abseil related linking issues are related to this issue, there are no abseil log related errors from what you pasted. As far as I know ubuntu:latest is currently using Jammy (22.04), which is using an much older version of Protobuf (3.12.4), which is before Protobuf started using abseil log.
The linking issues you have might be an ubuntu bug, perhaps a mismatch between abseil libraries and protobuf libraries. Did you runapt update
and apt upgrade
and see if it helps?
@jonaski I have built grpc along with its third party dependencies referring :https://github.com/grpc/grpc/blob/master/BUILDING.md#building-with-cmake and I have copied the build in docker container and I am specifying grpc build path in -DCMAKE_PREFIX_PATH
You can pass
-DCMAKE_FIND_PACKAGE_PREFER_CONFIG
to cmake and it will use "Config" first.Otherwise use the following so it's compatible with older versions of Protobuf too.
find_package(Protobuf CONFIG) if(NOT Protobuf_FOUND) find_package(Protobuf REQUIRED) endif()
For the library use
protobuf::libprotobuf
, for the executable useprotobuf::protoc
. But I think variables for include and library dirs are not set.There was also a bug in protobuf-generate.cmake (#12450) Can be worked around it with:
if(NOT protobuf_PROTOC_EXE) set(protobuf_PROTOC_EXE "protobuf::protoc") endif()
Thanks, worked for me after I have combined solutions (version 23.4):
-Dprotobuf_BUILD_TESTS=OFF -DABSL_BUILD_TESTING=OFF -DABSL_USE_GOOGLETEST_HEAD=OFF -DABSL_PROPAGATE_CXX_STD=ON -DCMAKE_CXX_STANDARD=17
Full example:
$ git clone https://github.com/protocolbuffers/protobuf.git --branch v23.4 --single-branch protobuf-23.4
$ cd protobuf-23.4
$ git submodule update --init --recursive
$ cmake -Dprotobuf_BUILD_TESTS=OFF -DABSL_BUILD_TESTING=OFF -DABSL_USE_GOOGLETEST_HEAD=OFF -DABSL_PROPAGATE_CXX_STD=ON -DCMAKE_CXX_STANDARD=17 .
$ make
$ make install
Added following in CMakeLists.txt
find_package(Protobuf CONFIG)
if(NOT Protobuf_FOUND)
find_package(Protobuf REQUIRED)
endif()
Linked protobuf::libprotobuf
to library
You can pass
-DCMAKE_FIND_PACKAGE_PREFER_CONFIG
to cmake and it will use "Config" first. Otherwise use the following so it's compatible with older versions of Protobuf too.find_package(Protobuf CONFIG) if(NOT Protobuf_FOUND) find_package(Protobuf REQUIRED) endif()
For the library use
protobuf::libprotobuf
, for the executable useprotobuf::protoc
. But I think variables for include and library dirs are not set. There was also a bug in protobuf-generate.cmake (#12450) Can be worked around it with:if(NOT protobuf_PROTOC_EXE) set(protobuf_PROTOC_EXE "protobuf::protoc") endif()
Thanks, worked for me after I have combined solutions (version 23.4):
- Using following options in cmake
-Dprotobuf_BUILD_TESTS=OFF -DABSL_BUILD_TESTING=OFF -DABSL_USE_GOOGLETEST_HEAD=OFF -DABSL_PROPAGATE_CXX_STD=ON -DCMAKE_CXX_STANDARD=17
Full example:
$ git clone https://github.com/protocolbuffers/protobuf.git --branch v23.4 --single-branch protobuf-23.4 $ cd protobuf-23.4 $ git submodule update --init --recursive $ cmake -Dprotobuf_BUILD_TESTS=OFF -DABSL_BUILD_TESTING=OFF -DABSL_USE_GOOGLETEST_HEAD=OFF -DABSL_PROPAGATE_CXX_STD=ON -DCMAKE_CXX_STANDARD=17 . $ make $ make install
- Added following in CMakeLists.txt
find_package(Protobuf CONFIG) if(NOT Protobuf_FOUND) find_package(Protobuf REQUIRED) endif()
- Linked
protobuf::libprotobuf
to library
@onocpj Hey, I have tried following your mentioned steps but I am still getting the following errors
[ 83%] Linking CXX executable test_nativelib nativelib.so: undefined reference to `absl::lts_20230125::log_internal::LogMessage::CopyToEncodedBuffer(absl::lts_20230125::string_view, absl::lts_20230125::log_internal::LogMessage::StringType)'
nativelib.so: undefined reference to `google::protobuf::internal::ArenaStringPtr::Set(absl::lts_20230125::string_view, google::protobuf::Arena*)'
nativelib.so: undefined reference to `absl::lts_20230125::cord_internal::InitializeCordRepExternal(absl::lts_20230125::string_view, absl::lts_20230125::cord_internal::CordRepExternal*)'
hello, I'm following this
https://github.com/protocolbuffers/protobuf/blob/main/docs/cmake_protobuf_generate.md
target_link_libraries(proto-objects PUBLIC protobuf::libprotobuf)
ld: error: undefined symbol: absl::lts_20230125::log_internal::LogMessageFatal::LogMessageFatal(char const*, int, std::__ndk1::basic_string_view<char, std::__ndk1::char_traits<char> >)
>>> referenced by arena_align.h:180 (protobuf/src/google/protobuf/arena_align.h:180)
>>> CMakeFiles/dir/sample.pb.cc.o:(google::protobuf::internal::ArenaAlignAs(unsigned long))
>>> referenced by arena_align.h:181 (protobuf/src/google/protobuf/arena_align.h:181)
>>> CMakeFiles/dir/sample.pb.cc.o:(google::protobuf::internal::ArenaAlignAs(unsigned long))
am I missing something? If so, please update file at the link
I have same issue
Compiling with -labsl_log_internal_message -labsl_log_internal_check_op -std=c++17
resolved the issue for me.
Seems that this issue was caused by the fact that the relevant Protobuf_* variables are empty, even find_package return Protobuf_FOUND=true. related issue
Have struggled days to solve this issue and found 2 solutions.
set(protobuf_MODULE_COMPATIBLE true)
find_package(Protobuf CONFIG) find_package(Protobuf REQUIRED)
In my case, both work on linux and windows.
Sorry for stupid questions, but I am pretty new to protobuf and abseil. I am getting the same linker errors for my own project. I am using MSVC 17 2022 Windows 11 and I do not have cmakelists.txt file in my project. So, I am stuck here from last few weeks. Would be greatful if someone can help me in getting it fixed.
Error LNK2001 unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * __cdecl absl::log_internal::MakeCheckOpString<unsigned __int64,unsigned __int64>(unsigned __int64,unsigned __int64,char const *)" (??$MakeCheckOpString@_K_K@log_internal@absl@@YAPEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@_K0PEBD@Z)
Error LNK2001 unresolved external symbol "public: __cdecl absl::log_internal::LogMessageFatal::~LogMessageFatal(void)" (??1LogMessageFatal@log_internal@absl@@QEAA@XZ) ..ONNX\libprotobuf.lib(zero_copy_stream_impl.obj)
Error LNK2001 unresolved external symbol "public: __cdecl absl::log_internal::LogMessageFatal::LogMessageFatal(char const *,int,class absl::string_view)" (??0LogMessageFatal@log_internal@absl@@QEAA@PEBDHVstring_view@2@@Z) ..\ONNX\libprotobuf.lib(zero_copy_stream_impl_lite.obj)
I did not post alloff the errors but they are related to absl.
I believe the issue is that something like
find_package(protobuf REQUIRED)
uses the embeddedFindProtobuf
package from CMake:https://cmake.org/cmake/help/latest/module/FindProtobuf.html
This package has not been updated to know about the
Abseil
dependency. One needs to use:find_package(protobuf REQUIRED CONFIG)
This still doesn't do it for me. My cmake file is like this:
set(PROTOBUF ${THIRD_PARTY}/protobuf) # My personal protobuf dir
set(Protobuf_INCLUDE_DIRS ${PROTOBUF}/include)
set(absl_DIR ${PROTOBUF}/lib/cmake/absl)
set(utf8_range_DIR ${PROTOBUF}/lib/cmake/utf8_range)
find_package(protobuf CONFIG REQUIRED HINTS ${PROTOBUF})
Still get all the linker issues like:
Error LNK2001 unresolved external symbol "void __cdecl google::protobuf::internal::protobuf_assumption_failed(char const *,char const *,int)" (?protobuf_assumption_failed@internal@protobuf@google@@YAXPEBD0H@Z) io C:\dev\velta\solution\projects\io\context.obj 1
Error LNK2001 unresolved external symbol "public: class absl::lts_20230802::log_internal::LogMessage & __cdecl absl::lts_20230802::log_internal::LogMessage::operator<<<unsigned __int64,0>(unsigned __int64 const &)" (??$?6_K$0A@@LogMessage@log_internal@lts_20230802@absl@@QEAAAEAV0123@AEB_K@Z) io C:\dev\velta\solution\projects\io\io.pb.obj 1
Error LNK2001 unresolved external symbol "private: void __cdecl absl::lts_20230802::log_internal::LogMessage::CopyToEncodedBuffer<0>(class absl::lts_20230802::string_view)" (??$CopyToEncodedBuffer@$0A@@LogMessage@log_internal@lts_20230802@absl@@AEAAXVstring_view@23@@Z) io C:\dev\velta\solution\projects\io\inputs.pb.obj 1
Error LNK2001 unresolved external symbol "public: __cdecl absl::lts_20230802::log_internal::LogMessageFatal::LogMessageFatal(char const *,int,class absl::lts_20230802::string_view)" (??0LogMessageFatal@log_internal@lts_20230802@absl@@QEAA@PEBDHVstring_view@23@@Z) io C:\dev\velta\solution\projects\io\pricers.pb.obj 1
...
I had the same errors with integration gRPC (1.59.3) build on Windows, which depends on abseil and protobuf (4.24.3) as well.
finally solved with abseil specific flags:
cmake ../../PublicRepos/grpc/grpc -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="G:/Build/grpc/install" -DgRPC_SSL_PROVIDER=package -DOPENSSL_ROOT_DIR="C:/Program Files/OpenSSL" -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON -DABSL_PROPAGATE_CXX_STD=ON -Dprotobuf_ABSL_PROVIDER=package -DCMAKE_PREFIX_PATH="G:\PublicRepos\grpc\grpc\third_party\abseil-cpp\absl" -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_TESTS=OFF
I got the same error during building my code using protobuf 3.21.
The approach @pascaldekloe left in his comment above worked for me, where I use c++20.
In CMakeLists.txt,
find_package( absl REQUIRED )
find_package( Protobuf 3.21 REQUIRED )
# ...
target_link_libraries(
${Protobuf_LIBRARIES}
absl::log_internal_message
absl::log_internal_check_op
)
No cmake variable set
was required.
I'm compiling the code of a program I downloaded from GitHub that employs emscripten and protobuf v25.3 for Windows 11 using this command line:
emcc -O2 -I. -I./eigen/ -Ic:/projects/soft/protobuf/src -Ic:/projects/soft/abseil-cpp libabsl_base.a libabsl_log_severity.a libabsl_malloc_internal.a libabsl_raw_logging_internal.a libabsl_scoped_set_env.a libabsl_spinlock_wait.a libabsl_strerror.a libabsl_throw_delegate.a libabsl_die_if_null.a libabsl_log_entry.a libabsl_city.a libabsl_hash.a libabsl_log_globals.a libabsl_log_flags.a libabsl_log_initialize.a libabsl_log_internal_conditions.a libabsl_log_internal_fnmatch.a libabsl_log_internal_globals.a libabsl_log_internal_nullguard.a libabsl_log_internal_proto.a libabsl_log_sink.a libabsl_int128.a libabsl_time_zone.a libabsl_time.a libabsl_kernel_timeout_internal.a libabsl_graphcycles_internal.a libabsl_stacktrace.a libabsl_symbolize.a libabsl_synchronization.a libabsl_log_internal_log_sink_set.a libabsl_str_format_internal.a libabsl_strings_internal.a libabsl_strings.a libabsl_string_view.a libabsl_log_internal_format.a libabsl_examine_stack.a libabsl_log_internal_message.a libabsl_die_if_null.a libabsl_log_internal_check_op.a libabsl_vlog_config_internal.a libabsl_cord.a libabsl_crc_cord_state.a libabsl_cord_internal.a libabsl_crc32c.a libabsl_flags_commandlineflag.a libabsl_flags_config.a libabsl_flags_internal.a libabsl_flags_marshalling.a libabsl_flags_parse.a libabsl_flags_private_handle_accessor.a libabsl_flags_program_name.a libabsl_flags_reflection.a libabsl_flags_usage.a libabsl_flags_usage_internal.a libabsl_log_internal_check_op.a libabsl_log_internal_fnmatch.a libabsl_log_internal_format.a libabsl_log_internal_globals.a libabsl_log_internal_log_sink_set.a libabsl_log_internal_message.a libabsl_random_internal_distribution_test_util.a libabsl_status.a libabsl_statusor.a libabsl_cordz_handle.a libabsl_cordz_info.a libabsl_crc_internal.a libabsl_failure_signal_handler.a libabsl_hashtablez_sampler.a libabsl_random_internal_pool_urbg.a libabsl_bad_any_cast_impl.a libabsl_bad_optional_access.a libabsl_bad_variant_access.a libabsl_civil_time.a libabsl_cordz_functions.a libabsl_cordz_sample_token.a libabsl_crc_cpu_detect.a libabsl_debugging_internal.a libabsl_demangle_internal.a libabsl_exponential_biased.a libabsl_flags.a libabsl_flags_commandlineflag_internal.a libabsl_leak_check.a libabsl_low_level_hash.a libabsl_periodic_sampler.a libabsl_random_distributions.a libabsl_random_internal_platform.a libabsl_random_internal_randen.a libabsl_random_internal_randen_hwaes.a libabsl_random_internal_randen_hwaes_impl.a libabsl_random_internal_randen_slow.a libabsl_random_internal_seed_material.a libabsl_random_seed_gen_exception.a libabsl_random_seed_sequences.a libabsl_raw_hash_set.a libgmock.a libgmock_main.a libupb.a libprotobuf.a libprotoc.a crtbegin.o libal.a libbulkmemory.a libc++-noexcept.a libc++abi-noexcept.a libc.a libcompiler_rt.a libdlmalloc.a libfetch.a libGL-getprocaddr.a libhtml5.a libnoexit.a libSDL2.a libsockets.a libstubs-debug.a libstubs.a crn/crn.o -s USE_SDL=2 -Iinclude main.cpp -o main.html
I've worked on this for several hours. It turned out that the order of the '.a' files had a great impact on the error messages I received. Anyway, now most of the error messages I initially had are gone and the remaining ones are in the kind of:
wasm-ld: error: libprotobuf.a(descriptor.cc.o): undefined symbol: absl::lts_20230802::log_internal::LogMessageFatal::LogMessageFatal(char const*, int, absl::lts_20230802::string_view)
And that puzzles me because I've included all '.a' files from abseil and linked libprotobuf.a after them. So what's wrong? I suspect it's related to string_view but I might err.
After some consideration I think that maybe the wrong version of abseil is used because if I use a different version of libprotobuf.a, the error message also includes a different version date for abseil.
I also encountered this problem when using grpc, and I found a solution that worked for me on stackoverflow
Original text: After puzzling another I found the real problem: I had protoc and protobuf already installed in Linux before I compiled GRPC. In that case GRPC decides that PROTOBUF does not need to compile again. But the change is big that the program tries to link wrong versions of libGRPC and libprotobuf. Best is to uninstall all protobuf versions, then remove remainders of protoc, libproto* and then compile GRPC again.
Following its approach, I uninstalled all of my protobuf versions and then recompiled grpc once, under linux
What version of protobuf and what language are you using? Version: v22.2 Language: C++
What operating system (Linux, Windows, ...) and version? Windows 11 What runtime / compiler are you using (e.g., python version or gcc version) gcc12.2.0 (mingw) What did you do?
CMakeLists.txt
,test.proto
andmain.cpp
. They are located in same dir.What did you expect to see
My code is compiled with no error.
What did you see instead?
22 errors was reported:
It seems that many functions defined in
absl::lts_20230125
can not be found by the linker.Anything else we should know about your project / environment
Version of my cmake: 3.26.0-rc6
ABSL is not installed before I configure protobuf, so it must be installed together with protobuf.
The command used to clone protobuf repo:
The command used to configure protobuf: