Use XrSceneLib_uwp in a native HoloLens 2 OpenXR application - c++

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:
I copy and paste the shared and openxr_preview folders from the OpenXR-MixedReality .zip file in my project folder.
Add XrSceneLib_uwp.vcxproj in /shared/XrSceneLib as an existing project to my solution.
Add the path to the copied shared and openxr_preview folders in Properties->Configuration Properties->C/C++->General->Additional Include Directories.
Add also the path to XrSceneLib_uwp.vcxproj in Additional Include Directories in my main project (CoreApp).
Add reference in CoreApp to XrSceneLib_uwp (Add->Reference->Projects).
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.

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

Related

C++ detours linking issue

I have problems building my code that is using static lib detours. I am trying to do an old basic CTF. For that I want to get into detours.
Whenever I try to build my .dll file I get an issue
LNK2019 unresolved external symbol _DetourTransactionBegin#0 referenced in function _DllMain#12
Now, I have built the detours library using 3 different version of the visual studio dev console.
I have tried firing 'vcvars32.bat' and then using nmake to build the library which was able to build it, but I get the above error during linking my .dll. I have also tried building it with 'vcvarsamd64_x86.bat' and then using nmake to build it which also was able to build the library, but I still get the same error as above during linking.
I have tried the usual stuff: the include folder for detours.h is added to C++/General/Additional Include Directories.
Under Linker/Additional Library Directories I added them as follows: "C:\temp\det_retry\lib.X64";"C:\temp\det_retry\lib.X86";%(AdditionalLibraryDirectories).
And also under Linker/Input/Additional Dependencies I have the following: detours.lib;%(AdditionalDependencies)
What am I missing here? This is a blocker for me for a couple of days and I am reiterating the same steps trying to figure out what's missing but I cannot see. I'd really appreciate the input.
I am sure I am using the newest version because I have downloaded (cloned) detours from the ms github page.
It appears your "Additional Library Directories" are setup incorrectly or contain invalid entries rather. They look like actual library file entries (i.e. pointing to some specific files) versus being only directories (e.g. "my/lib/path/for/my_project/"). Visual Studio's naming conventions are somewhat cryptic but they should be directory entries only. There should be an entry to whatever directory contains the detours.lib file (e.g. "MyProject/Libs/MSDetour" ... where MSDetour is a folder with the "detours.lib" in it) and then Visual Studio should find the library and link everything correctly.
As a side note, if you are using the Visual Studio developer console for building your project/solution you might want to look into CMake ... it is, in my opinion, significantly easier to work with (less "settings" digging) and maintain in the long-run.

Unresolved external symbol when including MFC object library

I have an object file library that exists as a standalone VC++ project. I have a number of other completely separate VC++ solutions, and I would like some of them to utilise the classes included in this library.
I have added the project to a solution as detailed here: (See docs). I have followed all of the instructions but am still getting "unresolved external symbol" errors when trying to use the class.
Can anyone help?
Specifics:
The class library in question is an SQL access library. Inside there are two files, sql.h and sql.cpp. Pretty simple. That project compiles itself absolutely fine, so I know there is nothing wrong with that project. I was under the impression that to get the project included in an existing solution I had to:
Add the project to add the project to the solution
Add a reference to the project
Add the include directory
Add #include "sql.h" to the project
That is what I have done, to no success.
Please make sure the external library is linked into your project. It usually comes in a form of a .lib file (for example, sql.lib)
Go to Configuration Properties ->Linker and add your library to the "Additional Dependencies" list.

Linking DLL error visual studio

I walked through this tutorial and tried to recreate the example I get this error:
Error 1 error LNK2019: unresolved external symbol __imp__GetXyz#0 referenced in function _main app.obj app
If I download the source from the website and run the project in visual studio it works, but If I even copy the code from the original project in my own visual studio solution it still doesn't work. I guess it must be some project settings, I don't know. What do do?
You need to add the XyzLibrary.lib to your Linker settings within project settings.
You can also do it directly in code by using #pragma comment(lib,"xyzlibrary.lib") if you are using VisualStudio.
The reason why it works in the given sample without these 2 approaches is that in the solution file, the dependencies are set from XyzExe to XyzLib, and XyzProject has 'Link Library Dependencies' in Linker settings set to true. However, I am not too keen on this approach, as I don't like to store data important for building inside solution files (for larger projects, developer's solution files can differ from build system solution files)
Seems like you are missing some external library that needs to be linked in. Whatever provides the GetXyz function is missing.
Open the Solution that works, right click the project, Properties, Linker, Input, and check what their Additional Dependencies list up. You need to add the same to your own project.

Visual studio 6.0 (VC++ reference issue)

I have the following workspace images of my project
I would like to know what are the highlighted components in Workspace ?
I tried to find out more about it by trying to access its properties but nothing was available. So I deleted them .But know if I try to build my VeCAD_EXE project I get unresolved external symbol errors for the methods defined in CAD_DLL project.
I suppose it acted as some reference to my CAD_DLL project.
But I don't know how do I get those 2 components back again :(.
Any views of how can I achieve this is highly appreciated.
Those are the dependencies that should be built before building VECAD_EXE project. Probably these project produce .lib/.dll that must be linked with main project and because they are missing you receive linking error.
To change dependencies for project go to Project -> Dependencies... menu.

