编译错误:unresolved external symbol

南墙太近 2014-10-19 12:47:02
调用了MSDN上在API,GetFirmwareEnvironmentVariable这个函数,编译报错如下:
error LNK2001: unresolved external symbol "unsigned long __cdecl GetFirmwareEnvironmentVariable(wchar_t const *,wchar_t const *,void *,unsigned long)" (?GetFirmwareEnvironmentVariable@@YAKPB_W0PAXK@Z)

#define UEFI_RUNTIME_VARIABLE_NAME L"UEFIDisplayInfo"
#define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID L"{9042a9de-23dc-4a38-96fb-7aded080516a}"
#define DEBUG_GOT_UEFI_VARIBLE_SUCCESS L"GOT THE UEFI VARIBLE SUCCESS"
#define DEBUG_GOT_UEFI_VARIBLE_FAIL L"GOT THE UEFI VARIBLE FAIL"
……
//不太懂C和C++,请问下面调用在方法在上面都要声明一下吗?这个函数是MSDN里面的函数。
DWORD WINAPI GetFirmwareEnvironmentVariable(
LPCTSTR lpName,
LPCTSTR lpGuid,
PVOID pBuffer,
DWORD nSize);

……

void testGetUEFIVariable() {
……
UCHAR Buffer[32];
DWORD dwRet = 0;

dwRet = GetFirmwareEnvironmentVariable(
UEFI_RUNTIME_VARIABLE_NAME,
EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID,
Buffer,
sizeof(Buffer));

if (dwRet) {
OutputDebugString(DEBUG_GOT_UEFI_VARIBLE_SUCCESS);
} else {
OutputDebugString(DEBUG_GOT_UEFI_VARIBLE_FAIL);
}
……

……
...全文
538 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
南墙太近 2014-10-20
  • 打赏
  • 举报
回复
引用 10 楼 zhao4zhong1 的回复:
#define _WIN32_WINNT 0x0501
这个我查了一下,我的系统是Windows8的,这个也要这么定义吗?
南墙太近 2014-10-20
  • 打赏
  • 举报
回复
引用 9 楼 zhao4zhong1 的回复:
如果是我的电脑,附加库目录可能是下列之一(有显摆之嫌啊!): C:\Microsoft SDK\lib\Kernel32.Lib C:\60G\Microsoft SDK\lib\IA64\Kernel32.Lib C:\60G\Microsoft SDK\lib\prerelease\Kernel32.Lib C:\60G\Microsoft SDK\lib\prerelease\IA64\Kernel32.Lib C:\masm32\lib\kernel32.lib C:\MSVC20\LIB\KERNEL32.LIB C:\Program Files\Borland\CBuilder6\Lib\Psdk\kernel32.lib C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib\Kernel32.Lib C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib\AMD64\Kernel32.Lib C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib\IA64\Kernel32.Lib C:\Program Files\Microsoft SDKs\Windows\v5.0\Lib\IA64\Kernel32.Lib C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib\Kernel32.Lib C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib\IA64\Kernel32.Lib C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib\x64\Kernel32.Lib C:\Program Files\Microsoft Visual Studio\VC98\Lib\KERNEL32.LIB C:\Program Files\Microsoft Visual Studio 8\VC\lib\kernel32.lib C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Lib\Kernel32.Lib C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Lib\AMD64\Kernel32.Lib C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Lib\IA64\Kernel32.Lib C:\Win2000DDK\lib\win_me\kernel32.lib C:\Win2000DDK\libchk\i386\kernel32.lib C:\Win2000DDK\libfre\i386\kernel32.lib C:\windows_2000_source_code\win2k\private\inet\mshtml\tools\alpha\lib\kernel32.lib C:\windows_2000_source_code\win2k\private\inet\mshtml\tools\ppc\lib\kernel32.lib C:\windows_2000_source_code\win2k\private\inet\mshtml\tools\x86\lib\kernel32.lib
我的是WindowsPhone项目,谢谢大神指点,我再试一下~
赵4老师 2014-10-20
  • 打赏
  • 举报
回复
#define _WIN32_WINNT 0x0501
赵4老师 2014-10-20
  • 打赏
  • 举报
回复
如果是我的电脑,附加库目录可能是下列之一(有显摆之嫌啊!): C:\Microsoft SDK\lib\Kernel32.Lib C:\60G\Microsoft SDK\lib\IA64\Kernel32.Lib C:\60G\Microsoft SDK\lib\prerelease\Kernel32.Lib C:\60G\Microsoft SDK\lib\prerelease\IA64\Kernel32.Lib C:\masm32\lib\kernel32.lib C:\MSVC20\LIB\KERNEL32.LIB C:\Program Files\Borland\CBuilder6\Lib\Psdk\kernel32.lib C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib\Kernel32.Lib C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib\AMD64\Kernel32.Lib C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib\IA64\Kernel32.Lib C:\Program Files\Microsoft SDKs\Windows\v5.0\Lib\IA64\Kernel32.Lib C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib\Kernel32.Lib C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib\IA64\Kernel32.Lib C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib\x64\Kernel32.Lib C:\Program Files\Microsoft Visual Studio\VC98\Lib\KERNEL32.LIB C:\Program Files\Microsoft Visual Studio 8\VC\lib\kernel32.lib C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Lib\Kernel32.Lib C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Lib\AMD64\Kernel32.Lib C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Lib\IA64\Kernel32.Lib C:\Win2000DDK\lib\win_me\kernel32.lib C:\Win2000DDK\libchk\i386\kernel32.lib C:\Win2000DDK\libfre\i386\kernel32.lib C:\windows_2000_source_code\win2k\private\inet\mshtml\tools\alpha\lib\kernel32.lib C:\windows_2000_source_code\win2k\private\inet\mshtml\tools\ppc\lib\kernel32.lib C:\windows_2000_source_code\win2k\private\inet\mshtml\tools\x86\lib\kernel32.lib
南墙太近 2014-10-20
  • 打赏
  • 举报
回复
引用 5 楼 zhao4zhong1 的回复:
VC6: 工程、设置、C/C++、分类:Preprocessor、附加包含路径:填写附加头文件所在目录 逗号间隔多项 工程、设置、Link、分类:Input、附加库路径:填写附加依赖库所在目录 分号间隔多项 工程、设置、Link、分类:Input、对象/库模块:填写附加依赖库的名字.lib 空格间隔多项 VS20xx: 项目、属性、C/C++、附加包含目录:填写附加头文件所在目录 分号间隔多项 项目、属性、链接器、常规、附加库目录:填写附加依赖库所在目录 分号间隔多项 项目、属性、链接器、输入、附加依赖项:填写附加依赖库的名字.lib 空格或分号间隔多项
请问引用库是Kernel32.lib的话,还需要再引用吗?如果引用的话,附加库的目录应该是哪里?是Windows \System32这个路径吗?
赵4老师 2014-10-20
  • 打赏
  • 举报
回复
还可能需要 将include和library目录的顺序略作调整。 #define _WIN32_WINNT 0x0501
南墙太近 2014-10-20
  • 打赏
  • 举报
回复
引用 4 楼 zhao4zhong1 的回复:
GetFirmwareEnvironmentVariable Function Retrieves the value of the specified firmware environment variable. DWORD WINAPI GetFirmwareEnvironmentVariable( __in LPCTSTR lpName, __in LPCTSTR lpGuid, __out PVOID pBuffer, __in DWORD nSize ); Parameters lpName The name of the firmware environment variable. lpGuid The GUID namespace of the firmware environment variable. This parameter is ignored if the system does not support GUID-based namespaces. pBuffer A pointer to a buffer that receives the value of the specified firmware environment variable. nSize The size of the pBuffer buffer, in bytes. Return Value If the function succeeds, the return value is the number of bytes stored in the pBuffer buffer. If the function fails, the return value is zero. To get extended error information, call GetLastError. Remarks The exact set of firmware environment variables is determined by the firmware. The location of these environment variables is also specified by the firmware. For example, on an EFI-based system, NVRAM contains firmware environment variables that specify system boot settings. For information about specific variables used, see the EFI specification. If you are creating a backup application, you can use this function to save all the boot settings for the system so they can be restored using the SetFirmwareEnvironmentVariable function if needed. Requirements Client Requires Windows Vista or Windows XP SP1. Server Requires Windows Server 2008 or Windows Server 2003. Header Declared in Winbase.h; include Windows.h. Library Use Kernel32.lib. DLL Requires Kernel32.dll. Unicode Implemented as GetFirmwareEnvironmentVariableW (Unicode) and GetFirmwareEnvironmentVariableA (ANSI). See Also SetFirmwareEnvironmentVariable System Information Functions Send comments about this topic to Microsoft Build date: 8/15/2007
操作系统是Windows8, 工具是VS2013 请问是否满足条件?
赵4老师 2014-10-20
  • 打赏
  • 举报
回复
VC6: 工程、设置、C/C++、分类:Preprocessor、附加包含路径:填写附加头文件所在目录 逗号间隔多项 工程、设置、Link、分类:Input、附加库路径:填写附加依赖库所在目录 分号间隔多项 工程、设置、Link、分类:Input、对象/库模块:填写附加依赖库的名字.lib 空格间隔多项 VS20xx: 项目、属性、C/C++、附加包含目录:填写附加头文件所在目录 分号间隔多项 项目、属性、链接器、常规、附加库目录:填写附加依赖库所在目录 分号间隔多项 项目、属性、链接器、输入、附加依赖项:填写附加依赖库的名字.lib 空格或分号间隔多项
赵4老师 2014-10-20
  • 打赏
  • 举报
回复
GetFirmwareEnvironmentVariable Function Retrieves the value of the specified firmware environment variable. DWORD WINAPI GetFirmwareEnvironmentVariable( __in LPCTSTR lpName, __in LPCTSTR lpGuid, __out PVOID pBuffer, __in DWORD nSize ); Parameters lpName The name of the firmware environment variable. lpGuid The GUID namespace of the firmware environment variable. This parameter is ignored if the system does not support GUID-based namespaces. pBuffer A pointer to a buffer that receives the value of the specified firmware environment variable. nSize The size of the pBuffer buffer, in bytes. Return Value If the function succeeds, the return value is the number of bytes stored in the pBuffer buffer. If the function fails, the return value is zero. To get extended error information, call GetLastError. Remarks The exact set of firmware environment variables is determined by the firmware. The location of these environment variables is also specified by the firmware. For example, on an EFI-based system, NVRAM contains firmware environment variables that specify system boot settings. For information about specific variables used, see the EFI specification. If you are creating a backup application, you can use this function to save all the boot settings for the system so they can be restored using the SetFirmwareEnvironmentVariable function if needed. Requirements Client Requires Windows Vista or Windows XP SP1. Server Requires Windows Server 2008 or Windows Server 2003. Header Declared in Winbase.h; include Windows.h. Library Use Kernel32.lib. DLL Requires Kernel32.dll. Unicode Implemented as GetFirmwareEnvironmentVariableW (Unicode) and GetFirmwareEnvironmentVariableA (ANSI). See Also SetFirmwareEnvironmentVariable System Information Functions Send comments about this topic to Microsoft Build date: 8/15/2007
南墙太近 2014-10-19
  • 打赏
  • 举报
回复
引用 1 楼 lovesmiles 的回复:
MSDN 上面是这样说的: Header Winbase.h (include Windows.h) Library Kernel32.lib DLL Kernel32.dll 你有没有包括正确的头文件和附加库了?
附加库也已经包含了,还是报错。
南墙太近 2014-10-19
  • 打赏
  • 举报
回复
引用 1 楼 lovesmiles 的回复:
MSDN 上面是这样说的: Header Winbase.h (include Windows.h) Library Kernel32.lib DLL Kernel32.dll 你有没有包括正确的头文件和附加库了?
头文件有包含,请问附加库要怎么包含呢?
勤奋的小游侠 2014-10-19
  • 打赏
  • 举报
回复
MSDN 上面是这样说的: Header Winbase.h (include Windows.h) Library Kernel32.lib DLL Kernel32.dll 你有没有包括正确的头文件和附加库了?

65,179

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