Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

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

Failed to Build Visual Stuido C++ Project with .pb.h and .pb.cc #9676

Closed
CodeFish711 opened this issue Mar 25, 2022 · 12 comments
Closed

Failed to Build Visual Stuido C++ Project with .pb.h and .pb.cc #9676

CodeFish711 opened this issue Mar 25, 2022 · 12 comments
Assignees
Labels
c++ inactive Denotes the issue/PR has not seen activity in the last 90 days. platform related Any issue releated to specific platform or OS windows

Comments

@CodeFish711
Copy link

CodeFish711 commented Mar 25, 2022

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:

  1. build Release x64 protobuf.sln using Visual Studio 2019

libprotobuf.dll
libprotobuf.lib
libprotoc.dll
libprotoc.lib
protoc.exe

  1. Write my test.proto
syntax = "proto3";

package test;

message Person {
  optional string name = 1;
  optional int32 id = 2;
  optional string email = 3;
}

  1. run .\protoc.exe --cpp_out=./ .\test.proto

test.pb.h
test.pb.cc

  1. 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"

  1. 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!!!

@CodeFish711 CodeFish711 changed the title 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
@elharo elharo added platform related Any issue releated to specific platform or OS c++ windows labels Mar 25, 2022
@ralucado
Copy link

Having the same issue, our project builds fine on Linux but it is getting a lot of errors from the protobuf macros on Visual Studio 2019

@znbitxx
Copy link

znbitxx commented Jun 8, 2022

build protobuf x64 with vs /MDd will get rid of this trouble

@vasdev8
Copy link

vasdev8 commented Jun 21, 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.

@harryqk
Copy link

harryqk commented Jul 5, 2022

same problem, but can build, run without error

@KuiLeiZS
Copy link

KuiLeiZS commented Sep 6, 2022

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!!!!!!!!!!!!!!!!!!

@nbreen
Copy link

nbreen commented Sep 10, 2022

I am having the same issue. Compiling with Visual Studio 2022. I've tried the suggestions by @vasdev8 and @sigaaron with no luck

@imadourabi
Copy link

Same issue here in VS 2022.
However, when I open the project as a folder (not as solution), it seems likely to work, although, this is not the desired solution for this issue.

@HMS-Yukikaze
Copy link

  1. I have same issue in vs2019 when i build grpc examples.
  2. 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.
  3. although it still have errors such as E0077,but it build success 。
  4. 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.
  5. maybe just the IntelliSense error?

@onlyou2030
Copy link

Same issue in VS2022.

@historyliao
Copy link

historyliao commented Aug 8, 2023

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
image

Copy link

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.

@github-actions github-actions bot added the inactive Denotes the issue/PR has not seen activity in the last 90 days. label Jan 23, 2024
Copy link

github-actions bot commented Feb 7, 2024

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.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ inactive Denotes the issue/PR has not seen activity in the last 90 days. platform related Any issue releated to specific platform or OS windows
Projects
None yet
Development

No branches or pull requests