获取LNK2001但Intellisense可以找到功能

Getting LNK2001 yet Intellisense Can Find Function

我在 VS2015 中构建项目时遇到以下 link 错误:

LNK2001 unresolved external symbol __imp__PathCombineW@12

PathCombineW 函数来自 shlwapi.h,我已将其包含在我的 header 中。我觉得很困惑的部分是 Intellisense 很好地解析了这个函数,我可以 "peek definition" 函数,它让我直接进入 shlwapi.h.

中的声明

如果我尝试使用 pathcch.h 中的任何函数,我会遇到完全相同的问题。我最初使用此 API,因为它似乎是较新的首选路径操作 API。但是,我得到了与 API 完全相同的 LNK2001。

我不知道它是否与我包含的其他 headers 有关。它们如下所列:

// daqServiceTray.cpp 
#include "stdafx.h"
#include "daqServiceTray.h"    
#include <Shlwapi.h>
#include <Shellapi.h>
#include <Strsafe.h>


//stdafx.h
#pragma once
#include "targetver.h"
#define WIN32_LEAN_AND_MEAN
#ifndef _UNICODE
#define _UNICODE
#endif
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>


//targetver.h
#pragma once
#define WINVER 0x0601
#define _WIN32_WINNT 0x0601
#include <SDKDDKVer.h>


//dayServiceTray.h
#pragma once
#include "resource.h"

Resource.h 是我的 UI 资源文件的 header。我正在将它们构建到 win32 GUI 应用程序中。我正在开发 Windows 7.

通读错误帮助,我觉得我使用来自两个不同平台版本的代码造成了一些冲突,但我很难弄清楚可能是什么冲突。在我尝试进行一些路径操作并添加 pathcch.h 或 shlwapi.h.

之前,应用程序正在构建并且 运行 OK

为什么 intellisense 可以通过 linker 对我大吼大叫的未解决的外部函数找到函数?找不到函数定义的库吗?我的包含顺序有问题吗?

我的核心问题有两个:

intellisense 如何找到函数但 linker 找不到?

如果问题是找不到函数的定义,我如何知道为我的目标平台编写应用程序需要包含哪些库(windows 7)?我在 MSDN 上获取此信息时遇到了很多麻烦。是否有某种高级教程或页面可以解释不同平台构建规范的细微差别?

How can IntelliSense find the function but the linker cannot?

linker 正在查找 .lib 文件,IntelliSense 正在使用 header。要生成一个 executable(编译 + link)你需要两者。

If the issue is that the definition of the function cannot be found, how can I learn which libraries need to be included for writing applications for my target platform (windows 7)?

PathCombine 的文档在底部有一个很好的 table 说明了函数定义在哪个 header 中,以及 link er需要 link 功能。

对于 PathCombine,table 看起来像这样:

+----------------------------------------------------------------------------------------+
| Minimum supported client  |  Windows 2000 Professional, Windows XP [desktop apps only] |
+----------------------------------------------------------------------------------------+
| Minimum supported server  |  Windows 2000 Server [desktop apps only]                   |
+----------------------------------------------------------------------------------------+
| Header                    |  Shlwapi.h                                                 |
+----------------------------------------------------------------------------------------+
| Library                   |  Shlwapi.lib                                               |
+----------------------------------------------------------------------------------------+
| DLL                       |  Shlwapi.dll (version 4.71 or later)                       |
+----------------------------------------------------------------------------------------+
| Unicode and ANSI names    |  PathCombineW (Unicode) and PathCombineA (ANSI)            |
+----------------------------------------------------------------------------------------+

阅读此图表告诉我们,要获得此功能,我们需要使用

#include <Shlwapi.h>

并将 Shlwapi.lib 添加到 link 用户的图书馆列表中。它还告诉我们,如果我们要动态调用该函数,我们可以调用LoadLibrary并将Shlwapi.dll传递给它,然后使用GetProcAddress找到PathCombineAPathCombineW 函数。