添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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

What version of protobuf and what language are you using?
Version: protobuf-3.19.4
Language: C++ 14

What operating system (Linux, Windows, ...) and version?
Windows 10
What runtime / compiler are you using (e.g., python version or gcc version)
MSVC 19.29.30141.0
CMake 3.22.0 -- Configure BUILD_SHARED_LIBS

What did you do?
Steps to reproduce the behavior:

  • build Release x64 protobuf.sln using Visual Studio 2019
  • libprotobuf.dll
    libprotobuf.lib
    libprotoc.dll
    libprotoc.lib
    protoc.exe

  • Write my test.proto
  • syntax = "proto3";
    package test;
    message Person {
      optional string name = 1;
      optional int32 id = 2;
      optional string email = 3;
    
  • run .\protoc.exe --cpp_out=./ .\test.proto
  • test.pb.h
    test.pb.cc

  • Create Simple Hello_World ConsoleApplication using using Visual Studio 2019 Release x64
  • add src test.pb.h and test.pb.cc
    add link lirary libprotobuf.lib and libprotoc.lib
    add include dir google
    copy DLL libprotobuf.dll and libprotoc.dll
    #include "test.pb.h"

  • Build
  • What did you expect to see
    build suceess
    What did you see instead?

    Error LNK2001 unresolved external symbol "class google::protobuf::internal::ExplicitlyConstructed<class std::basic_string<char,struct std::char_traits,class std::allocator > > google::protobuf::internal::fixed_address_empty_string" (?fixed_address_empty_string@internal@protobuf@google@@3v?$ExplicitlyConstructed@V?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@@123@A)

    And once I opened "test.pb.h" in vs editor, hundreds of errors occured
    e.g some macro marked error
    PROTOBUF_NAMESPACE_OPEN
    Error (active) E0077 this declaration has no storage class or type specifier

    ::PROTOBUF_NAMESPACE_ID::
    Error (active) E0276 name followed by '::' must be a class or namespace name

    Furthermore, if import "google/protobuf/any.proto";

    Error LNK2001 unresolved external symbol "struct google::protobuf::AnyDefaultTypeInternal google::protobuf::Any_default_instance" (?Any_default_instance@protobuf@google@@3UAnyDefaultTypeInternal@12@A)

    How Can I correctly build? Thanks a lot!!!

    Failed to Build .pb.h and .pb.cc in Windows C++ Project Failed to Build Visual Stuido C++ Project with .pb.h and .pb.cc Mar 25, 2022

    changing the "C++ Language Standard" to "ISO C++ 17 Standard (/std:c++17)" resolved the header issues "Error (active) E0077".
    Other issues can be resolved using the solution mentioned above by @sigaaron.

    same problem,but my OS is Ubuntu 18.04
    And once I opened "test.pb.h" in vs code, hundreds of errors occured
    e.g some macro marked error
    PROTOBUF_NAMESPACE_OPEN
    Error (active) E0077 this declaration has no storage class or type specifier

    ::PROTOBUF_NAMESPACE_ID::
    Error (active) E0276 name followed by '::' must be a class or namespace name
    How Can I correctly build? Thanks a lot!!!!!!!!!!!!!!!!!!

  • I have same issue in vs2019 when i build grpc examples.
  • I try to enable grpc_MSVC_STATIC_RUNTIME ,protobuf_MSVC_STATIC_RUNTIME,Cares_MSVC_STATIC_RUNTIME in cmake configuration,then I try to generate a static lib by”.grpc.pb.cc“、”.grpc.pb.h“、”.pb.cc“、”.pb.h“rather than dynamic library.
  • although it still have errors such as E0077,but it build success 。
  • According to the header file "<google/protobuf/port_def.inc>",The definitions in this file are intended to be portable across Clang,GCC, and MSVC. Function-like macros are usable without an #ifdef guard. Syntax macros (for example, attributes) are always defined, although they may be empty.
  • maybe just the IntelliSense error?
  • changing the "C++ Language Standard" to "ISO C++ 17 Standard (/std:c++17)" resolved the header issues "Error (active) E0077". Other issues can be resolved using the solution mentioned above by @sigaaron.

    changing standard to c++17 successfully clears errors

    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.