#include cause errors

2019-03-14 10:44发布

问题:

VS 2010 C++ CLR Library project, errors on adding comutil.h library

> Error 20  error LNK2001: unresolved
> external symbol "extern "C" long
> __stdcall VariantCopy(struct tagVARIANT *,struct tagVARIANT const
> *)" (?VariantCopy@@$$J18YGJPAUtagVARIANT@@PBU1@@Z)    D:\Projects\AL\Service\ncFlow\ncOPClient.NET\Stdafx.obj ncOPClient.NET
> Error 18  error LNK2001: unresolved
> external symbol "extern "C" void
> __stdcall VariantInit(struct tagVARIANT *)"
> (?VariantInit@@$$J14YGXPAUtagVARIANT@@@Z) D:\Projects\AL\Service\ncFlow\ncOPClient.NET\Stdafx.obj ncOPClient.NET
> Error 13  error LNK2001: unresolved
> external symbol "void __stdcall
> _com_issue_error(long)" (?_com_issue_error@@$$FYGXJ@Z)    D:\Projects\AL\Service\ncFlow\ncOPClient.NET\Stdafx.obj ncOPClient.NET
> Error 10  error LNK2028: unresolved
> token (0A000376) "void __stdcall
> _com_issue_error(long)" (?_com_issue_error@@$$FYGXJ@Z)
> referenced in function "void __cdecl
> _com_util::CheckError(long)" (?CheckError@_com_util@@$$FYAXJ@Z)   D:\Projects\AL\Service\ncFlow\ncOPClient.NET\Stdafx.obj ncOPClient.NET
> Error 4   error LNK2028: unresolved
> token (0A0003BC) "extern "C" void
> __stdcall VariantInit(struct tagVARIANT *)"
> (?VariantInit@@$$J14YGXPAUtagVARIANT@@@Z)
> referenced in function "public:
> __thiscall _variant_t::_variant_t(class _variant_t const &)" (??0_variant_t@@$$FQAE@ABV0@@Z)  D:\Projects\AL\Service\ncFlow\ncOPClient.NET\Stdafx.obj ncOPClient.NET
> Error 2   error LNK2028: unresolved
> token (0A0003D1) "extern "C" long
> __stdcall VariantCopy(struct tagVARIANT *,struct tagVARIANT const
> *)" (?VariantCopy@@$$J18YGJPAUtagVARIANT@@PBU1@@Z)
> referenced in function "public:
> __thiscall _variant_t::_variant_t(class _variant_t const &)" (??0_variant_t@@$$FQAE@ABV0@@Z)  D:\Projects\AL\Service\ncFlow\ncOPClient.NET\Stdafx.obj ncOPClient.NET

needed for

private:
        std::string from_variant(VARIANT& vt)
        {
            _bstr_t bs(vt);
            return std::string(static_cast<const char*>(bs));
        }
        /*
        void to_variant(const std::string& str, VARIANT& vt)
        {
            _bstr_t bs(str.c_str());
            reinterpret_cast<_variant_t&>(vt) = bs;
        }*/

how can I fix it ?

回答1:

According to MSDN, _bstr_t requires comsuppw.lib. Add this library to the linker dependencies list.



回答2:

try to include comdef.h, don't include comutil.h



回答3:

Add the requisite import library as per the documentation, likely Oleaut32.lib

http://msdn.microsoft.com/en-us/library/ms221236.aspx

edit: I'm assuming the Compiler COM Support library subsumes this and Alex's answer would be the preferred library.



标签: c++ clr