-
Notifications
You must be signed in to change notification settings - Fork 16.1k
C++: Undefine reference to functions defined in absl::lts_20230125 #12292
Copy link
Copy link
Closed
Labels
Description
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?
- Build and install protobuf from source code, and install it into the prefix of gcc.
- Write the following cmake project containing 3 files:
CMakeLists.txt,test.protoandmain.cpp. They are located in same dir.
#CMakeLists.txt
find_package(protobuf REQUIRED)
protobuf_generate_cpp(pb_src pb_hdr test.proto)
add_library(test_pb_lib ${pb_hdr} ${pb_src})
target_include_directories(test_pb_lib INTERFACE ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(test_pb_lib PUBLIC protobuf::libprotobuf)
add_executable(test_pb main.cpp)
target_link_libraries(test_pb PRIVATE test_pb_lib)// test.proto
syntax = "proto3";
message test {
int32 msg = 1;
}// main.cpp
#include <iostream>
#include <test.pb.h>
int main(int, char **) {
::test test_msg;
std::cout << "Hello, world!\n";
}- Configure my cmake project
cmake.EXE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/g++.exe -SD:/Git/learnProtobuf -Bd:/Git/build-learnProtobuf-win -G Ninja- Build the project
cmake --build .What did you expect to see
My code is compiled with no error.
What did you see instead?
22 errors was reported:
[main] Building folder: learnProtobuf
[build] Starting build
[proc] Executing command: D:\ProgramFiles\CMake\bin\cmake.EXE --build d:/Git/build-learnProtobuf-win --config Debug --target all --parallel --
[build] [1/1 100% :: 0.167] Linking CXX executable test_pb.exe
[build] FAILED: test_pb.exe
[build] cmd.exe /C "cd . && D:\ProgramFilesU\gcc-compilers\mingw-gcc12\bin\g++.exe -g CMakeFiles/test_pb.dir/main.obj -o test_pb.exe -Wl,--out-implib,libtest_pb.dll.a -Wl,--major-image-version,0,--minor-image-version,0 libtest_pb_lib.a D:/ProgramFilesU/gcc-compilers/mingw-gcc12/lib/libprotobuf.dll.a -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libtest_pb_lib.a(test.pb.obj): in function `test::MergeImpl(google::protobuf::Message&, google::protobuf::Message const&)':
[build] D:/Git/build-learnProtobuf-win/test.pb.cc:243: undefined reference to `absl::lts_20230125::log_internal::LogMessageFatal::LogMessageFatal(char const*, int, std::basic_string_view<char, std::char_traits<char> >)'
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Git/build-learnProtobuf-win/test.pb.cc:243: undefined reference to `absl::lts_20230125::log_internal::LogMessageFatal::~LogMessageFatal()'
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libtest_pb_lib.a(test.pb.obj): in function `absl::lts_20230125::log_internal::LogMessage::operator<<(unsigned long long)':
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/include/absl/log/internal/log_message.h:123: undefined reference to `absl::lts_20230125::log_internal::LogMessage& absl::lts_20230125::log_internal::LogMessage::operator<< <unsigned long long, 0>(unsigned long long const&)'
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libtest_pb_lib.a(test.pb.obj): in function `google::protobuf::internal::ArenaAlignAs(unsigned long long)':
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/include/google/protobuf/arena_align.h:178: undefined reference to `absl::lts_20230125::log_internal::LogMessageFatal::LogMessageFatal(char const*, int, std::basic_string_view<char, std::char_traits<char> >)'
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/ProgramFilesU/gcc-compilers/mingw-gcc12/include/google/protobuf/arena_align.h:178: undefined reference to `absl::lts_20230125::log_internal::LogMessageFatal::~LogMessageFatal()'
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/ProgramFilesU/gcc-compilers/mingw-gcc12/include/google/protobuf/arena_align.h:179: undefined reference to `absl::lts_20230125::log_internal::LogMessageFatal::LogMessageFatal(char const*, int, std::basic_string_view<char, std::char_traits<char> >)'
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/ProgramFilesU/gcc-compilers/mingw-gcc12/include/google/protobuf/arena_align.h:179: undefined reference to `absl::lts_20230125::log_internal::LogMessageFatal::~LogMessageFatal()'
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/ProgramFilesU/gcc-compilers/mingw-gcc12/include/google/protobuf/arena_align.h:179: undefined reference to `absl::lts_20230125::log_internal::LogMessageFatal::~LogMessageFatal()'
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libtest_pb_lib.a(test.pb.obj): in function `google::protobuf::internal::EpsCopyInputStream::DoneWithCheck(char const**, int)':
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/include/google/protobuf/parse_context.h:241: undefined reference to `absl::lts_20230125::log_internal::LogMessageFatal::LogMessageFatal(char const*, int, std::basic_string_view<char, std::char_traits<char> >)'
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/ProgramFilesU/gcc-compilers/mingw-gcc12/include/google/protobuf/parse_context.h:241: undefined reference to `absl::lts_20230125::log_internal::LogMessageFatal::~LogMessageFatal()'
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/ProgramFilesU/gcc-compilers/mingw-gcc12/include/google/protobuf/parse_context.h:244: undefined reference to `absl::lts_20230125::log_internal::LogMessageFatal::LogMessageFatal(char const*, int, std::basic_string_view<char, std::char_traits<char> >)'
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/ProgramFilesU/gcc-compilers/mingw-gcc12/include/google/protobuf/parse_context.h:244: undefined reference to `absl::lts_20230125::log_internal::LogMessageFatal::~LogMessageFatal()'
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/ProgramFilesU/gcc-compilers/mingw-gcc12/include/google/protobuf/parse_context.h:241: undefined reference to `absl::lts_20230125::log_internal::LogMessageFatal::~LogMessageFatal()'
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libtest_pb_lib.a(test.pb.obj): in function `test::SharedDtor()':
[build] D:/Git/build-learnProtobuf-win/test.pb.cc:139: undefined reference to `absl::lts_20230125::log_internal::LogMessageFatal::LogMessageFatal(char const*, int, std::basic_string_view<char, std::char_traits<char> >)'
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Git/build-learnProtobuf-win/test.pb.cc:139: undefined reference to `absl::lts_20230125::log_internal::LogMessageFatal::~LogMessageFatal()'
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Git/build-learnProtobuf-win/test.pb.cc:139: undefined reference to `absl::lts_20230125::log_internal::LogMessageFatal::~LogMessageFatal()'
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libtest_pb_lib.a(test.pb.obj): in function `absl::lts_20230125::log_internal::LogMessage& absl::lts_20230125::log_internal::LogMessage::operator<< <19>(char const (&) [19])':
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/include/absl/log/internal/log_message.h:295: undefined reference to `absl::lts_20230125::log_internal::LogMessage::CopyToEncodedBuffer(std::basic_string_view<char, std::char_traits<char> >, absl::lts_20230125::log_internal::LogMessage::StringType)'
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libtest_pb_lib.a(test.pb.obj): in function `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* absl::lts_20230125::log_internal::Check_LEImpl<int, google::protobuf::internal::EpsCopyInputStream::{unnamed type#2}>(int const&, google::protobuf::internal::EpsCopyInputStream::{unnamed type#2} const&, char const*)':
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/include/absl/log/internal/check_op.h:338: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* absl::lts_20230125::log_internal::MakeCheckOpString<long long, long long>(long long, long long, char const*)'
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libtest_pb_lib.a(test.pb.obj): in function `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* absl::lts_20230125::log_internal::Check_NEImpl<test const*, test*>(test const* const&, test* const&, char const*)':
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/include/absl/log/internal/check_op.h:337: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* absl::lts_20230125::log_internal::MakeCheckOpString<void const*, void const*>(void const*, void const*, char const*)'
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libtest_pb_lib.a(test.pb.obj): in function `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* absl::lts_20230125::log_internal::MakeCheckOpString<unsigned long long, long long>(unsigned long long, long long, char const*)':
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/include/absl/log/internal/check_op.h:292: undefined reference to `absl::lts_20230125::log_internal::CheckOpMessageBuilder::CheckOpMessageBuilder(char const*)'
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/ProgramFilesU/gcc-compilers/mingw-gcc12/include/absl/log/internal/check_op.h:294: undefined reference to `absl::lts_20230125::log_internal::CheckOpMessageBuilder::ForVar2()'
[build] D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/ProgramFilesU/gcc-compilers/mingw-gcc12/include/absl/log/internal/check_op.h:295: undefined reference to `absl::lts_20230125::log_internal::CheckOpMessageBuilder::NewString[abi:cxx11]()'
[build] collect2.exe: error: ld returned 1 exit status
[build] ninja: build stopped: subcommand failed.
[proc] The command: D:\ProgramFiles\CMake\bin\cmake.EXE --build d:/Git/build-learnProtobuf-win --config Debug --target all --parallel -- exited with code: 1
[build] Build finished with exit code 1
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:
git clone --recursive https://github.com/protocolbuffers/protobuf.gitThe command used to configure protobuf:
cmake -S . -B ../build -G Ninja -DCMAKE_CXX_COMPILER:FILEPATH=D:\ProgramFilesU\gcc-compilers\mingw-gcc12\bin\g++.exe -DCMAKE_C_COMPILER:FILEPATH=D:\ProgramFilesU\gcc-compilers\mingw-gcc12\bin\gcc.exe -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=D:\ProgramFilesU\gcc-compilers\mingw-gcc12\bin
Reactions are currently unavailable