Linker error passing unique_ptr to function with C++/CLI - by you-drove-me-to-it

Status : 

  Deferred<br /><br />
		The product team has reviewed this issue and has deferred it for consideration at a later time.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


1
0
Sign in
to vote
ID 777768 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 1/29/2013 7:57:25 AM
Access Restriction Public

Description

Creating a unique_ptr and passing it into a function/method causes the linker errors:

error LNK2028: unresolved token (0A00007C) "private: __thiscall std::unique_ptr<int,struct std::default_delete<int> >::unique_ptr<int,struct std::default_delete<int> >(class std::unique_ptr<int,struct std::default_delete<int> > const &)" (??0?$unique_ptr@HU?$default_delete@H@std@@@std@@$$FAAE@ABV01@@Z) referenced in function "public: static void __clrcall std::unique_ptr<int,struct std::default_delete<int> >::<MarshalCopy>(class std::unique_ptr<int,struct std::default_delete<int> > *,class std::unique_ptr<int,struct std::default_delete<int> > *)" (?<MarshalCopy>@?$unique_ptr@HU?$default_delete@H@std@@@std@@$$FSMXPAV12@0@Z)

error LNK2019: unresolved external symbol "private: __thiscall std::unique_ptr<int,struct std::default_delete<int> >::unique_ptr<int,struct std::default_delete<int> >(class std::unique_ptr<int,struct std::default_delete<int> > const &)" (??0?$unique_ptr@HU?$default_delete@H@std@@@std@@$$FAAE@ABV01@@Z) referenced in function "public: static void __clrcall std::unique_ptr<int,struct std::default_delete<int> >::<MarshalCopy>(class std::unique_ptr<int,struct std::default_delete<int> > *,class std::unique_ptr<int,struct std::default_delete<int> > *)" (?<MarshalCopy>@?$unique_ptr@HU?$default_delete@H@std@@@std@@$$FSMXPAV12@0@Z)


This does not occur in my example project in a normal non-CLI build. These errors are from Visual Studio 2010, but I have tested in Visual Studio 2012 express, and the same errors occur. I have tried using pragma managed on/off and only using the unique_ptr's in the unmanaged functions, without success.
Sign in to post a comment.
Posted by Microsoft on 2/12/2013 at 1:50 PM
Hi,

Thank you for taking the time to provide your feedback. After reviewing your reported issue, in the context of all the issues reported to us, we have decided not to take any action on this feedback at this time. We will re-consider our decision for a future release.

If this issue is severe, causing critical business situations or blocking your product development or deployment, please go to http://support.microsoft.com or call 1-800-MICROSOFT for assistance.
For Microsoft premier customers, please contact your administrator, your Technical Account Manager, or your Microsoft premier account representative.

Thanks,
Karl Niu
VC++ Team
Posted by you-drove-me-to-it on 1/30/2013 at 2:36 AM
Regarding the workaround posted by Viorel_, I don't think this would really work in my case, because it changes the point that the memory is freed, and I discovered the problem by including a template that uses this behaviour to have memory freed at the end of a method, when it no longer needs some temporary memory held by a class member variable. The example I made is the simplest case I could come up with, and reworking the templates to manually delete the memory would be a considerable amount of work, and somewhat defeats the purpose of unique_ptr.
Posted by Microsoft on 1/29/2013 at 6:12 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 1/29/2013 at 8:50 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)