C++ 使用 GetFileVersionInfoSize() 时出现 LNK2019 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7028304/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error LNK2019 when using GetFileVersionInfoSize()
提问by Neophile
I just included this bit in my already working code, but I am getting an LNK2019 error. I'll paste the error after pasting the code.
我只是在我已经工作的代码中包含了这一点,但我收到了 LNK2019 错误。粘贴代码后,我将粘贴错误。
The Class CAboutDlg has:
类 CAAboutDlg 具有:
public:
CStatic m_VersionInfoCtrl;
virtual BOOL OnInitDialog();
};
The Function itself:
函数本身:
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CString inFileName = AfxGetApp()->m_pszExeName;
inFileName += ".exe";
void * theVersionInfo;
void * theFixedInfo;
unsigned long aVersionInfoSize = GetFileVersionInfoSize ( inFileName , &aVersionInfoSize);
CString returnString;
if (aVersionInfoSize)
{
theVersionInfo = new char [aVersionInfoSize];
GetFileVersionInfo ( inFileName, 0 , aVersionInfoSize, theVersionInfo) ;
unsigned int aSize = 0;
VerQueryValue( theVersionInfo , "\" , &theFixedInfo , &aSize);
if (theFixedInfo)
{
VS_FIXEDFILEINFO * aInfo = (VS_FIXEDFILEINFO *) theFixedInfo;
DWORD dwMajorVersionMsb = HIWORD( aInfo->dwFileVersionMS );
DWORD dwMajorVersionLsb = LOWORD( aInfo->dwFileVersionMS );
DWORD dwMinorVersionMsb = HIWORD( aInfo->dwFileVersionLS );
DWORD dwMinorVersionLsb = LOWORD( aInfo->dwFileVersionLS );
returnString.Format("Version %d . %d . %d. %d",dwMajorVersionMsb,dwMajorVersionLsb,dwMinorVersionMsb,dwMinorVersionLsb);
//memcpy(sVer,returnString.GetBuffer(),returnString.GetLength()+1);
}
delete theVersionInfo;
}
m_VersionInfoCtrl.SetWindowText(returnString);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
....
....
Its giving me the following three errors:
它给了我以下三个错误:
1.RangemasterGenerator error LNK2019: unresolved external symbol _VerQueryValueA@16 referenced in function "public: virtual int __thiscall CAboutDlg::OnInitDialog(void)" (?OnInitDialog@CAboutDlg@@UAEHXZ)
2.RangemasterGenerator error LNK2019: unresolved external symbol _GetFileVersionInfoA@16 referenced in function "public: virtual int __thiscall CAboutDlg::OnInitDialog(void)" (?OnInitDialog@CAboutDlg@@UAEHXZ)
3.RangemasterGenerator error LNK2019: unresolved external symbol _GetFileVersionInfoSizeA@8 referenced in function "public: virtual int __thiscall CAboutDlg::OnInitDialog(void)" (?OnInitDialog@CAboutDlg@@UAEHXZ)
... I am not able to understand what the problem is. Can anyone help please. Thanks.
......我无法理解问题是什么。任何人都可以请帮忙。谢谢。
回答by Timo Geusch
You need to link against the library that contains the two functions VerQueryValue
and GetFileVersionInfo
- the linker doesn't know by default where to find them.
您需要链接包含这两个函数的库,VerQueryValue
并且GetFileVersionInfo
链接器默认不知道在哪里可以找到它们。
A quick search for the two functions on MSDN suggests that they're both in the system library version.dll and the library you want to link against is version.lib. Just add that to the library list in the linker properties.
在 MSDN 上快速搜索这两个函数表明它们都在系统库 version.dll 中,您要链接的库是 version.lib。只需将其添加到链接器属性中的库列表中即可。
回答by Alok Save
The functions GetFileVersionInfoand GetFileVersionInfoSizeare defined in Version.dll
and Version.lib
so make sure, you are liking to the appropriate libraries.
函数GetFileVersionInfo和GetFileVersionInfoSize在中定义Version.dll
,Version.lib
因此请确保您喜欢适当的库。
回答by Mahendra
I am also getting same error, while upgrading the VS6.0 application to VS2012 platform.
在将 VS6.0 应用程序升级到 VS2012 平台时,我也遇到了同样的错误。
a.error LNK2019: unresolved external symbol _GetFileVersionInfoSizeA@8 referenced in function _main
一种。错误 LNK2019:未解析的外部符号 _GetFileVersionInfoSizeA@8 在函数 _main 中引用
b.error LNK2019: unresolved external symbol _GetFileVersionInfoA@16 referenced in function _main
湾 错误 LNK2019:未解析的外部符号 _GetFileVersionInfoA@16 在函数 _main 中引用
c.error LNK2019: unresolved external symbol _VerQueryValueA@16 referenced in function _main
C。错误 LNK2019:未解析的外部符号 _VerQueryValueA@16 在函数 _main 中引用
Resolution:
解析度:
I found that it is due to missing reference to library "Version.lib".
我发现这是由于缺少对库“Version.lib”的引用。
a.For VS6.0 add it to Project Setting->Link->library modules
一种。对于 VS6.0 将其添加到ProjectSetting- >Link->library modules
b.For VS2012 add to Project Properties->Linker->Input->Additional Dependanciesand add full lib path to Include directory.
湾 对于 VS2012,添加到Project Properties->Linker->Input->Additional Dependancies并将完整的 lib 路径添加到 Include 目录。
回答by AirCal86
For VS2012 or 2013 add to Project Properties->Linker->Input->Additional Dependencies -> Add Version.lib
对于 VS2012 或 2013 添加到 Project Properties->Linker->Input->Additional Dependencies -> Add Version.lib