I'm experimenting the next error when including muiload.h and linking with muiload.lib and calling LoadMUILibrary in Visual Studio 2015:
Muiload.lib(muiload.obj) : error LNK2019: unresolved external symbol
__vsnwprintf referenced in function "long __stdcall StringVPrintfWorkerW(unsigned short *,unsigned int,unsigned int
*,unsigned short const *,char *)" (?StringVPrintfWorkerW##YGJPAGIPAIPBGPAD#Z)
Maybe something wrong in muiload.lib?
Solved adding the additional library legacy_stdio_definitions.lib to the linker input as explained in https://social.msdn.microsoft.com/Forums/en-US/5150eeec-4427-440f-ab19-aecb26113d31/updated-to-vs-2015-and-now-get-unresolved-external-errors?forum=vcgeneral
An alternative to linking against legacy_stdio_definitions.lib is to redefine these function signatures to match their deprecated style:
int (WINAPIV * __vsnprintf)(char *, size_t, const char*, va_list) = _vsnprintf;
int (WINAPIV * __vsnwprintf)(wchar_t *, size_t, const wchar_t*, va_list) = _vsnwprintf;
One benefit of this is that it avoids other possible linker definition issues caused by including the legacy library.
Note that this should be defined in a compiler unit (.cpp) rather than in a header file.
Related
so i was following along an dll injection tutorial on yt, and it gave me some errors when trying to compile.
1.unresolved external symbol "unsigned __int64 __cdecl Detours::X64::DetourFunction(unsigned __int64,unsigned __int64,enum Detours::X64Option)" (?DetourFunction#X64#Detours##YA_K_K0W4X64Option#2##Z) referenced in function "unsigned long __cdecl mainThread(void *)"
CODE TO ERROR:
DWORD WINAPI mainThread(PVOID base) {
void* d3d9Device[119];
if(GetD3D9Device(d3d9Device, sizeof(d3d9Device))){
oEndScene = (EndScene)Detours::X64::DetourFunction((uintptr_t)d3d9Device[42], (uintptr_t)hkEndScene);//here
}
while (true) {
if (GetAsyncKeyState(VK_F10)) {
CleanUpDeviceD3D();
FreeLibraryAndExitThread(static_cast<HMODULE>(base),1);
}
}
FreeLibraryAndExitThread(static_cast<HMODULE>(base), 1);
}
2. unresolved external symbol Direct3DCreate9 referenced in function "bool __cdecl GetD3D9Device(void * *,unsigned __int64)"
CODE TO ERROR:
bool GetD3D9Device(void **pTable, size_t size) {
if (!pTable) {
return false;
}
g_pD3D = Direct3DCreate9(D3D_SDK_VERSION); //here
on the first error, the tutorial stated you should use the following syntax:
oEndScene = (EndScene)Detours::X64::DetourFunction((Detours::uint8_t*)d3d9Device[42], (Detours::uint8_t*)hkEndScene);
however detours doesnt have uint8_t for me and some forums online said to use uintptr_t. but i still get the error. ive tried looking at my includes for lib and release in detours but it still says unresolved external symbol even after including the folder where Detoursx64.cpp is present.
any help ise appreciated.
you need to compile Detours as x86 and use the release folder instead of compiling detours as x64
I am working on a C++ Windows Form Application in Visual Studio 2019.
I want to use some functions of the external library EDFlib. EDFlib is a programming library for C/C++ which consists of only two files (.c and .h).
Here, a simple code that writes data in an EDF file when I click on a button:
#include "edflib.h"
// [...]
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
double buf[200];
for (int i = 0; i < 200; i++)
buf[i] = i;
int hdl;
hdl = edfopen_file_writeonly("test.edf", EDFLIB_FILETYPE_EDFPLUS, 1);
// [...]
edfwrite_physical_samples(hdl, buf);
edfclose_file(hdl);
}
// [...]
I have the 2 following errors:
Erreur LNK2028 jeton non résolu (0A000038) "extern "C" int __cdecl edfopen_file_writeonly(char const *,int,int)" (?edfopen_file_writeonly##$$J0YAHPBDHH#Z) référencé dans la fonction "private: void __clrcall TestEDF::MyForm::button1_Click(class System::Object ^,class System::EventArgs ^)" (?button1_Click#MyForm#TestEDF##$$FA$AAMXP$AAVObject#System##P$AAVEventArgs#4##Z)
&
Erreur LNK2019 symbole externe non résolu "extern "C" int __cdecl edfopen_file_writeonly(char const *,int,int)" (?edfopen_file_writeonly##$$J0YAHPBDHH#Z) référencé dans la fonction "private: void __clrcall TestEDF::MyForm::button1_Click(class System::Object ^,class System::EventArgs ^)" (?button1_Click#MyForm#TestEDF##$$FA$AAMXP$AAVObject#System##P$AAVEventArgs#4##Z)
I tried to read documentation about these errors.
But I am not an C/C++ expert. I don't know what to do. I need some help.
Thanks.
I am guessing the errors state that you have unresolved symbols,
it means that you are calling functions that you have a declaration for (from the #include "edflib.h") that the linker tries to find during the build process but have no definition.
it seems like you just included the header of the library, but you need to also link with it.
I don't know what IDE you use but you should look up how to link libraries to your projects in C++.
there is a lot of information about creating and linking libraries online that should help you solve this issue.
You Should Give Extern "C" Method and Add the Library into It, Check
https://isocpp.org/wiki/faq/mixing-c-and-cpp
You Cannot Externally Add C Libraries in C++
I've declared a simple function with variadic template.
template<typename ...Args>
void Log(const LogLevel level, const char * format, Args ...args);
Upon calling it in the following manner -
Log(LogLevel::debug,
R"(starting x, %d pending call for "%s" with param "%s")",
id, first.c_str(),
second.c_str())
where the variable types are : id (unsigned int), first (std::string) , second (std::string)
I'm getting the following error:
Error LNK2001 unresolved external symbol "public: void __cdecl Log<unsigned int,char const *,char const *>(enum LogLevel,char const *,unsigned int,char const *,char const *)"
When I remove the unsigned int argument from the function call - the error disappears.
AFAIK the variadic template does support different types... so what am I missing?
It's a linker error, so (I suppose) you have declared the template function in a header file and defined it in a c++ (not header) file.
If you use the template function that receive the unsigned int in a different c++ file, the compiler doesn't know which versions of the function to implement.
Simple solution: declare and define the template functions/classes/structs in the headers.
If I'm wrong... please prepare a minimal example to replicate the error.
In my application, I have a dll which exposes a function that takes two vectors:
static int myFunc( vector<double> vec1, vector<double> &vec2 );
When I changed this declaration to
static int myFunc( vector<double> &vec1, vector<double> &vec2 );
I get a linker error saying this:
error LNK2019: unresolved external symbol "__declspec(dllimport) public: static int __cdecl myFunctions::myFunc(class std::vector<double,class std::allocator<double> > &,class std::vector<double,class std::allocator<double> > &)" (__imp_?myFunc#myFunctions##SAHAAV?$vector#NV?$allocator#N#std###std##0#Z) referenced in function "public: void __thiscall MainWindow::modelMeanCurve(void)" (?modelMeanCurve#MainWindow##QAEXXZ)
Why is this behavior and how do I resolve this error so that I can pass the reference to the first argument also?
Thanks,Rakesh.
Well, it is not enough to change the declaration alone. You also have to change the definition of that function and recompile the DLL.
If you simply changed the declaration and left the definition unchanged, you essentially created a new declaration for a function that does not really exist. The DLL still contains the original function with original set of parameters, which is now completely unrelated to you new declaration. This is what the linker is telling you through the above error.
Thank you #Michael Burr, I was referring to a stale copy of the .lib file. I replaced this with the new version and everything built fine.
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 9 years ago.
This is the error I have been getting the whole time and I've been trying to figure out how to fix it but have failed. I am asking if anyone can point me to the right direction.
WorldServer fatal error LNK1120: 2 unresolved externals
WorldServer error LNK2019: unresolved external symbol "public: class CItemElem * __thiscall CLinkedItemMgr::GetLinkedItem(unsigned long)" (?GetLinkedItem#CLinkedItemMgr##QAEPAVCItemElem##K#Z) referenced in function "private: void __thiscall CDPSrvr::OnLinkedItem(class CAr &,unsigned long,unsigned long,unsigned char *,unsigned long)" (?OnLinkedItem#CDPSrvr##AAEXAAVCAr##KKPAEK#Z)
WorldServer error LNK2019: unresolved external symbol "public: int __thiscall CLinkedItemMgr::AddLinkedItem(class CItemElem *)" (?AddLinkedItem#CLinkedItemMgr##QAEHPAVCItemElem###Z) referenced in function "private: void __thiscall CDPSrvr::OnLinkedItem(class CAr &,unsigned long,unsigned long,unsigned char *,unsigned long)" (?OnLinkedItem#CDPSrvr##AAEXAAVCAr##KKPAEK#Z)
This is the .h
#ifndef __ITEM_LINK__H
#define __ITEM_LINK__H
class CLinkedItemMgr
{
private:
CLinkedItemMgr(){ m_dwLinkedItemCount = 0;};
~CLinkedItemMgr(){};
DWORD m_dwLinkedItemCount;
public:
map<DWORD,CItemElem*> m_mapLinkedItems;
static CLinkedItemMgr *GetInstance()
{
static CLinkedItemMgr instance;
return &instance;
}
int AddLinkedItem(CItemElem *pItem);
CItemElem *GetLinkedItem(DWORD dwIndex);
};
#endif
this is the .cpp
#include "stdafx.h"
#include "ItemLink.h"
int CLinkedItemMgr::AddLinkedItem(CItemElem *pItem)
{
if(!pItem)
return 0;
m_mapLinkedItems.insert(make_pair<DWORD,CItemElem*>(++m_dwLinkedItemCount,pItem));
return m_dwLinkedItemCount;
}
CItemElem *CLinkedItemMgr::GetLinkedItem(DWORD dwIndex)
{
map<DWORD,CItemElem*>::iterator it = m_mapLinkedItems.find(dwIndex);
if(it == m_mapLinkedItems.end())
return FALSE;
return it->second;
}
Your problem is in the cpp here.
#ifdef __ITEM_LINK
#include "ItemLink.h"
#ifdef __ITEM_LINK means "only process the code below if __ITEM_LINK is defined"
And in your case, it is not defined. It only gets defined when "ItemLink.h" is included, and "ItemLink.h" only gets included if it's already defined. You've prevented either from happening first.
Remove the #ifdef line.
It looks like a linking problem.
The compiler knows your class has a function called GetLinkedItem but can't find any definition of that function anywhere. Are you linking properly when compiling your executable?
I bet stopping the compiler before linking doesn't trigger any error.
(e.g. g++ -c ItemLink.cpp).
i'm going to ask the help of someone who's accustomed to visual studio to elaborate more :D
anyway, compiling requires three major steps:
1) applying preprocessor directives, parsing the source code, looking for syntax errors and the like
2) creating an object file from source code (something half-way between source code and executable)
3) linking all the object files making up your project in one executable
your compiling chain fails at the third step.
the compiler expects a certain function to be defined in some .cpp (that has become an object file at step 2 of compiling chain) but can't find it anywhere.
and it can't find it because of that #ifdef in the .cpp file, which tells the preprocessor NOT TO INCLUDE your definitions, since __ITEM_LINK is not defined
i see you changed the .cpp in your question by the way