error LNK2019: unresolved external symbol __imp__debugf referenced in function "int __cdecl fld_new - visual-c++

I am upgrading my project from VS 6 to VS 2010, while building in release mode, I am facing the below error.
1>Creating library .\Release\JfFrpF32.lib and object .\Release\JfFrpF32.exp>
1>FLD_.obj : error LNK2019: unresolved external symbol __imp__debugf referenced in function "int __cdecl fld_new(char *,unsigned char,unsigned char,short,char,char,unsigned char,short,char,double,double,short,char *,char,short,short)" (?fld_new##YAHPADEEFDDEFDNNF0DFF#Z)
1>Release/JfFrpF32.dll : fatal error LNK1120: 1 unresolved externals
1>
1>Build FAILED.
Please help me .. thanks in advance..

Common problems that cause LNK2019 include:
The declaration of the symbol contains a spelling mistake, such that,
it is not the same name as the definition of the symbol.
A function was used but the type or number of the parameters did not
match the function definition.
The calling convention (__cdecl, __stdcall, or __fastcall) differs on
the use of the function declaration and the function definition.
Symbol definitions are in a file that was compiled as a C program and
symbols are declared in a C++ file without an extern "C" modifier. In
that case, modify the declaration.
For More Information See Here

In my case, even though I used extern "C", I got the unresolved symbol error.
The hpp was
extern "C"
{
class A
{
public:
void hi();
};
A* a;
DECLDIR int Connect();
}//extern
and the cpp was
#include "DatabasePlugin.hpp"// Include our header, must come after #define DLL_EXPORT
extern "C" // Get rid of name mangling
{
DECLDIR int Connect()
{
a = new A();
a->hi();
return 0;
}//Connect
}//extern
The problem was that I had not created an implementation for the hi() function. Adding it solved the problem. Like this:
extern "C" // Get rid of name mangling
{
void A::hi() {}
DECLDIR int Connect()
{
a = new A();
a->hi();
return 0;
}//Connect
}//extern
Having to declare Hi() before Connect() may also be significant.

Related

LNK2019 unable to use GetStagedPackageOrigin()

I have been trying to use the GetStagedPackageOrigin() to get the origin of a specific application in my system.
But my program is not compiling because of an unresolved external error.
Error LNK2019 : unresolved external symbol __imp__GetStagedPackageOrigin#8 referenced in function "void __cdecl check(wchar_t const *)" (?check##YAXPB_W#Z)
Here is my code:
void check(__in PCWSTR fullName)
{
PackageOrigin origin;
LONG rc = GetStagedPackageOrigin(fullName, &origin);
if (rc == ERROR_SUCCESS)
{
static PCWSTR originstring[] = {L"Unknown",L"Unsigned",L"Inbox",L"Store",L"DeveloperUnsigned",L"DeveloperSigned",L"LineOfBusiness" };
PCWSTR str = originstring[origin];
wcout << str << endl;
}
}
Why does this error keep coming and is there any way to resolve that?
I used dumpbin command in the visual studio command prompt and that function was not being exported from kernel32.dll. The function was not present in the dll in the first place.
I think that is why the error occured.

Boost Serialization MSVC 2015 do not compile in DEBUG mode

By some reason MSVC DO NOT compile boost serialization example with the following code:
class MyName
{
public:
MyName(std::string _name, std::string _family_name)
:name{ _name }, family_name{ _family_name }
{ }
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{ ar & name; ar & family_name; } std::string name; std::string family_name;
};
int main()
{
// create and open a character archive for output
std::stringstream ofs;
// save data to archive
{
MyName my_name("MyName", "FamilyName");
boost::archive::text_oarchive oa(ofs);
// write class instance to archive
oa << my_name;
// archive and stream closed when destructors are called
}
// save data to archive
{
MyName my_name("afsf", "dgsass");
boost::archive::text_iarchive oa(ofs);
// write class instance to archive
oa >> my_name;
// archive and stream closed when destructors are called
}
return 0;
}
I get the follwing error:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "public: __thiscall boost::archive::archive_exception::archive_exception(enum boost::archive::archive_exception::exception_code,char const *,char const *)" (??0archive_exception#archive#boost##QAE#W4exception_code#012#PBD1#Z) referenced in function "protected: void __thiscall boost::archive::basic_text_iprimitive<class std::basic_istream<char,struct std::char_traits<char> > >::load<unsigned int>(unsigned int &)" (??$load#I#?$basic_text_iprimitive#V?$basic_istream#DU?$char_traits#D#std###std###archive#boost##IAEXAAI#Z) cpp11_cpp14_cpp17 D:\Projects_Programing\__Testing\cpp11_cpp14_cpp17\cpp11_cpp14_cpp17\cpp11_cpp14_cpp17.obj 1
But when I compiled it in release mode.
I have read that it could happen due to MSVC STRICT mode, but I have tried and it does not work neither.
Have anybody got such error ?
I have figured out the reason of this error.
It happens when I tried to compile with flag /Za (means zero extension from MSVC for C++).
When I removed this flag my code compiles succesfully.
#lakeweb Thank you for your help and support !!
Unfortunately I do not understand why some extensions from MSVC does allow to compile Boost, but without extentions it does not compile. It is very strange !!
Maybe it is either the bug on Boost side or on MSVC side.
Any assumption ?

Adding an stdcall on a callback function gives an argument mismatch [GNU]

I'm trying to add an stdcall calling convention to my GNU compiled DLL.
Here is my code:
typedef void (__stdcall * CTMCashAcceptCallback) (
const struct CTMEventInfo,
const struct CTMAcceptEvent );
It's been called by this function:
LIBCTMCLIENT_FUNC void ctm_add_cash_accept_event_handler(CTMCashAcceptCallback);
where:
#define LIBCTMCLIENT_FUNC LIBCTMCLIENT_C_LINKAGE __declspec(dllexport) __stdcall
The problem is that it gives me this note:
note: expected 'CTMCashAcceptCallback' but argument is of type 'void (*)(const struct CTMEventInfo, const struct CTMAcceptEvent)'
When I remove the __stdcall or replace it with __cdecl instead, it does not give that information. Is it not possible to use stdcall when compiling through GNU or maybe I'm not doing it right?
The user code needs to explicitly tell the compiler its own function (the one you did not show) to be __stdcall, if that is what the DLL expects. Something like
__stdcall myCTMCashAccept (
const struct CTMEventInfo,
const struct CTMAcceptEvent)
{
//...
}
// ...
ctm_add_cash_accept_event_handler(myCTMCashAccept);
should work.
Remember that the #define LIBCTMCLIENT_FUNC you showed is about the convention for user code calling the DLL; while the callback, with its typedef, is about the other way: it is the DLL calling the user code. They do not have to use the same conventions (although it is clearer when they do); so if your user code is likely to use __cdecl code (perhaps because it already exists), then you should remove the __stdcall from the typedef (and it should work, too).

Unresolved externals in Visual C++

I'm trying to compile a solution in MS Visual Studio C++ 2012.
My code uses marshallsoft AES library.
I added these for library and include paths:
C:\aes4c\APPS to Configuration properties->VC++ Directories->Include Directories
C:\aes4c\DLLS to Configuration properties->VC++ Directories->Library Directories
When I compile the individual .cpp file it compiles without problem but when I build the solution I get:
------ Build started: Project: cryptest2, Configuration: Debug Win32 ------
cryptest2.obj : error LNK2019: unresolved external symbol __imp__aesAttach#8 referenced in function "int __cdecl EncryptFileW(char *,char *)" (?EncryptFileW##YAHPAD0#Z)
cryptest2.obj : error LNK2019: unresolved external symbol __imp__aesEncryptFile#12 referenced in function "int __cdecl EncryptFileW(char *,char *)" (?EncryptFileW##YAHPAD0#Z)
cryptest2.obj : error LNK2019: unresolved external symbol __imp__aesInitAES#20 referenced in function "int __cdecl EncryptFileW(char *,char *)" (?EncryptFileW##YAHPAD0#Z)
C:\Users\ariyan\documents\visual studio 2012\Projects\cryptest2\Debug\cryptest2.exe : fatal error LNK1120: 3 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
What is the problem?
How Can I fix it?
My code is:
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include "aes.h"
int EncryptFile(char *KeyBuffer, char *FileName);
int _tmain(int argc, _TCHAR* argv[])
{
EncryptFile("1234567890abcdef","c:\test.txt");
return 0;
}
int EncryptFile(char *KeyBuffer, char *FileName)
{int Code;
// attach DLL
Code = aesAttach(0, 0);
if(Code<0)
{printf("ERROR %d: Cannot attach\n", Code);
return FALSE;
}
printf("Will encrypt file in CBC mode\n");
Code = aesInitAES((char *)KeyBuffer, NULL, AES_ECB_MODE, AES_ENCRYPT, NULL);
if(Code<0)
{printf("aesInitAES fails\n");
return FALSE;
}
printf("Encrypt file...\n");
Code = aesEncryptFile(NULL, KeyBuffer, FileName);
if(Code<0)
{printf("aesEncryptFile fails\n");
return FALSE;
}
printf("%d bytes encrypted\n", Code);
return Code;
}
It's not enough to add to library path - that just tells the linker where to look for a library if and when it decides to link with it. But you have to tell the linker to look for it in the first place. For that, mention the LIB file name in
Project > Properties > Linker > Input > Additional Dependencies

VS2012 WindowsApplicationForDrivers8.0 can not include trd lib

#pragma comment(lib, "libmcrypt.lib")
When the platform is Visual Studio 2012 (v110), it is OK. But, when platform is WindowsApplicationForDrivers8.0, it reports error LNK2019
When I include OpenSSL in my project, I'm getting the same error.
From the MSDN.
The following sample generates LNK2019:
// LNK2019.cpp
// LNK2019 expected
extern char B[100]; // B is not in avilable to the linker
int main() {
B[0] = ' ';
}
LNK2019 can also occur when you declare but do not define a static data member. The following sample generates LNK2019:
// LNK2019b.cpp
// LNK2019 expected
struct C {
static int s;
};
// Uncomment the following line to resolve.
// int C::s;
int main() {
C c;
C::s = 1;
}
Please go to the MSDN link for full explanation
http://msdn.microsoft.com/en-us/library/799kze2z(v=vs.80).aspx

Resources