use*_*158 -1 c++ visual-studio-2010 visual-c++-2010
我试图用VS2010 C++编译器编译一个14岁的C++程序(不要问为什么:().我收到以下错误
错误10错误LNK2019:未解析的外部符号"public:__thiscall CConfiguration :: CConfiguration(void)"(?? 0CConfiguration @@ QAE @ XZ)在函数"public:__thiscall CWhoisService :: CWhoisService(void)"中引用(?? 0CWhoisService @ @ QAE @ XZ)
我有一个带有头CWhoisService.h的cpp文件CWhoisService.cpp
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
};
Run Code Online (Sandbox Code Playgroud)
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);
Run Code Online (Sandbox Code Playgroud)
cpp文件中引用并在CWhoisService.h之前包含的ConfigurationLib.h文件如下:
#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
Run Code Online (Sandbox Code Playgroud)
上次大约10年前汇编的一切都很好.但现在它似乎没有找到ConfigurationLib.h文件.我确保它是项目的一部分.如果我从cpp文件的开头删除它我得到错误:缺少';' 在标识符"m_Configuration"之前,显然可以看到它.但它似乎无法解决这个问题.
任何帮助将不胜感激,我已经在这个网站和其他许多人花了3天,但没有进展.
i have spend last 3 days on this site and many others but no progress
理解Visual C++链接器产生的错误总是很好的.然后下次你看到这样的错误时,不应该花3天时间搞清楚.我知道这条消息一开始看起来很乱,但如果你知道要找什么,那真的不是.
诀窍是选择有意义的错误部分,并跳过名称错误(看起来像链接器的gobbledy-gook正在咒骂你).有时名称修改是有用的,但对于您的错误,它并不重要.
让我们来看看错误:
unresolved external symbol "public: __thiscall CConfiguration::CConfiguration(void)"
上面的行表示链接器无法找到的函数实现.功能是CConfiguration::CConfiguration(void).换句话说,CConfiguration链接器无法找到0参数构造函数.
错误消息的下一部分指出:
referenced in function "public: __thiscall CWhoisService::CWhoisService(void)"
这是试图调用CConfiguration构造函数的函数.它是CWhoisService::CWhoisService(void)构造函数.你在这里看到它:
class CWhoisService
{
//...
protected:
CConfiguration m_Configuration;
};
Run Code Online (Sandbox Code Playgroud)
您有一个CConfiguration(m_Configuration)成员,因此在实例化a时CWhoIsService,您还要实例化一个CConfiguration对象.
底线是链接器无法找到CConfiguration不带参数的构造函数的实现.
不管你
CConfiguration构造函数实现的项目中,或者CConfiguration构造函数是在库中没有指定库项目中的链接,或CConfiguration没有参数的构造函数,或我的猜测不仅仅是1.上面的项目.
此外,这与头文件无关.头文件允许编译模块而不会出错.它并不能保证连接器将成功链接.
例如,您可以拥有一个包含对不存在的函数的调用的模块,但该模块将成功编译.但是,在链接时,如果调用的函数实际上不存在,那么您将得到错误(正如您现在看到的那样).
| 归档时间: |
|
| 查看次数: |
172 次 |
| 最近记录: |