C++ linking error unresolved external symbol - c++

I have a project that includes files from a different project. I am getting linking errors...
"unresolved external symbol "public: _cdecl classA::classA(void"
(??()classA ##QEAA#XZ) referenced in function "class classA *_cdecl
functionB(char const*)" (?functionB##YAPEAVClassA##PEBD#Z)...
and other 125 errors of the same type (after the constructor, which is the error I just listed, every function from the class I use is mentioned in one of the link errors).
The path for including the files of the second project is included in my property sheet. That project, on its own, builds fine.
I have tried to add that project to my solution, and add it as a dependency. No help. I have tried to add the dll that it creates in the project - linker - input. No help.
In Configuration properties, the Runtime Library is set to /MTd.
I have even tried to add extern "C" in front of my include. No help.
I have tried to build them with Debug or Release, x64 or Win32. I prefer Release x64 but I'll take anything.
Could you please help me - tell me what am I doing wrong, or where to look to fix this problem ? Thank you very much.

When you build the project which yours depends on, it should produce both a lib and a dll. You need to link that lib with your project. See this thread for a screenshot of how to link the lib in your project.

I found out that my dependencies in the Link - Input were being removed by the fact that I didn't explicitly specify that I can have dependencies in the property sheet. After changing the property sheet, I finally was able to create a dll.

Related

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:
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

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.

C++ - LNK2019 unresolved external symbol - Can't seem to find what I'm missing

I know this is a common problem and I can see quite a few questions about LNK2019 but I can't for the life of me find what I'm missing.
I am working on a C++ DirectX project and I want to use the DirectXTK library (Direct X Tool Kit). I have included the project in my solution and it builds fine.
I've also included the ScreenGrab.h header I want to use in my own project. Intellisense picks up the function definitions from ScreenGrab.h fine and so I have called SaveDDSTextureToFile().
But when I go to build the project I get the LNK2019 error on SaveDDSTextureToFile(). I'm assuming this means it knows where the definition is (in the header) but can't find the implementation of the function in the .obj or .lib, is this correct?
I assume I need to tell the linker where these files are? I tried doing that in Properties->Configuration Settings->Linker->General->Additional Library Directories but I still get the LNK2019 error.
Does anyone know what I'm still missing?
Thanks for your time.
Stupidly, I didn't add the lib to the Linker oops.
Basically for anyone else that forgets this step - after you've added the directory to Linker->General, go over to Linker->Input and add the name of the .lib to "Additional Dependencies" - so for me I typed "DirectXTK.lib" here (without the quotes).
If I hadn't added the directory to Linker->General I also could have typed "../folder1/folder2/folder-etc/DirectXTK.lib" here depending on the relative path from where my project is.
Sorry for wasting people's time and I hope this helps others.
Make sure your linker->general->additional library directories configuration is for all configurations, and not just "release" or "debug". Try adding the static library file (depending on the Direct3D version you're using) to your project from the SDK directories - if it compiles then you've definitely done something wrong with the linker configurations.

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.