c++uwphololensopenxr

Use XrSceneLib_uwp in a native HoloLens 2 OpenXR application


I'm trying to create a native HoloLens 2 C++ application with OpenXR. In the Microsoft OpenXR-MixedReality example I discovered the XrSceneLib_uwp project which has the configuration type set as static library (.lib) in the Visual Studio properties. Accordingly to that I tried to add it as a library in my solution which also has a Core Application (C++/WinRT) in it where I want to use the functions from XrSceneLib_uwp. In my thinking it makes sens because I can use the library for example to create a holographic title scene without much effort. The problem here is that when I build my solution I'm getting linker errors and I don't know how to fix them. I'm also relatively new to Visual Studio (22 in my case) and most likely I'm just doing someting wrong in the linking process.

Linker error when I try to build:

Error LNK2019 unresolved external symbol xrGetInstanceProcAddr referenced in function "public: __cdecl `anonymous namespace'::ImplementXrApp::ImplementXrApp(struct engine::XrAppConfiguration)" (??0ImplementXrApp@?A0x934f03db@@QEAA@UXrAppConfiguration@engine@@@Z) CoreApp3 \repos\CoreApp3\CoreApp3\XrSceneLib_uwp.lib(XrApp.obj) 1

My solution explorer

Here is what I do:

After that everything works fine and I can even build the solution. But when I try to use the library I'm getting these linker errors. I don't understand why it works in the OpenXR-MixedReality examples but not when I try to implement it on an different project. What am I missing? I assume that XrSceneLib may not have been designed to be used externally in other projects but at the same time I think it should be possible somehow.

I also tried to add Additional Library Directories and the missing object files but either I have done something wrong or it just simply does not work.

I really appreciate any help.


Solution

  • I think the linker is failing to find the OpenXR Loader. The sample projects in the microsoft/OpenXR-MixedReality github repo link to the OpenXR Loader using the NuGet package manager. I get the same linker error if I purposely remove the NuGet package references from the sample projects.

    You can either link to the OpenXR Loader using NuGet or you can build the OpenXR Loader youself. Take a look at the "Using OpenXR in an existing project" section on the microsoft site:

    https://learn.microsoft.com/en-us/windows/mixed-reality/develop/native/openxr-getting-started#using-openxr-in-an-existing-project