加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

Windows – 链接到User32.dll时链接错误2001

发布时间:2020-12-14 02:48:56 所属栏目:Windows 来源:网络整理
导读:我正在尝试链接一个目标文件,该文件使用winuser.h中声明的两个方法并在User32.dll中定义:GetMonitorInfo和WindowFromMonitor.源编译到一个目标文件就好了,但是当我尝试链接时,我得到以下错误输出: D3dCtx.obj : error LNK2001: unresolved external symbol
我正在尝试链接一个目标文件,该文件使用winuser.h中声明的两个方法并在User32.dll中定义:GetMonitorInfo和WindowFromMonitor.源编译到一个目标文件就好了,但是当我尝试链接时,我得到以下错误输出:

D3dCtx.obj : error LNK2001: unresolved external symbol xGetMonitorInfo
D3dCtx.obj : error LNK2001: unresolved external symbol xMonitorFromWindow

问题是,我不称之为“xGetMonitorInfo”或“xMonitorFromWindow”.在所有源文件上运行grep表明只调用了“GetMonitorInfo”和“WindowFromMonitor”.我正确地包括windows.h,其中包括winuser.h.我也正在链接器选项中正确设置我的LIBPATH,这由详细的链接输出确认.

我的详细链接输出中也出现以下内容:

Found __imp_GetMonitorInfoA
    Referenced in nafxcw.lib(afxribboncategory.obj)
    Referenced in nafxcw.lib(afxtooltipctrl.obj)
    Referenced in nafxcw.lib(afxribbonkeytip.obj)
    Referenced in nafxcw.lib(afxfullscreenimpl.obj)
    Referenced in nafxcw.lib(afxframeimpl.obj)
    Referenced in nafxcw.lib(afxglobalutils.obj)
    Referenced in nafxcw.lib(afxdropdowntoolbar.obj)
    Referenced in nafxcw.lib(wincore.obj)
    Referenced in nafxcw.lib(afxglobals.obj)
    Referenced in nafxcw.lib(afxpopupmenu.obj)
    Referenced in nafxcw.lib(afxpropertygridtooltipctrl.obj)
    Loaded User32.lib(USER32.dll)
Found __imp_MonitorFromWindow
    Referenced in nafxcw.lib(wincore.obj)
    Loaded User32.lib(USER32.dll)

此外,GetMonitorInfo在winuser.h中定义为:

WINUSERAPI
BOOL
WINAPI
GetMonitorInfoA(
    __in HMONITOR hMonitor,__inout LPMONITORINFO lpmi);
WINUSERAPI
BOOL
WINAPI
GetMonitorInfoW(
    __in HMONITOR hMonitor,__inout LPMONITORINFO lpmi);
#ifdef UNICODE
#define GetMonitorInfo  GetMonitorInfoW
#else
#define GetMonitorInfo  GetMonitorInfoA
#endif // !UNICODE

当我将对“GetMonitorInfo”的所有引用更改为“GetMonitorInfoA”时,我只会得到

D3dCtx.obj : error LNK2001: unresolved external symbol xMonitorFromWindow

作为我的链接器错误输出.不幸的是,MonitorFromWindow似乎没有多个版本可用.

我应该注意到我使用的是64位版本的库,链接和cl.

这里发生了什么,我怎样才能成功链接我的程序?

解决方法

我不知道你是否能够找到解决方案但是我遇到了同样的问题,而且发生这种情况的原因是我有一个名为multimon.h的文件.

看起来在64位编译的情况下,由于宏定义,这些函数的定义来自两个来源,并且可能来自multimon.h的一个是重写并且是错误的.

我只是通过评论这个包括它来解决它,它已经开始链接很好.

//#include <multimon.h>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读