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.