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

Can not use grpc in an export class (my grpc service) #15653

Closed
liukaifei opened this issue Jun 6, 2018 · 5 comments
Closed

Can not use grpc in an export class (my grpc service) #15653

liukaifei opened this issue Jun 6, 2018 · 5 comments

Comments

@liukaifei
Copy link

liukaifei commented Jun 6, 2018

# Should this be an issue in the gRPC issue tracker?
Yes

# What version of gRPC and what language are you using?
1.12.x C++

# What operating system (Linux, Windows, …) and version?
Windows 10

# What runtime / compiler are you using (e.g. python version or version of gcc)
MSVC2017

# What did you do?
I am trying to build my grpc service in dll

# What did you expect to see?
I want to be ok

# What did you see instead?

## 1. use __declspec(dllexport) : error C2280
image

c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.14.26428\include\xutility(2443): error C2280: 'std::unique_ptr<grpc::internal::RpcServiceMethod,std::default_delete<_Ty>> &std::unique_ptr<_Ty,std::default_delete<_Ty>>::operator =(const std::unique_ptr<_Ty,std::default_delete<_Ty>> &)': attempting to reference a deleted function
1>        with
1>        [
1>            _Ty=grpc::internal::RpcServiceMethod
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.14.26428\include\memory(2309): note: see declaration of 'std::unique_ptr<grpc::internal::RpcServiceMethod,std::default_delete<_Ty>>::operator ='
1>        with
1>        [
1>            _Ty=grpc::internal::RpcServiceMethod
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.14.26428\include\xutility(2462): note: see reference to function template instantiation '_OutIt std::_Copy_unchecked1<_InIt,_OutIt>(_InIt,_InIt,_OutIt,std::_General_ptr_iterator_tag)' being compiled
1>        with
1>        [
1>            _OutIt=std::unique_ptr<grpc::internal::RpcServiceMethod,std::default_delete<grpc::internal::RpcServiceMethod>> *,
1>            _InIt=std::unique_ptr<grpc::internal::RpcServiceMethod,std::default_delete<grpc::internal::RpcServiceMethod>> *
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.14.26428\include\vector(1430): note: see reference to function template instantiation '_OutIt *std::_Copy_unchecked<_Iter,std::unique_ptr<grpc::internal::RpcServiceMethod,std::default_delete<_Ty>>*>(_InIt,_InIt,_OutIt)' being compiled
1>        with
1>        [
1>            _OutIt=std::unique_ptr<grpc::internal::RpcServiceMethod,std::default_delete<grpc::internal::RpcServiceMethod>> *,
1>            _Iter=std::unique_ptr<grpc::internal::RpcServiceMethod,std::default_delete<grpc::internal::RpcServiceMethod>> *,
1>            _Ty=grpc::internal::RpcServiceMethod,
1>            _InIt=std::unique_ptr<grpc::internal::RpcServiceMethod,std::default_delete<grpc::internal::RpcServiceMethod>> *
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.14.26428\include\vector(1448): note: see reference to function template instantiation 'void std::vector<std::unique_ptr<grpc::internal::RpcServiceMethod,std::default_delete<_Ty>>,std::allocator<std::unique_ptr<_Ty,std::default_delete<_Ty>>>>::_Assign_range<_Iter>(_Iter,_Iter,std::forward_iterator_tag)' being compiled
1>        with
1>        [
1>            _Ty=grpc::internal::RpcServiceMethod,
1>            _Iter=std::unique_ptr<grpc::internal::RpcServiceMethod,std::default_delete<grpc::internal::RpcServiceMethod>> *
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.14.26428\include\vector(1448): note: see reference to function template instantiation 'void std::vector<std::unique_ptr<grpc::internal::RpcServiceMethod,std::default_delete<_Ty>>,std::allocator<std::unique_ptr<_Ty,std::default_delete<_Ty>>>>::_Assign_range<_Iter>(_Iter,_Iter,std::forward_iterator_tag)' being compiled
1>        with
1>        [
1>            _Ty=grpc::internal::RpcServiceMethod,
1>            _Iter=std::unique_ptr<grpc::internal::RpcServiceMethod,std::default_delete<grpc::internal::RpcServiceMethod>> *
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.14.26428\include\vector(1471): note: see reference to function template instantiation 'void std::vector<std::unique_ptr<grpc::internal::RpcServiceMethod,std::default_delete<_Ty>>,std::allocator<std::unique_ptr<_Ty,std::default_delete<_Ty>>>>::assign<std::unique_ptr<_Ty,std::default_delete<_Ty>>*,void>(_Iter,_Iter)' being compiled
1>        with
1>        [
1>            _Ty=grpc::internal::RpcServiceMethod,
1>            _Iter=std::unique_ptr<grpc::internal::RpcServiceMethod,std::default_delete<grpc::internal::RpcServiceMethod>> *
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.14.26428\include\vector(1471): note: see reference to function template instantiation 'void std::vector<std::unique_ptr<grpc::internal::RpcServiceMethod,std::default_delete<_Ty>>,std::allocator<std::unique_ptr<_Ty,std::default_delete<_Ty>>>>::assign<std::unique_ptr<_Ty,std::default_delete<_Ty>>*,void>(_Iter,_Iter)' being compiled
1>        with
1>        [
1>            _Ty=grpc::internal::RpcServiceMethod,
1>            _Iter=std::unique_ptr<grpc::internal::RpcServiceMethod,std::default_delete<grpc::internal::RpcServiceMethod>> *
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.14.26428\include\vector(1457): note: while compiling class template member function 'std::vector<std::unique_ptr<grpc::internal::RpcServiceMethod,std::default_delete<_Ty>>,std::allocator<std::unique_ptr<_Ty,std::default_delete<_Ty>>>> &std::vector<std::unique_ptr<_Ty,std::default_delete<_Ty>>,std::allocator<std::unique_ptr<_Ty,std::default_delete<_Ty>>>>::operator =(const std::vector<std::unique_ptr<_Ty,std::default_delete<_Ty>>,std::allocator<std::unique_ptr<_Ty,std::default_delete<_Ty>>>> &)'
1>        with
1>        [
1>            _Ty=grpc::internal::RpcServiceMethod
1>        ]
1>d:\workspace\code\caxaeap\trunk\2019sp1\platform\server\configureserver\testdll\metaserviceimp.h(13): note: see reference to function template instantiation 'std::vector<std::unique_ptr<grpc::internal::RpcServiceMethod,std::default_delete<_Ty>>,std::allocator<std::unique_ptr<_Ty,std::default_delete<_Ty>>>> &std::vector<std::unique_ptr<_Ty,std::default_delete<_Ty>>,std::allocator<std::unique_ptr<_Ty,std::default_delete<_Ty>>>>::operator =(const std::vector<std::unique_ptr<_Ty,std::default_delete<_Ty>>,std::allocator<std::unique_ptr<_Ty,std::default_delete<_Ty>>>> &)' being compiled
1>        with
1>        [
1>            _Ty=grpc::internal::RpcServiceMethod
1>        ]
1>d:\workspace\code\caxaeap\trunk\2019sp1\thirdmoudle\grpc\include\grpcpp\impl\codegen\service_type.h(158): note: see reference to class template instantiation 'std::vector<std::unique_ptr<grpc::internal::RpcServiceMethod,std::default_delete<_Ty>>,std::allocator<std::unique_ptr<_Ty,std::default_delete<_Ty>>>>' being compiled
1>        with
1>        [
1>            _Ty=grpc::internal::RpcServiceMethod
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.14.26428\include\memory(2309): note: 'std::unique_ptr<grpc::internal::RpcServiceMethod,std::default_delete<_Ty>> &std::unique_ptr<_Ty,std::default_delete<_Ty>>::operator =(const std::unique_ptr<_Ty,std::default_delete<_Ty>> &)': function was explicitly deleted
1>        with
1>        [
1>            _Ty=grpc::internal::RpcServiceMethod
1>        ]
1>Done building project "testdll.vcxproj" -- FAILED.

**## 2. do not use __declspec(dllexport) : ok
image

# Anything else we should know about your project / environment?

I use static grpc, protobuf, my proto library. I want my grpc service class as an export class in dll

Is there any better advice?

@sreecha
Copy link
Contributor

sreecha commented Aug 16, 2018

@jtattermusch / @nicolasnoble : Do either of you have any idea about this issue?

@liukaifei : By any chance, did you already workaround this issue?

@jtattermusch
Copy link
Contributor

I'm not sure I understand the question fully, but it looks like the obvious workaround it to build statically.

@sreecha
Copy link
Contributor

sreecha commented Aug 29, 2018

Closing this issue due to no response from the submitter. Please reopen if needed

@sreecha sreecha closed this as completed Aug 29, 2018
@bassofil
Copy link

According to https://bugs.chromium.org/p/chromium/issues/detail?id=770771#c7 the issue here seems to be that class grpc::Service does not explicitly delete the copy constructor.

@bassofil
Copy link

@sreecha I think it is better to reopen the issue, that should be simply solved by adding

Service (const Service &) = delete;
Service & operator = (const Service &) = delete;

to ::grpc::Service class.
According to https://stackoverflow.com/questions/33376021/deleted-constructor-inheritance nothing should be added to inheriting auto-generated classes.

bassofil added a commit to bassofil/grpc that referenced this issue Oct 12, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jan 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants