Reputation: 12877
Been looking around for how to link a small program that references the DataWriter
My program references other objects (like the winrt::Windows::Devices::Bluetooth class). So I know it's not totally broken.
I have these two libs at the top of my cpp file, which got everything to link until I started using DataWriter.
#pragma comment(lib, "oleaut32")
#pragma comment(lib, "runtimeobject")
it compiles fine, but I have no idea what lib to include. MS reference docs don't seem to mention the libraries you need to link with to use them:
https://learn.microsoft.com/en-us/uwp/api/windows.storage.streams.datawriter
I tried searching (using dumpbin) all of the libraries on my system for it first before posting here.
auto writer = DataWriter();
writer.WriteString(L"HEREIAM");
EDIT: Added the actual linker error:
error LNK2001: unresolved external symbol "public: __cdecl winrt::Windows::Storage::Streams::DataWriter::DataWriter(void)" (??0DataWriter@Streams@Storage@Windows@winrt@@QEAA@XZ)
error LNK2001: unresolved external symbol "public: unsigned int __cdecl winrt::impl::consume_Windows_Storage_Streams_IDataWriter<struct winrt::Windows::Storage::Streams::IDataWriter>::WriteString(struct winrt::param::hstring const &)const " (?WriteString@?$consume_Windows_Storage_Streams_IDataWriter@UIDataWriter@Streams@Storage@Windows@winrt@@@impl@winrt@@QEBAIAEBUhstring@param@3@@Z)
If there's some other way to create a Buffer with winrt, that'd be fine too.
Upvotes: 1
Views: 685
Reputation: 3115
The only lib you need is "windowsapp.lib", although others will do for desktop/console apps. When you get a linker error like that it means that you failed to include a necessary header that provides the missing definition. Try including "winrt/Windows.Storage.Streams.h".
Here's more info from the FAQ.
Upvotes: 2