7

Possible Duplicate:
What is an undefined reference/unresolved external symbol error and how do I fix it?

I'm trying to make WinRT library that is not using CX extension. I need to get name of package, roaming data folder, etc.. I wrote some wrapper, but when I'm linking this library to executable project, I get linker error

error LNK2019: unresolved external symbol _WindowsCreateStringReference@16 referenced in function "private: void __thiscall Microsoft::WRL::Wrappers::HStringReference::CreateReference(wchar_t const *,unsigned int,unsigned int)" (?CreateReference@HStringReference@Wrappers@WRL@Microsoft@@AAEXPB_WII@Z)
error LNK2019: unresolved external symbol _WindowsDeleteString@4 referenced in function "public: __thiscall Microsoft::WRL::Wrappers::HStringReference::~HStringReference(void)" (??1HStringReference@Wrappers@WRL@Microsoft@@QAE@XZ)
error LNK2019: unresolved external symbol _WindowsGetStringRawBuffer@8 referenced in function "long __cdecl aponialib::winrt::GetFullName(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > &)" (?GetFullName@winrt@aponialib@@YAJAAV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@@Z)
error LNK2019: unresolved external symbol __imp__RoGetActivationFactory@12 referenced in function "long __cdecl Windows::Foundation::GetActivationFactory<struct ABI::Windows::Storage::IApplicationDataStatics>(struct HSTRING__ *,struct ABI::Windows::Storage::IApplicationDataStatics * *)" (??$GetActivationFactory@UIApplicationDataStatics@Storage@Windows@ABI@@@Foundation@Windows@@YAJPAUHSTRING__@@PAPAUIApplicationDataStatics@Storage@1ABI@@@Z)

this is package name wrapper

// including in .h
#include <windows.h>
#include <string>
#include <Strsafe.h>
#include <Winstring.h>

#include <windows.storage.h>
#include <Windows.ApplicationModel.h>
#include <windows.Foundation.h>
#include <wrl/client.h>
#include <wrl/wrappers/corewrappers.h>

//...

HRESULT GetFullName(std::wstring &fullName)
{
    HRESULT hr;
    Microsoft::WRL::ComPtr<ABI::Windows::ApplicationModel::IPackageStatics> packageStatics;

    hr = Windows::Foundation::GetActivationFactory(Microsoft::WRL::Wrappers::HStringReference(RuntimeClass_Windows_ApplicationModel_Package).Get(), &packageStatics);
    if (FAILED(hr))
        return hr;

    Microsoft::WRL::ComPtr<ABI::Windows::ApplicationModel::IPackage> package;
    hr = packageStatics->get_Current(&package);
    if (FAILED(hr))
        return hr;

    Microsoft::WRL::ComPtr<ABI::Windows::ApplicationModel::IPackageId> packageId;
    hr = package->get_Id(&packageId);
    if (FAILED(hr))
        return hr;

    HSTRING name;
    hr = packageId->get_FullName(&name);
    if (FAILED(hr))
        return hr;

    UINT32 length;
    PCWSTR value = WindowsGetStringRawBuffer(name, &length);
    fullName = value;
    WindowsDeleteString(name);
    return S_OK;
}

Maybe I don't get WRL and I'm using it wrong.

Thank you for your help :) Tomas

Community
  • 1
  • 1
Lipov3cz3k
  • 454
  • 4
  • 14
  • possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/). You are in the case [Failure to link against appropriate libraries/object files or compile implementation files](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix/12574400#12574400). – Raymond Chen Oct 23 '12 at 13:31
  • 13
    @RaymondChen "Look up the ... documentation, and it should say which library" Not helpful when the MSDN entry for WindowsCreateStringReference and most of the recent WinRT API's are light, along with anything related to WRL and real C++. Thankfully someone's community content has filled in the gap that #pragma comment(lib,"runtimeobject") fills the need. – Dwayne Robinson Mar 28 '15 at 10:53
  • 1
    Looking at the documentation for [WindowsCreateStringReference](https://msdn.microsoft.com/en-us/library/br224631.aspx), [WindowsDeleteString](https://msdn.microsoft.com/en-us/library/br224632.aspx), and [WindowsGetStringRawBuffer](https://msdn.microsoft.com/en-us/library/br224636.aspx) doesn't answer the question **which** import library to use, and the header file *Winstring.h* doesn't contain an appropriate `#pragma comment(lib, "...")` directive either. Voting to re-open the question. – IInspectable Aug 29 '16 at 15:27
  • 2
    @RaymondChen : This is not a duplicate. Many developers know the answer to the question you have pointed to, but for people new to WRL (https://msdn.microsoft.com/en-us/library/hh438466) this question will be more relevant. – Sahil Singh Jul 14 '17 at 10:16
  • 6
    Add **WindowsApp.lib** in additional linker dependencies (`Linker->Input->Additional Dependencies`) (from - https://stackoverflow.com/a/39759804/981766 , https://stackoverflow.com/questions/35578616/unresolved-external-symbols-in-qtmaind-lib/39759804) – Sahil Singh Jul 14 '17 at 10:21

0 Answers0