I have the code presented later using Xerces-c, which can be built as a static or dynamic library. Failing to include of course results in a compiler error, however when I add #include <xercesc/util/PlatformUtils.hpp> visual studio 2012 gives me a linker errors saying:
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static void __cdecl xercesc_3_1::XMLPlatformUtils::Initialize(char const * const,char const * const,class xercesc_3_1::PanicHandler * const,class xercesc_3_1::MemoryManager * const)" (__imp_?Initialize#XMLPlatformUtils#xercesc_3_1##SAXQBD0QAVPanicHandler#2#QAVMemoryManager#2##Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static void __cdecl xercesc_3_1::XMLPlatformUtils::Terminate(void)" (__imp_?Terminate#XMLPlatformUtils#xercesc_3_1##SAXXZ) referenced in function __catch$_main$0
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static char const * const xercesc_3_1::XMLUni::fgXercescDefaultLocale" (__imp_?fgXercescDefaultLocale#XMLUni#xercesc_3_1##2QBDB)
Based on the dllimport part of the error it seems that it's failing to find a dll. This is confirmed by that when I build Xerces-c as a dynamic library and link to it the error goes away. However if I build Xerces-c as a static library and link to it the same error remains. So my question is why am I getting an error asking for a dll when I'm including and linking to a static library?
using namespace xercesc;
int main(int argc, char* argv[])
{
std::ifstream inputFile(argv[1]);
char c = inputFile.get();
while (inputFile.good()) {
std::cout << c;
c = inputFile.get();
}
try {
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch) {
// Do your failure processing here
return 1;
}
// Do your actual work with Xerces-C++ here.
//XercesDOMParser parser;
//parser.useScanner(XMLUni::fgDGXMLScanner);
XMLPlatformUtils::Terminate();
// Other terminations and cleanup.
return 0;
}
You need to compile your application with XERCES_STATIC_LIBRARY preprocessor macro to disable DLL import/export for Xerces library.
Also check that you link against static version of .lib files.
Related
I am getting an error in Visual Studio when compiling my program.
Error LNK2019 unresolved external symbol "public: __cdecl
Grid::Grid(void)" (??0Grid##QEAA#XZ) referenced in function
main Grid C:\Users\Ryan\Desktop\Dev\Grid\Grid\main.obj 1
Error LNK2019 unresolved external symbol "public: __thiscall
Grid::~Grid(void)" (??1Grid##QAE#XZ) referenced in function
_main Grid C:\Users\Ryan\Desktop\Dev\Grid\Grid\main.obj 1
This project works fine at my university but not on my own computer and I am not sure what is wrong.
My main.cpp:
#include <iostream>
#include "Grid.h"
using namespace std;
int main(int args, char **argv)
{
Grid grid;
// grid.LoadGrid("Grid1.txt");
// grid.SaveGrid("OutGrid.txt");
system("pause");
}
And my header file:
#pragma once
class Grid
{
public:
Grid();
~Grid();
void LoadGrid(const char filename[]);
void SaveGrid(const char filename[]);
private:
int m_grid[9][9];
};
Any help at all is appreciated, thanks.
Issue resolved from advise given on [error LNK2019: unresolved external symbol "public: __thiscall : constructor issue
"First in the library project do rightclick->properties, then under the tab General, Configuration Type should be Static library (.lib)."
Thanks everyone for your answers.
As per my understanding your grid class constructor and destractor implementation are missing. You should check your .cpp file, implemention like this
Grid(){}
~ Grid(){}
After removing the CRT from my DLL I have gotten these weird errors.
Here are they:
LNK2001 unresolved external symbol "void __cdecl std::_Xbad_alloc(void)" (?_Xbad_alloc#std##YAXXZ)
LNK2001 unresolved external symbol "void __cdecl std::_Xlength_error(char const *)" (?_Xlength_error#std##YAXPBD#Z)
LNK2001 unresolved external symbol "void __cdecl std::_Xout_of_range(char const *)" (?_Xout_of_range#std##YAXPBD#Z)
unresolved external symbol __dtest
unresolved external symbol __fdtest
unresolved external symbol __invalid_parameter)noinfo_noreturn
unresolved external symbol __stdio_common_vsnprintf_s
unresolved external symbol __stdio_common_vsprintf
unresolved external symbol __std_terminate
If I understand correctly the Xbad_alloc and Xlength_error are because of the new and delete operators? In that case I create my class instance like this:
class sc_Core
{
public:
static sc_Core *Instance(void);
func A();
public:
void *operator new(size_t si)
{
return HeapAlloc(GetProcessHeap(), NULL, si);
}
void operator delete(void *pv) throw()
{
HeapFree(GetProcessHeap(), NULL, pv);
}
private:
sc_Core(void) { }
~sc_Core(void) { }
sc_Core(const sc_Core&) { }
sc_Core(sc_Core&&) {}
sc_Core& operator=(const sc_Core&) {}
sc_Core& operator=(sc_Core&&) {}
static sc_Core *p_Instance;
};
// Global Scope
sc_Core *sc_Core::p_Instance = nullptr;
sc_Core *sc_Core::Instance(void)
{
if (p_Instance == nullptr)
p_Instance = new sc_Core();
return p_Instance;
}
If anyone knows how these occur or how I can fix them it would be very much appreciated!
There's nothing weird about those errors.
Compilers are allowed to assume that they can generate code that rely on their runtime libraries. If you're going omit the runtime library at the link step, then you'll have to provide definitions for the missing symbols in your own code.
Turning off certain compiler features may reduce the number of missing symbols. You could try, for example, turning off exception handling support to see if the internal exception classes are still expected. In debug builds, the compiler may expect even more support from the runtime that in release builds.
I have downloaded net-snmp from
http://softlayer-ams.dl.sourceforge.net/project/net-snmp/net-snmp%20binaries/5.7-binaries/net-snmp-5.7.0-1.x86.exe
and installed.
Now, I am trying to follow this tutorial to get stated (http://www.net-snmp.org/wiki/index.php/TUT:Simple_Application)
I am trying to use net-snmp in my C++ Qt5 applicaton with VC++ 2010 Compiler but I get the following error
snmptest.obj:-1: Fehler: LNK2019: unresolved external symbol __imp__generate_Ku referenced in function "public: void __thiscall SnmpTest::doSnmp(void)" (?doSnmp#SnmpTest##QAEXXZ)
snmptest.obj:-1: Fehler: LNK2019: unresolved external symbol __imp__snmp_sess_init referenced in function "public: void __thiscall SnmpTest::doSnmp(void)" (?doSnmp#SnmpTest##QAEXXZ)
snmptest.obj:-1: Fehler: LNK2019: unresolved external symbol __imp__init_snmp referenced in function "public: void __thiscall SnmpTest::doSnmp(void)" (?doSnmp#SnmpTest##QAEXXZ)
C:\build\debug\a.exe:-1: Fehler: LNK1120: 4 unresolved externals
snmptest.obj:-1: Fehler: LNK2001: unresolved external symbol __imp__usmHMACMD5AuthProtocol
I added this line to my *.pro file:
win32:INCLUDEPATH += "C:\snmp_5.7.0\include"
SnmpTest.h
#ifndef SNMPTEST_H
#define SNMPTEST_H
#include <QDebug>
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/library/transform_oids.h>
class SnmpTest
{
public:
SnmpTest();
void doSnmp();
};
#endif // SNMPTEST_H
SnmpTest.cpp
SnmpTest::SnmpTest()
{
}
void SnmpTest::doSnmp()
{
const char *our_v3_passphrase = "XXXXX";
struct snmp_session session, *ss;
struct snmp_pdu *pdu;
struct snmp_pdu *response;
oid anOID[MAX_OID_LEN];
size_t anOID_len = MAX_OID_LEN;
struct variable_list *vars;
int status;
/*
* Initialize the SNMP library
*/
init_snmp("snmpapp");
snmp_sess_init(&session);
session.peername = "xxxxx";
session.version=SNMP_VERSION_3;
/* set the SNMPv3 user name */
session.securityName = _strdup("YYYY");
session.securityNameLen = strlen(session.securityName);
/* set the security level to authenticated, but not encrypted */
session.securityLevel = SNMP_SEC_LEVEL_AUTHNOPRIV;
/* set the authentication method to MD5 */
session.securityAuthProto = usmHMACMD5AuthProtocol;
session.securityAuthProtoLen = sizeof(usmHMACMD5AuthProtocol)/sizeof(oid);
session.securityAuthKeyLen = USM_AUTH_KU_LEN;
/* set the authentication key to a MD5 hashed version of our
passphrase (which must be at least 8
characters long) */
if(generate_Ku(
session.securityAuthProto,
session.securityAuthProtoLen,
(u_char *) our_v3_passphrase, strlen(our_v3_passphrase),
session.securityAuthKey,
&session.securityAuthKeyLen) != SNMPERR_SUCCESS)
{
qDebug() << "Error generating Ku from authentication pass phrase.";
}
}
Thanks for the help!
Specifying the include path is not enough. You need to link against the library, naturally, otherwise all the symbols will be unresolved for the linker. Try
win32 {
INCLUDEPATH += "C:\snmp_5.7.0\include"
LIBS+= -L"C:\snmp_5.7.0\lib" -lnetsnmp
}
or something similar. You can even specify the absolute path to the library should it be located elsewhere than beside the application. Check how exactly the library is called.
I'm getting these error messages
2>main.obj : error LNK2019: unresolved external symbol "public: __thiscall CEngine::CEngine(void)" (??0CEngine##QAE#XZ) referenced in function _WinMain#16
2>main.obj : error LNK2019: unresolved external symbol "public: void __thiscall CEngine::SetWindowSize(int,int,char const *,int)" (?SetWindowSize#CEngine##QAEXHHPBDH#Z) referenced in function _WinMain#16
2>main.obj : error LNK2019: unresolved external symbol "public: void __thiscall CEngine::Begin(void)" (?Begin#CEngine##QAEXXZ) referenced in function _WinMain#16
2>main.obj : error LNK2019: unresolved external symbol "public: int __thiscall CEngine::GetDisplayWidth(void)" (?GetDisplayWidth#CEngine##QAEHXZ) referenced in function _WinMain#16
2>main.obj : error LNK2019: unresolved external symbol "public: int __thiscall CEngine::GetDisplayHeight(void)" (?GetDisplayHeight#CEngine##QAEHXZ) referenced in function _WinMain#16
2>C:\Users\ethan\Desktop\C++ Projects\delveenginetest\Debug\delveenginetest.exe : fatal error LNK1120: 5 unresolved externals
This is my solution:
Solution 'delveenginetest' (2 projects)
DelveEngine
Include
delve.h
Engine.h
SetupSDL.h
stdafx.h
Engine.cpp
Main.cpp
SetupSDL.cpp
This is the code for Engine.h
#pragma once
#include "SetupSDL.h"
class CEngine
{
public:
CEngine(void);
~CEngine(void);
void SetWindowSize(int winW, int winH, const char* GameName, int windowMode);
void Begin(void);
int GetDisplayWidth(void);
int GetDisplayHeight(void);
private:
int deskW;
int deskH;
bool playing;
CSetupSDL* sdl_setup;
};
Code for Engine.cpp
#include "Include/stdafx.h"
#include "Include/Engine.h"
CEngine::CEngine(void)
{
playing = true;
deskW = GetSystemMetrics(SM_CXSCREEN);
deskH = GetSystemMetrics(SM_CYSCREEN);
}
CEngine::~CEngine(void)
{
}
void CEngine::SetWindowSize(int winW, int winH, const char* GameName, int windowMode)
{
// set up SDL for use
sdl_setup = new CSetupSDL(winW, winH, GameName, windowMode);
}
void CEngine::Begin(void)
{
while (playing && sdl_setup->GetMainEvent()->type != SDL_QUIT)
{
sdl_setup->Begin();
sdl_setup->End();
}
playing = false;
}
int CEngine::GetDisplayWidth(void){ return deskW; }
int CEngine::GetDisplayHeight(void){ return deskH; }
The DelveEngine project builds successfully, whereas the delveenginetest project fails.
What's wrong? I've looked everywhere for a reason, can't find one that suits me.
Despite the fact you're not providing all the sufficient information for a correct diagnosis of your problems, I'll try to share what I could imagine that might be the reasons for the linker errors:
I suppose the project delveenginetest you mention is meant to set up unit tests for the classes from the DelveEngine project.
Since you have a Main.cpp in your DelveEngine project, I'd guess it's simply build as an executable (successfully).
Your delveenginetest needs to link to the classes provided from the DelveEngine project, but that's actually not possible, since the .exe from DelveEngine can't be used for linking, you'll need a library to import it to another executable (the unit testing framework).
I'd recommend to separate out your classes/source files from DelveEngine project to make up a static or shared library, that can be linked from an application and the test framework simultaneously from within a single VS solution:
Solution 'DelveEngine' (3 projects)
DelveEngineLib (project [.lib/.dll])
Include
delve.h
Engine.h
SetupSDL.h
Engine.cpp
SetupSDL.cpp
DelveEngine (project [.exe])
Main.cpp
delveenginetest (project [.exe])
Main.cpp (TestFramework main definition)
Since I'm not very versed with it I don't know actually, if VS 2013 supports to setup projects consuming virtual resources (think of links to sources in the actual build environment), but this could be an alternative how to setup application and unit tests without need of an extra library.
I have a visual c++ console project named "C_test".
Another project is called "dll_project" which is dll project.
in "C_test" project, I have set the location of additional include directory for "dll_project".
I have these simple codes.
in "C_test" project's main.cpp.
#include "SampleClass.h"
int main()
{
SampleClass *_parser = new SampleClass();
return 0;
}
And in "dll_project" SampleClass.h and SampleClass.cpp.
SampleClass.h
#pragma once
class SampleClass
{
public:
SampleClass(void);
~SampleClass(void);
};
SampleClass.cpp
#include "SampleClass.h"
SampleClass::SampleClass(void)
{
}
SampleClass::~SampleClass(void)
{
}
When I try to debug or build, I get this error.
error LNK2019: unresolved external symbol "public: __thiscall SampleClass::SampleClass(void)" (??0SampleClass##QAE#XZ) referenced in function _main C:\C_test\main.obj C_test
What have I done wrong?