Unresolved external - c++

I am having difficulty figuring out my unresolved external errors.
I have 2 different solutions that both share a core project. Solution #1 is called SnapGame and Solution #2 is called SnapEditor. The core project is called SnapCore.
My SnapGame solution is a Win32 application. It compiles, references, and links the SnapCore project with no issues.
The SnapEditor solution is a Windows Forms Application. It compiles and references the SnapCore project. However, it will not link with it properly. I get unresolved external errors any time I try to reference anything from the SnapCore project.
The SnapCore project has some GDI+ support classes. All classes in the SnapCore project are under the SnapCore namespace.
Here is the file Form1.cpp:
#include "stdafx.h"
#include "App.h"
#include "Orient.h"
using namespace SnapCore;
using namespace SnapEdit;
void Form1::Init()
{
SnapCore::Orient orient;
new App();
}
Here are the linker errors I get:
1>Form1.obj : warning LNK4248: unresolved typeref token (01000049) for 'Gdiplus.GpCachedBitmap'; image may not run
1>Form1.obj : error LNK2028: unresolved token (0A000019) "public: __clrcall SnapCore::App::App(void)" (??0App#SnapCore##$$FQAM#XZ) referenced in function "public: void __clrcall SnapEdit::Form1::InitSnapCore(void)" (?InitSnapCore#Form1#SnapEdit##$$FQ$AAMXXZ)
1>Form1.obj : error LNK2028: unresolved token (0A00001A) "public: __clrcall SnapCore::Orient::Orient(void)" (??0Orient#SnapCore##$$FQAM#XZ) referenced in function "public: void __clrcall SnapEdit::Form1::InitSnapCore(void)" (?InitSnapCore#Form1#SnapEdit##$$FQ$AAMXXZ)
1>Form1.obj : error LNK2019: unresolved external symbol "public: __clrcall SnapCore::App::App(void)" (??0App#SnapCore##$$FQAM#XZ) referenced in function "public: void __clrcall SnapEdit::Form1::InitSnapCore(void)" (?InitSnapCore#Form1#SnapEdit##$$FQ$AAMXXZ)
1>Form1.obj : error LNK2019: unresolved external symbol "public: __clrcall SnapCore::Orient::Orient(void)" (??0Orient#SnapCore##$$FQAM#XZ) referenced in function "public: void __clrcall SnapEdit::Form1::InitSnapCore(void)" (?InitSnapCore#Form1#SnapEdit##$$FQ$AAMXXZ)
1>C:\Work\PC\SnapEdit\SnapEdit\Debug\SnapEdit.exe : fatal error LNK1120: 4 unresolved externals
I can't figure out why my SnapGame solution links with no troubles, but the SnapEditor solution will not.
Any help would be appreciated.

If I understand you right, SnapEditor is a managed application. It can't simply refer to a native library, like SnapCore. Use P/Invoke, or write a managed wrapper.

Related

Unresolved external symbol ATL::IAtlMemMgr after upgrading to Visual Studio 2019

I am currently upgrading our source code from VS2012 to VS2019. One project which uses MFC does not link successfully:
fatal error LNK1120: 4 unresolved externals
error LNK2001: unresolved external symbol "public: void * __cdecl ATL::IAtlMemMgr::Allocate(unsigned __int64)" referenced in function "public: virtual struct ATL::CStringData * __cdecl ATL::CAtlStringMgr::Allocate(int,int)"
error LNK2001: unresolved external symbol "public: void __cdecl ATL::IAtlMemMgr::Free(void *)" referenced in function "public: virtual void __cdecl ATL::CAtlStringMgr::Free(struct ATL::CStringData *)"
error LNK2001: unresolved external symbol "public: void * __cdecl ATL::IAtlMemMgr::Reallocate(void *,unsigned __int64)" referenced in function "public: virtual struct ATL::CStringData * __cdecl ATL::CAtlStringMgr::Reallocate(struct ATL::CStringData *,int,int)"
error LNK2001: unresolved external symbol "public: virtual struct ATL::CStringData * __cdecl ATL::IAtlStringMgr::Reallocate(struct ATL::CStringData *,int,int)"
We are building with Multi-Byte Character Set (MBCS). My first thought was, that we are missing the the mbcs libraries. But as mentioned here, the libraries are installed by default, "when you select MFC and ATL support".
I added atlbase.h in the code and added atls.lib manually as additional dependency, but that did not solve the problem.
How can I figure out which library is missing?
Edit 1:
Let's take a look into atlmem.h:
__interface __declspec(uuid("654F7EF5-CFDF-4df9-A450-6C6A13C622C0")) IAtlMemMgr{
public:
_Ret_maybenull_ _Post_writable_byte_size_(nBytes) void* Allocate(_In_ size_t nBytes) throw();
As far as I see, this is one of the symbols which is not found. As can be red about the __interface keyword, it implicitly makes the functions pure virtual. These kind of linker errors might be caused by non pure virtual function declarations.
Might there be a bug which makes the functions in the __interface not pure virtual?
After excluding nearly all source files and commenting out a lot of functionality, I could see that the linker errors are correlated to <afxwin.h>. Moving <afxwin.h> to the top of each source files removed the linker errors.
However, I am interested to know why compiling with VS2012 gives another behavior compared to VS2019.

LNK2019 error using Nite and OpenNI

I haven't ever seen the error of LNK 2019 before and now I encounter it when i try to link the code that i get from Nite.
The error is...
1>kinect.obj : error LNK2019: unresolved external symbol __imp__niteShutdownHandTracker referenced in function "public: void __thiscall nite::HandTracker::destroy(void)" (?destroy#HandTracker#nite##QAEXXZ)
1>kinect.obj : error LNK2019: unresolved external symbol __imp__niteStartHandTracking referenced in function "public: enum nite::Status __thiscall nite::HandTracker::startHandTracking(class nite::Point3f const &,short *)" (?startHandTracking#HandTracker#nite##QAE?AW4Status#2#ABVPoint3f#2#PAF#Z)
1>kinect.obj : error LNK2019: unresolved external symbol __imp__niteReadHandTrackerFrame referenced in function "public: enum nite::Status __thiscall nite::HandTracker::readFrame(class nite::HandTrackerFrameRef *)" (?readFrame#HandTracker#nite##QAE?AW4Status#2#PAVHandTrackerFrameRef#2##Z)
1>kinect.obj : error LNK2019: unresolved external symbol __imp__niteHandTrackerFrameRelease referenced in function "public: void __thiscall nite::HandTrackerFrameRef::release(void)" (?release#HandTrackerFrameRef#nite##QAEXXZ)
1>kinect.obj : error LNK2019: unresolved external symbol __imp__niteStartGestureDetection referenced in function "public: enum nite::Status __thiscall nite::HandTracker::startGestureDetection(enum nite::GestureType)" (?startGestureDetection#HandTracker#nite##QAE?AW4Status#2#W4GestureType#2##Z)
1>D:\AcerUser\Documents\Visual Studio 2013\Projects\kinect\Debug\kinect.exe : fatal error LNK1120: 11 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
how to solve it?
Thanks
If you get error LNK2019 from Visual Studio Console output, you might building your project for Win32 platform on your 64bit Windows, try swiching to x64.
IF you are Using Visual Studio GO TO ->Build --> (thats where you change or create win32/x64
Configuration Manager
Are you sure your application is being linked against the corresponding libraries?
Somewhere in your OpenNI and Nite installation, there must be a folder containing .lib files. You have to specify this path in the additional library directories in your project's property page. If it still doesn't work afterwards, you should add the names of these libraries in the additional dependencies.

unresolved external symbol due to CString

I have a prject where the main process is a DLL and it is being used the UI project.
When I declare a variable in the DLL project as below
CString NewMethod;
I get the above error unresolved external symbol in the UI project.
NewPNCUI.obj : error LNK2001: unresolved external symbol "public: __thiscall WBFilter::~WBFilter(void)" (??1WBFilter##QAE#XZ)
Here WBFilter is a completely separate class and unrelated.
How do I solve this?
Many thanks.
Best Regards
Chitnan

Strange LNK2001 linker error

Yesterday I got this linker error. I have searched on google and msdn without success.
My problem:
I have moved some parts of my cpp project in a extern static library. I added the h file to my main project and added the dependencies to the lib files. Unfortunately I get a lot linker errors.
1>Compressor.obj : error LNK2001: unresolved external symbol "public: bool __thiscall NWindows::NFile::NFind::CFileInfo::Find(unsigned short const *)" (?Find#CFileInfo#NFind#NFile#NWindows##QAE_NPBG#Z)
1>Compressor.obj : error LNK2001: unresolved external symbol "public: class NWindows::NCOM::CPropVariant & __thiscall NWindows::NCOM::CPropVariant::operator=(unsigned short const *)" (??4CPropVariant#NCOM#NWindows##QAEAAV012#PBG#Z)
1>Compressor.obj : error LNK2001: unresolved external symbol "public: bool __thiscall CInFileStream::Open(unsigned short const *)" (?Open#CInFileStream##QAE_NPBG#Z)
1>Compressor.obj : error LNK2001: unresolved external symbol "public: bool __thiscall NWindows::NFile::NIO::COutFile::Create(unsigned short const *,bool)" (?Create#COutFile#NIO#NFile#NWindows##QAE_NPBG_N#Z)
1>Compressor.obj : error LNK2001: unresolved external symbol "void __cdecl ConvertUInt32ToString(unsigned int,unsigned short *)" (?ConvertUInt32ToString##YAXIPAG#Z)
1>Compressor.obj : error LNK2001: unresolved external symbol "public: bool __thiscall NWindows::NDLL::CLibrary::Load(unsigned short const *)" (?Load#CLibrary#NDLL#NWindows##QAE_NPBG#Z)
All this methods a part of my extern lib. I have tries a lot of compiler settings without success.
Further more when I remove the lib dependencie completely from the linker I get 26 LNK2001 error. So the linker finds only "parts" of the lib.
Do I use a wrong compiler / linker option for my projects?
edit:
The problem was the parameter define LPCTSTR of the method CLibrary::Load(LPCTSTR fileName). In my lib I set the option "Treat wchar_t as build-in type (Properties->C/C++->Lanuage-> ... ) to No. And now it works.
There's not enough information in the question so my answer merely serves as a guide.
Take one function, for instance bool NWindows::NFile::NFind::CFileInfo::Find(unsigned short const *) and find definition of it in your code. Is it there? With this exact function signature? Is it in unnamed namespace? Is it declared static in source file?
Also, try full rebuild of everything. You'd be surprised how many times full rebuild makes mysterious problems go away.

Linker generates LNK2001 (( try to make unmanaged c++ dll in vs 2010

Error 10 error LNK2001: unresolved external symbol "public: virtual void __thiscall MPPostProcess::prepareForProcess(void)" (?prepareForProcess#MPPostProcess##UAEXXZ) D:\Prj\MagicLib\MagicLib\dllmain.obj MagicLib
Error 11 error LNK2001: unresolved external symbol "public: virtual void __thiscall MPPostProcess::prepareForProcess(void)" (?prepareForProcess#MPPostProcess##UAEXXZ) D:\Prj\MagicLib\MagicLib\MPImageData.obj MagicLib
Error 12 error LNK2019: unresolved external symbol "private: virtual __thiscall PPBlackAndWhite::~PPBlackAndWhite(void)" (??1PPBlackAndWhite##EAE#XZ) referenced in function "private: virtual void * __thiscall PPBlackAndWhite::`scalar deleting destructor'(unsigned int)" (??_GPPBlackAndWhite##EAEPAXI#Z) D:\Prj\MagicLib\MagicLib\dllmain.obj MagicLib
How to cure this?
There are 2 likely candidates for unresolved external errors:
If you defined the MPPostProcess class, then you have probably forgot to provide an implementation for the prepareForProcess(void) and ~PPBlackAndWhite(void) functions.
If the MPPostProcess class is a class you are using provided by an external library, then you need to link to the library that provides those functions
You probably haven't provided definitions for prepareForProcess() or ~PPBlackAndWhite().