ODBC refuses to statically link to libcmt.lib under VS2010

There is a short response from Microsoft regarding this issue:
https://connect.microsoft.com/VisualStudio/feedback/details/470376/odbc-application-linking-with-odbccp32-lib-gets-link-errors-in-vs2010-beta-1?wa=wsignin1.0#tabs
Basically, their response doesn't seem to address the problem.
Our application needs to statically link to the C libraries, but there is a linker error when attempting to do so. Microsoft's answer seems to be "dynamically link instead", but that's not an option. Their alternative is to "Use the version of odbccp32.lib that came with Vista SDK." However, I am unaware as to how to force VisualStudio 2010 to use a different version of the ODBC library?
I just spent the last hour trying every conceivable search through the .vcxproj and .sln files for any references to odbccp32.lib. None. I similarly looked for ODBC. None. Looking at all of the compiler & linker options for the project(s) in question: nothing refers to ODBC whatsoever. The only connection between our application and ODBC I can see is the #include <sql.h> and <sqlext.h>. However, even those files do not refer to odbccp32.lib (or any other .lib or linker option).
The only references to odbccp32.lib I can find at all are in .obj files. So it appears that VS2010 automagically knows which ODBC libraries to link against based on what functions are referenced in our software (SQLConnect(), for example).
So how might I:
1) "obtain Vista SDK version of odbccp32.lib"?
2) cause VS2010 to link against that version?
-OR-
Is there a better way to solve this?! Right now I am unable to proceed with a conversion of our software from VS2008 -> 2010 unless I can find a way to force this goofy software to compile.
NOTE: Apparently I could force the system to compile using 2008's tooling, which may "cure" this. But that means changing all of our projects up & down the chain to do this, which is rather backwards and contrary to the whole point of moving to 2010, no?
For the curious, the exact linker error:
odbccp32.lib(dllload.obj) : error LNK2019: unresolved external symbol __imp___vsnprintf referenced in function _StringVPrintfWorkerA#20
Reading through your link, it seems that Microsoft has verified that there is a problem, and they intend to fix it in the next version of the SDK. Doesn't help much, does it?
It's quite normal for the linker to daisy-chain through the objects, linking one object only to discover that it has dependencies on other objects. If you want to preemptively link to a specific library, add it to the "Additional Dependencies" in the Linker Input tab of the project properties.
If you aren't able to get the linker to prefer a specific version of a library, just seek out and replace the version of the library in the installation.
I think this is a link to the Vista SDK, but I can't verify it: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=ff6467e6-5bba-4bf5-b562-9199be864d29&displaylang=en
I see it. Ouch, my condolences. Their advice is about as best as it is going to get if you don't want to compile with /MD. I think I know the source of the problem, this isn't that easy to fix for them either. It's going to require them getting the VS2010 CRT header file fixed first, then recompile and issue an SDK update. That takes some major doing.
It is getting linked because it is listed in the "Core Windows Libraries" property sheet. View + Property Manager to see it. Not linking it is not an option, you are probably actually using it when you #include <sql.h>
The Vista version indeed doesn't have the same problem, it was probably built with an earlier version of VS. Project + Properties, Linker, Input, Additional Dependencies = "c:\program files\microsoft sdks\windows\v6.0a\lib\odbccp32.lib". This injects the vista version before the 7.0 version. You may have to live with this for a while, be sure to keep VS2008 installed on your build machines.
I just encountered the undefined __imp___vsnprintf symbol while converting an ODBC application to Visual Studio 2015. Figuring that there must be a workaround, I dumped all the symbols exported by the various libraries in the Visual Studio 2015 LIB directories with DUMPBIN and found that this library with a most obvious name, legacy_stdio_definitions.lib, defines these symbols.
Adding this to the LINK command line resolved the missing external referenced by odbccp32.lib.
Once one knows what to search for, some info is available here.
Don't know all the details, so shooting in the dark. When I had a situation when certain functions were available with one compiler and not the other, I created a simple DLL with the functions exported with C interface, using compiler version that supported those functions, and used that DLL with another compiler.
the solution is to link with just odbccp32.lib from v6.0 sdk all else from the default sdk.
1. download v6.0 sdk from: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=ff6467e6-5bba-4bf5-b562-9199be864d29&displaylang=en
(do not install documentation and samples/examples, the result is 75MB downlaod):
2. create a folder, some folder.
for example: lib_odbc_fromsdkv6.0 in your project's folder
3. copy the file odbccp32.lib from:
C:\Program Files\Microsoft SDKs\Windows\v6.0\Lib
to folder created above (only one file).
4. in each project's properties add that (lib_odbc_fromsdkv6.0) directory to Library directories:
VC++ Directories -> Library directories
the depended projects in myodbc are myodbc5S and myodbc-installer.
(from Mordachai)