Skip to content

[Regression] Link /MD static lib failed #25036

@noonchen

Description

@noonchen

What version of protobuf and what language are you using?
Version: v33.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)
VS 2022

What did you do?
Steps to reproduce the behavior:

  1. git clone --depth 1 -b v33.2 --recurse-submodules https://github.com/protocolbuffers/protobuf.git
  2. Build /MD static lib.
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17 -Dprotobuf_ABSL_PROVIDER=module -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -Dprotobuf_BUILD_TESTS=OFF -DABSL_PROPAGATE_CXX_STD=ON
cmake --build build --parallel 10 --config Release
cmake --install build --prefix ./install
  1. Serialize a message in c++.
message RetStatus {
    bool success	= 1;
    string message	= 2;
}
auto ret = imgpb::RetStatus();
ret.set_success(s.success);
ret.set_message(s.msg);

std::string retmsg;
ret.SerializeToString(&retmsg);
  1. find protobuf in cmake.
find_package(Protobuf CONFIG REQUIRED)
...
add_library(XXX SHARED ${SOURCE})
target_link_libraries(XXX PRIVATE protobuf::libprotoc)

What did you expect to see

No error

What did you see instead?

Link error.

image_fault_inj_server.obj : error LNK2019: unresolved external symbol "public: void __cdecl google::protobuf::internal::ArenaStringPtr::Set(class absl::lts_20250512::string_view,class google::protobuf::Arena *)" (?Set@ArenaStringPtr@internal@protobuf@google@@QEAAXVstring_ view@lts_20250512@absl@@PEAVArena@34@@Z) referenced in function "public: void __cdecl imagefaultinj::RetStatus::set_message<char const (&)[43]>(char const (&)[43])" (??$set_message@AEAY0CL@$$CBD$$V@RetStatus@imagefaultinj@@QEAAXAEAY0CL@$$CBD@Z)
imagefaultinj.pb.obj : error LNK2019: unresolved external symbol "private: void __cdecl absl::lts_20250512::log_internal::LogMessage::CopyToEncodedBuffer<0>(class absl::lts_20250512::string_view)" (??$CopyToEncodedBuffer@$0A@@LogMessage@log_internal@lts_20250512@absl@@AEAA XVstring_view@23@@Z) referenced in function "public: class absl::lts_20250512::log_internal::LogMessage & __cdecl absl::lts_20250512::log_internal::LogMessage::operator<<<2>(char const (&)[2])" (??$?6$01@LogMessage@log_internal@lts_20250512@absl@@QEAAAEAV0123@AEAY01$$CBD@Z )
imagefaultinj.pb.obj : error LNK2019: unresolved external symbol "private: unsigned char * __cdecl google::protobuf::io::EpsCopyOutputStream::WriteStringMaybeAliasedOutline(unsigned int,class absl::lts_20250512::string_view,unsigned char *)" (?WriteStringMaybeAliasedOutlin e@EpsCopyOutputStream@io@protobuf@google@@AEAAPEAEIVstring_view@lts_20250512@absl@@PEAE@Z) referenced in function "public: unsigned char * __cdecl google::protobuf::io::EpsCopyOutputStream::WriteStringMaybeAliased(unsigned int,class absl::lts_20250512::string_view,unsigned char *)" (?WriteStringMaybeAliased@EpsCopyOutputStream@io@protobuf@google@@QEAAPEAEIVstring_view@lts_20250512@absl@@PEAE@Z)
imagefaultinj.pb.obj : error LNK2019: unresolved external symbol "public: static bool __cdecl google::protobuf::internal::WireFormatLite::VerifyUtf8String(char const *,int,enum google::protobuf::internal::WireFormatLite::Operation,class absl::lts_20250512::string_view)" (? VerifyUtf8String@WireFormatLite@internal@protobuf@google@@SA_NPEBDHW4Operation@1234@Vstring_view@lts_20250512@absl@@@Z) referenced in function "public: virtual unsigned char * __cdecl imagefaultinj::RetStatus::_InternalSerialize(unsigned char *,class google::protobuf::io:: EpsCopyOutputStream *)const " (?_InternalSerialize@RetStatus@imagefaultinj@@UEBAPEAEPEAEPEAVEpsCopyOutputStream@io@protobuf@google@@@Z)

Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).

Anything else we should know about your project / environment

When I pull an old version of protobuf, perform the exact same steps above, no issue at all, such as:

git clone --depth 1 -b v3.29.5 --recurse-submodules https://github.com/protocolbuffers/protobuf.git

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions