This one is driving me nuts. I've tried everything I can think of. Here are the relevant parts of the DirectInput code.
BOOL CALLBACK EnumDevicesCallback(const DIDEVICEINSTANCE* DeviceInfo, VOID* Context);
if(DirectInput8Interface == DI_OK)
{
DirectInput8InterfacePointer->EnumDevices(
DI8DEVCLASS_GAMECTRL,
(LPDIENUMDEVICESCALLBACKA) EnumDevicesCallback,
NULL,
DIEDFL_ATTACHEDONLY);
}
When I try to compile, I get the error:
unresolved external symbol "int __stdcall EnumDevicesCallback(struct
DIDEVICEINSTANCEA const *,void *)"
(?EnumDevicesCallback##YGHPBUDIDEVICEINSTANCEA##PAX#Z) referenced in
function _WinMain#16.
As you can see, the external symbol the compiler can't find is related to the DIDEVICEINSTANCE parameter of the EnumDevicesCallback function. That shouldn't be, because I've included dinput.h and linked to dinput8.lib and dxguid.lib. I even tried defining DIDEVICEINSTANCE in my own code and got a message that it conflicted with a previous definition.
What could that error message mean?
That is not how callbacks work.
EnumDevicsCallback is not a function that exists. You're supposed to write your own function that EnumDevices will call for each device. Your function doesn't have to be called EnumDevicesCallback - that's an example.
For example, if you just wanted to print the name of each device, you might write
BOOL CALLBACK PrintDevicesCallback(const DIDEVICEINSTANCE* DeviceInfo, VOID* Context)
{
_tprintf("%s %s\n", DeviceInfo->tszProductName, DeviceInfo->tszProductName);
return DIENUM_CONTINUE;
}
and then pass PrintDevicesCallback to EnumDevices.
I dare say, the culprit is BOOL CALLBACK EnumDevicesCallback(const DIDEVICEINSTANCE* DeviceInfo, VOID* Context); - the function is likely a C-function, but you declare it in your .cpp file as C++-function.
Instead of doing that, include a proper .h file with the declaration, which is likely to have correct extern specified.
Related
I am willing to make a 2D game with SDL and I am following a Shaun Mitchell's book. But I faced serious difficulties with this user-defined type conversion error when trying to compile my project...
Also, I am unfamiliar with this topic. I've watched some tutorials and searched the web for a solution.
Do I need to add
operator std::string&() const { return ???;}
to the tinyxmlstr.h in TiXmlString class? If so, how to implement it? What should I return?
The Errors
If I don't define the STL (which I use) in tinyxml.h, the compiler then returns a linkage error.
Error 19 error LNK2019: unresolved external symbol "public: virtual __cdecl TiXmlNode::~TiXmlNode(void)" (??1TiXmlNode##UEAA#XZ) referenced in function "public: virtual __cdecl TiXmlDocument::~TiXmlDocument(void)" (??1TiXmlDocument##UEAA#XZ)
Without STL
StateParser class and implementation is the same as the one in the book.
Finally, if I have a mistake somewhere, how to debug it properly and where to look for it? Thank you, in advance!
The error is clear: non conversion available from const TiXmlString to const std::string &.
According to this page, if I'm not wrong, there isn't even a direct conversion from TiXmlString to a std::string
I suppose you can write a method like this (exactly like the value() that return a const char *)
std::string valueStr () cont
{ return value.c_str(); }
but in this way you return a copy of value (so return a const std::string, instead a plain std::string, is useless), not a reference. I don't know if this it's OK for you.
I've looked at a ton of examples and I don't know what I'm doing wrong. I can't pass a vector as a parameter or the compiler says unresolved externals.
Here's an example that doesn't work for me:
In the .h:
#include <vector>
void VectorTest(std::vector<std::string> & vect);
In the .cpp:
void VectorTest(std::vector<std::string> & vect)
{
}
Also in the .cpp, in a method where I'm trying to call it:
std::vector<std::string> test;
VectorTest(test);
When I compile I get the error:
error LNK1120: 1 unresolved externals
If I comment out
VectorTest(test);
It builds. I'm still learning C++ so it's probably something obvious. I'm using Visual Studio Express 2013 if that matters.
On a Yahoo! Answers someone posted this example and it does not work for me, same error:
void myfunc( std::vector<int>& vec )
{
}
std::vector<int> vec;
myfunc( vec );
Here's the error (trying to use the myfunc shown above):
error LNK2019: unresolved external symbol "public: void __thiscall trackManager::myfunc(class std::vector<int,class std::allocator<int> > &)" (?myfunc#trackManager##QAEXAAV?$vector#HV?$allocator#H#std###std###Z) referenced in function "public: __thiscall trackManager::trackManager(void)" (??0trackManager##QAE#XZ)
It looks like you declared VectorTest() as a trackManager member function in the header but then defined it as a free function in the cpp. This results in two unrelated functions with the same name. If you try to call VectorTest() without qualifications from inside a trackManager member function, the resolver will (sensibly) prefer the version that is also a trackManager member over the free function. But since that one doesn't have a definition, the linker can't figure out what to do with it and you get an error.
To fix this, either move the declaration out of the body of trackManager (if you want it to be a free function), or write the definition as void trackManager::VectorTest(...) (if you want it to be a member).
You're most likely missing the include file for string. Try to add the following line at the top of the .h file:
#include <string>
I am trying to compile a 14 year old C++ program with VS2010 C++ compiler (dont ask why :( ). I am getting the following error
Error 10 error LNK2019: unresolved external symbol "public: __thiscall CConfiguration::CConfiguration(void)" (??0CConfiguration##QAE#XZ) referenced in function
"public: __thiscall CWhoisService::CWhoisService(void)" (??0CWhoisService##QAE#XZ)
I have a cpp file CWhoisService.cpp with a header CWhoisService.h
CWhoisService.h:
class CWhoisService
{
public:
HRESULT Initialize(const char * szServiceName, REFCLSID pMetricsCLSID);
CWhoisService();
~CWhoisService();
HRESULT CheckService();
protected:
CConfiguration m_Configuration;
protected:
bool m_bStartedEvenLog;
bool m_bStartedConfiguration;
private:
//Don't want standard constructor to be called
};
CWhoisService.cpp
#include "ConfigurationLib.h"
#include "CWhoisService.h"
CWhoisService::CWhoisService():
m_bStartedEvenLog(false),
m_bStartedConfiguration(false)
{
}
HRESULT CWhoisService::Initialize(const char * szServiceName, REFCLSID pMetricsCLSID)
{
HRESULT hr = S_OK;
//Initialize the configuration library
hr = m_Configuration.Initialize(VERSION_COMPANY,VERSION_SYSTEM);
the ConfigurationLib.h file referenced in the cpp file and included before CWhoisService.h is as follows:
#ifndef _CONFIGURATION_MODULE
#define _CONFIGURATION_MODULE
class CConfigurationBase
{
public:
CConfigurationBase() : m_bInitialized(false) {};
virtual ~CConfigurationBase() {};
virtual HRESULT Initialize(LPCTSTR szCompanyName, LPCTSTR szSystemName, LPCTSTR szGlobalMachineName = NULL) = 0;
virtual bool IsInitialized() { return m_bInitialized;};
protected:
bool m_bInitialized; // True if the object has been initialized
};
class CConfiguration : public CConfigurationBase
{
public:
CConfiguration();
virtual ~CConfiguration();
// Initialized some values for the class. Must be called first!
virtual HRESULT Initialize(LPCTSTR szCompanyName, LPCTSTR szSystemName, LPCTSTR szGlobalMachineName = NULL);
protected:
// This is the function that actually goes about getting values from the registry
// The other Get functions all call this one
virtual HRESULT GetValue(HKEY hkeyBase, LPCTSTR szSectionName, LPCTSTR szValueName, CString * csValue, DWORD * pdwValue, DWORD dwType);
}; // CConfiguration
#endif // _CONFIGURATION_MODULE
everything was fine last time it compiled around 10 years ago. but now it does not seem to find the ConfigurationLib.h file. i made sure it as part of the project. if i removed it from the start of the cpp file I get the error: missing ';' before identifier 'm_Configuration' so ti obviously see it. yet it does not appear to be able to resolve the class.
Any assistance would be appreciated, i have spend last 3 days on this site and many others but no progress.
i have spend last 3 days on this site and many others but no progress
It is always good to understand the errors that are produced by the linker for Visual C++. Then next time you see such an error, it shouldn't take 3 days to figure out. I know the message looks garbled at first, but it really isn't if you know what to look for.
The trick is to choose the parts of the error that makes sense, and skip over the name-mangling (the gobbledy-gook that looks like the linker is swearing at you). Sometimes the name-mangling is useful, but for your error, it isn't important.
Let's go through the error:
unresolved external symbol "public: __thiscall CConfiguration::CConfiguration(void)"
The line above indicates the function implementation that cannot be found by the linker. The function is CConfiguration::CConfiguration(void). In other words, the 0-argument constructor for CConfiguration cannot be located by the linker.
Next part of the error message states:
referenced in function "public: __thiscall CWhoisService::CWhoisService(void)"
This is the function that is attempting to call the CConfiguration constructor. It is the CWhoisService::CWhoisService(void) constructor. You see it here:
class CWhoisService
{
//...
protected:
CConfiguration m_Configuration;
};
You have a member that is a CConfiguration (m_Configuration), so when you instantiate a CWhoIsService, you are also instantiating a CConfiguration object.
The bottom line is that the linker cannot find the implementation to the CConfiguration constructor that takes no arguments.
Either you
did not add the source module to your project that contains the implementation of the CConfiguration constructor to the project, or
The CConfiguration constructor is in a library and you didn't specify the library to link to in your project, or
You just plain old didn't code a CConfiguration constructor that has no arguments, or
some other unknown issue that causes the linker to miss the code that contains the implementation of the constructor.
My guess is more than likely item 1. above.
Also, this has nothing to do with header files. The header file allows a module to be compiled without error. It does not guarantee that the linker will link successfully.
For example, you can have a module that contains calls to functions that do not exist, but the module will compile successfully. However, at link time, if the function called doesn't actually exist, then you will get the error (as you're seeing now).
At least in the code snippets you showed there is no the constructor definition. It is only declared
class CConfiguration : public CConfigurationBase
{
public:
CConfiguration();
//...
I've spent the last 2 days searching for and implementing the answers from similar questions into my code with little success. I have an API that is an external .dll (windows) and I have the header file included into my .cpp file to reference the API.
However I have this issue that no matter what I do, I always get an unresolved external symbol that references this line in my .h file. Yes, I have used Google and modified the answers I found into my code, with no success.
Foo.h
Class Foo {
public:
static Foo* Interface_Get(char* dllfilename);
Foo.cpp
// I declare this just underneath the #include "Foo.h" header
Foo *foo = 0;
Inside my main function I declare it as this (along with some other functions that are fine).
//This has already been created and both Header and .dll are in the same directory.
Foo::Interface_Get("bar.dll");
And I get this error
error LNK2019: unresolved external symbol
"public: static class Foo * __cdecl Foo::Interface_Get(char *)"
I've tried everything I know (This is my first .dll creation experience) I have a feeling I am missing something painfully obvious, but for the life of me I cannot see it.
Entire Foo.cpp
#include "Foo.h"
Foo* Foo::Interface_Get(char* dllfilename); //May not be redeclared outside class error
Foo* foo = 0;
bool Frame()
{
if (foo->Key_Down(DIK_ESCAPE))
return false;
return true;
}
INT WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, INT)
{
foo->Interface_Get("bar.dll");
foo->System_SetState(grSTATE_FRAME, Frame);
foo->System_SetState(grSTATE_WINDOWED, true);
foo->System_SetState(grSTATE_KEYBOARD, true);
foo->System_Initiate();
foo->System_Start();
foo->System_Shutdown();
foo->Inferface_Release();
return 0;
}
This question explains common problems, and in your case it's (probably) a combination of:
(possibly) forgetting to implement the function
forgetting __declspec(dllexport)
forgetting to link against the library
You need to provide function definition for Interface_Get(char* dllfilename); if you haven't done that.
This only redeclares function again, you need to provide function like below format with {}
Foo* Foo::Interface_Get(char* dllfilename); //May not be redeclared outside class error
Foo.cpp
Foo* Foo::Interface_Get(char* dllfilename)
{
//....
return new Foo();
}
i have a class
class ICIecHdlcSetup
{
//some thing
};
to create a global access object i do this:
//in obj.cpp:
ICIecHdlcSetup obj_ICIecHdlcSetup(0x00,0x00,0x16,0x00,0x00,0xFF);
//in obj.hpp:
extern ICIecHdlcSetup obj_ICIecHdlcSetup;
now i have a template class:
template <class TValue>
class ICData
{
//some thing
};
but the same way would not work
//in obj.cpp:
ICData <uint8_t> temperture(7,64,41,0,0,255) ;
//in obj.hpp:
extern ICData <uint8_t> temperture ;
and make this error:
Error 10 error LNK2019: unresolved external symbol "public: void __thiscall ICData<unsigned char>::set_value(unsigned char)" (?set_value#?$ICData#E##QAEXE#Z) referenced in function "void __cdecl object_instantiation(void)" (?object_instantiation##YAXXZ) E:\sv_repos\Test\Test\VS2010\Test\Test\Objects.obj Test
thanks in advance.
The error given most likely means the function referenced simply doesn't exist, in general or in the current compilation unit.
Check to make sure it has been defined in the class body (in the header in the templated case) or is being imported properly (if coming from an external source, such as DLL or library; a common issue but unlikely with templates), including the library being linked against.
The form of your extern global variable appears to be correct, and that does work with templates generally speaking. The error seems specific to your templated class, but there is not information on whether that function actually exists in your posted code.