Search code examples
c++-winrt

C++/WinRT Library support


Does c++/WinRT supports c++ static/dynamic library?

I have a c++ static library which I tried to add as a reference in c++/winrt project but VS says project not supported!

My VS Version :: Microsoft Visual Studio Enterprise 2019 Version 16.4.5

How I tried to add reference :

  • Right click on my project-> Add->Reference
  • Select the c++ library project from the Add Reference window

Then a warning dialog is shown that project is not supported. Please see the attached image

enter image description here


Solution

  • From this document, it mentions

    If you just try to add a reference from a Universal Windows Project to a classic desktop library, you get an error message that says the library is not compatible. In the case of a static library, you can link to your library simply by adding the library (.lib file) to your linker input.

    Do not add a reference in the References node in Solution Explorer. That mechanism only works for Windows Runtime Components.

    So you need to right-click your c++/winrt project, choose Configuration Properties > Linker > Input and add the path to the library in the Additional Dependencies. Then include the header file to your pch.h or .cpp file.

    The specific steps you can refer here.