protobuf
protobuf copied to clipboard
Protobuf24.4 linking ABSL errors : C++: Undefine reference to functions defined in absl::lts_20230802
What version of protobuf and what language are you using? Version: v24.4 Language: C++
What operating system (Linux, Windows, ...) and version? CentOS7.9
What runtime / compiler are you using (e.g., python version or gcc version) g++ (GCC) 10.2.1 20210130 (Red Hat 10.2.1-11)
What did you do? 1.Create a C++ basic project and write CMakelist.text 2.Use git -clone to obtain the source code of protobuf-24.4 I compiled the source code under window, generated protoc and wrote the .proto file, exported the corresponding .h .cc file, and copied the file to the CentOS7 C++ project. Then my operation under centos7: cd protobuf-24.4 cmake . -DCMAKE_CXX_STANDARD=14 -Dprotobuf_BUILD_TESTS=OFF .. cmake --build . make install DESTDIR=./output 3.Copy include lib64 in the generated (bin include lib64) to the corresponding directory of the C++ project where the library header file is placed and the library file is placed. 4.Introduce library files and library files into Cmakelist.txt in the C++ project target_include_directories(GlobalServer PRIVATE ${PROJECT_SOURCE_DIR}/baseEngine/thirdlyLib/protobuf.24.4/include) target_link_directories(GlobalServer PRIVATE ${PROJECT_SOURCE_DIR}/wkBinaryDeploy/DynLibrary) target_link_libraries(GlobalServer absl_bad_any_cast_impl) ...... ( According to the original idea, I didn’t want to manually add the ABSL library. There were too many, but to be safe, I could only add it manually. ) target_link_libraries(GlobalServer protobuf) 5.When compiling my C++ project, an error will appear when linking.
What did you expect to see
My code is compiled with no error.
What did you see instead?
[ 33%] Building CXX object CMakeFiles/GlobalServer.dir/CNServerMain.cpp.o
[ 66%] Building CXX object CMakeFiles/GlobalServer.dir/comProtocol/ComGameInfos.pb.cc.o
[100%] Linking CXX executable /home/lztResearchIn/PrMingzhongZhu/LServCluster_v.0.0.1/adGlobalServer/wkBinaryDeploy/ExecObjects/GlobalServer
/opt/rh/devtoolset-10/root/usr/libexec/gcc/x86_64-redhat-linux/10/ld: /home/lztResearchIn/PrMingzhongZhu/LServCluster_v.0.0.1/adGlobalServer/wkBinaryDeploy/DynLibrary/libabsl_log_internal_message.a(log_message.cc.o): in function absl::lts_20230802::log_internal::LogMessage::LogMessageData::LogMessageData(char const*, int, absl::lts_20230802::LogSeverity, absl::lts_20230802::Time)': log_message.cc:(.text+0x2d3): undefined reference to absl::lts_20230802::ShouldPrependLogPrefix()'
/opt/rh/devtoolset-10/root/usr/libexec/gcc/x86_64-redhat-linux/10/ld: log_message.cc:(.text+0x30d): undefined reference to absl::lts_20230802::base_internal::GetCachedTID()' /opt/rh/devtoolset-10/root/usr/libexec/gcc/x86_64-redhat-linux/10/ld: /home/lztResearchIn/PrMingzhongZhu/LServCluster_v.0.0.1/adGlobalServer/wkBinaryDeploy/DynLibrary/libabsl_log_internal_message.a(log_message.cc.o): in function absl::lts_20230802::log_internal::LogMessage::LogMessageData::FinalizeEncodingAndFormat()':
log_message.cc:(.text+0x42f): undefined reference to absl::lts_20230802::log_internal::ThreadIsLoggingToLogSink()' /opt/rh/devtoolset-10/root/usr/libexec/gcc/x86_64-redhat-linux/10/ld: log_message.cc:(.text+0x4d1): undefined reference to absl::lts_20230802::log_internal::FormatLogPrefix(absl::lts_20230802::LogSeverity, absl::lts_20230802::Time, int, absl::lts_20230802::string_view, int, absl::lts_20230802::log_internal::PrefixFormat, absl::lts_20230802::Spanabsl::lts_20230802::log_internal::LogMessage::FailWithoutStackTrace()': log_message.cc:(.text+0xdfe): undefined reference to absl::lts_20230802::log_internal::SetSuppressSigabortTrace(bool)'
/opt/rh/devtoolset-10/root/usr/libexec/gcc/x86_64-redhat-linux/10/ld: /home/lztResearchIn/PrMingzhongZhu/LServCluster_v.0.0.1/adGlobalServer/wkBinaryDeploy/DynLibrary/libabsl_log_internal_message.a(log_message.cc.o): in function absl::lts_20230802::log_internal::LogMessage::Flush()': log_message.cc:(.text+0x101a): undefined reference to absl::lts_20230802::MinLogLevel()'
/opt/rh/devtoolset-10/root/usr/libexec/gcc/x86_64-redhat-linux/10/ld: log_message.cc:(.text+0x1109): undefined reference to absl::lts_20230802::log_internal::ExitOnDFatal()' /opt/rh/devtoolset-10/root/usr/libexec/gcc/x86_64-redhat-linux/10/ld: /home/lztResearchIn/PrMingzhongZhu/LServCluster_v.0.0.1/adGlobalServer/wkBinaryDeploy/DynLibrary/libabsl_log_internal_message.a(log_message.cc.o): in function absl::lts_20230802::log_internal::LogMessage::IsFatal() const':
log_message.cc:(.text+0x15c2): undefined reference to absl::lts_20230802::log_internal::ExitOnDFatal()' /opt/rh/devtoolset-10/root/usr/libexec/gcc/x86_64-redhat-linux/10/ld: /home/lztResearchIn/PrMingzhongZhu/LServCluster_v.0.0.1/adGlobalServer/wkBinaryDeploy/DynLibrary/libabsl_log_internal_message.a(log_message.cc.o): in function absl::lts_20230802::log_internal::LogMessage::PrepareToDie()':
log_message.cc:(.text+0x169f): undefined reference to absl::lts_20230802::log_internal::LogToSinks(absl::lts_20230802::LogEntry const&, absl::lts_20230802::Span<absl::lts_20230802::LogSink*>, bool)' /opt/rh/devtoolset-10/root/usr/libexec/gcc/x86_64-redhat-linux/10/ld: log_message.cc:(.text+0x16d9): undefined reference to absl::lts_20230802::log_internal::ShouldSymbolizeLogStackTrace()'
/opt/rh/devtoolset-10/root/usr/libexec/gcc/x86_64-redhat-linux/10/ld: log_message.cc:(.text+0x16e1): undefined reference to absl::lts_20230802::log_internal::MaxFramesInLogStackTrace()' /opt/rh/devtoolset-10/root/usr/libexec/gcc/x86_64-redhat-linux/10/ld: log_message.cc:(.text+0x16f7): undefined reference to absl::lts_20230802::debugging_internal::DumpStackTrace(int, int, bool, void ()(char const, void*), void*)'
/opt/rh/devtoolset-10/root/usr/libexec/gcc/x86_64-redhat-linux/10/ld: /home/lztResearchIn/PrMingzhongZhu/LServCluster_v.0.0.1/adGlobalServer/wkBinaryDeploy/DynLibrary/libabsl_log_internal_message.a(log_message.cc.o): in function absl::lts_20230802::log_internal::LogMessage::SendToLog()': log_message.cc:(.text+0x17d0): undefined reference to absl::lts_20230802::log_internal::LogToSinks(absl::lts_20230802::LogEntry const&, absl::lts_20230802::Spanabsl::lts_20230802::LogSink*, bool)'
/opt/rh/devtoolset-10/root/usr/libexec/gcc/x86_64-redhat-linux/10/ld: /home/lztResearchIn/PrMingzhongZhu/LServCluster_v.0.0.1/adGlobalServer/wkBinaryDeploy/DynLibrary/libabsl_log_internal_message.a(log_message.cc.o): in function absl::lts_20230802::log_internal::LogMessage::LogBacktraceIfNeeded()': log_message.cc:(.text+0x1812): undefined reference to absl::lts_20230802::log_internal::IsInitialized()'
Anything else we should know about your project / environment Version of my cmake: cmake version 3.26.6 My operating environment is relatively new. My G++ Cmake has also been upgraded to the version required by the source code. The protobuf source code is also obtained directly from git. Everything is operated through the normal installation process, but I feel that the symbols of the ABSL library are not transferred to the Protobuf library. I hope that when protobuf.a is compiled, I can only connect it to a library instead of also connecting the ABSL library. That would be too painful! Now in version 24.4, is there still such a problem?
One more thing: After reading several related posts, I made the following changes to the CMakelist.txt of the C++ program: …… set(absl_DIR ${PROJECT_SOURCE_DIR}/wkBinaryDeploy/DynLibrary/lib64/cmake/absl) set(utf8_range_DIR ${PROJECT_SOURCE_DIR}/wkBinaryDeploy/DynLibrary/lib64/cmake/utf8_range) set(protobuf_DIR ${PROJECT_SOURCE_DIR}/wkBinaryDeploy/DynLibrary/lib64/cmake/protobuf)
find_package(absl CONFIG REQUIRED) find_package(utf8_range CONFIG REQUIRED) find_package(protobuf CONFIG REQUIRED)
target_include_directories(GlobalServer PRIVATE ${PROJECT_SOURCE_DIR}/baseEngine/thirdlyLib/protobuf.24.4/include) target_link_directories(GlobalServer PRIVATE ${PROJECT_SOURCE_DIR}/wkBinaryDeploy/DynLibrary) target_link_libraries(GlobalServer absl_bad_any_cast_impl) ...(all ABSL libraries) target_link_libraries(GlobalServer protobuf)
I used find_package(xxx CONFIG REQUIRED) and it was successful. I still got an error after recompiling and connecting. Several libraries related to ABSL could not be found.
I am experiencing the same problem, and i still haven't found a solution.
I have been experiencing the same problem since 24. #15050
I am now on 27 which is the latest.
This is what I have found so far: Using a static library you get the output as described above. Try making a release build and see if the behaviour is different.
I then built a shared library using 27
cmake . -Dprotobuf_BUILD_SHARED_LIBS=ON -DCMAKE_CXX_STANDARD=20
If you build using the shared object library most of the absl linker errors disappear
If I set the build type to Debug I get 1 linker error which I have no idea how to even begin to solve. Bear in mind that I am only compiling the protoc generated files and not yet using them so I expect that once I start populating them I will get more errors.
undefined reference to symbol '_ZN4absl12lts_2024011612log_internal21CheckOpMessageBuilder7ForVar2Ev'
[build] /usr/bin/ld: /usr/local/lib/libabsl_log_internal_check_op.so.2401.0.0: error adding symbols: DSO missing from command line
[build] collect2: error: ld returned 1 exit status
If I set the build type to Release then the Protoc generated files build fine but I get a similar linker error when using the
google::protobuf::util::JsonStringToMessage(j); function so I imagine I will get many more going forward.
undefined reference to symbol '_ZNK4absl12lts_2024011615status_internal9StatusRep5UnrefEv'
[build] /usr/bin/ld: /usr/local/lib/libabsl_status.so.2401.0.0: error adding symbols: DSO missing from command line
[build] collect2: error: ld returned 1 exit status
I would prefer to build using the static library for many reasons, but I get the same results.
Hello again. I tried a few of the latest versions, but the link issues with absl persist. According to the example in the link below, I tried version v3.14.0, one of the older versions, and it's working smoothly now. I will continue working with this version for now. If this issue gets resolved, I will switch to the new versions.
https://www.youtube.com/watch?v=gIOEGnra180&t=1013s
Hi, I've been struggling on this issue for a few hours, and since Google led me here, here's a potential workaround.
So, I updated from 3.22.11 to 4.25.2 and now my shiny CMake project broke, and I fixed it by explicitely looking and linking to absl.
add_library (my-stuff
path/to/generated/foo.pb.cc
path/to/generated/bar.pb.cc
)
find_package (protobuf REQUIRED)
target_link_libraries (my-stuff
PUBLIC
protobuf::libprotobuf
)
if (Protobuf_VERSION VERSION_GREATER_EQUAL 4)
find (absl REQUIRED)
target_link_libraries (my-stuff
PUBLIC
absl::log_internal_check_op
)
endif ()
Of course, this is hackish: explictely linking against some absl::*_internal_* is probably wrong, but this fix the link issue.
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 inactive because the last activity was over 90 days ago.
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 inactive label was added.
I have the same problem:
/usr/local/lib64/libprotobuf.so: undefined reference to symbol '_ZN4absl12lts_2024011612log_internal21CheckOpMessageBuilder7ForVar2Ev' /usr/bin/ld: /usr/local/lib64/libabsl_log_internal_check_op.so.2401.0.0: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status
Adding -labsl_log_internal_check_op -labsl_log_internal_message -labsl_raw_logging_internal -labsl_spinlock_wait after -lprotobuf solved the problem for me. Please reference this url
I had the same problem @smod
I had the same problem