2014-10-22 139 views
-1

我有功能findId(常量QString的&名)抛出我coompilation过程中出现错误:错误LNK2019:解析外部符号:: FindWindow函数()函数

error LNK2019: unresolved external symbol [email protected] referenced in function "private: unsigned int__thiscall MainClass::findId(class QString const &)"([email protected]@@[email protected]@@Z)

mainclass.cpp:

WId MainClass::findId(const QString& name) 
{ 
    return (WId) ::FindWindow(NULL, (TCHAR*)name.utf16()); 
} 

我不知道问题出在哪里,因为我之前在其他项目中使用过这个代码,并且在那里工作。也许我错过了什么。

+0

如果重新标记您的问题,您将得到更好的答案。什么语言?什么OS?什么技术?什么编译器? 'lnk2019'不是一个有用的标签。 – 2014-10-22 08:16:31

+2

FindWindow需要Windows.h和User32.lib – 2014-10-22 08:26:18

+2

链接器无法找到':: FindWindow(...)'的定义。你确定有吗? – CinCout 2014-10-22 08:26:22

回答

2

解决方案资源管理器中,您有几个选项卡。其中一个标签名为“物业经理”,打开此选项卡。在这个标签中你会找到你的项目及其配置。它实际上包含的内容是属性表,其中之一是“核心Windows库”。如果你右键单击这个,然后转到链接器 - >输入,你会发现Windows库user32.lib等等。这些属性由你的项目通过%(AdditionalDependencies)继承。

其中一件事情在当前项目中没有正确设置。

+0

一个'编译指示评论'更适合这种情况IMO。 – cybermonkey 2014-10-22 08:58:12

+0

错误我删除%(AdditionalDependencies),同时添加我的库。现在它工作,谢谢 – 2014-10-22 09:14:59

2

链接器正在尝试编译您的应用程序,但无法完成,因为它不知道FindWindow所指的是什么,因为您尚未使用函数所需的user32库。 以下代码将修复它。

 #prama comment(lib, "user32.lib")  
     WId MainClass::findId(const QString& name) 
     { 
      return (WId) ::FindWindow(NULL, (TCHAR*)name.utf16()); 
     } 

这是从您提供的代码工作,可能有更多的代码。 如果是这样,只需#pragma comment(lib, "user32.lib")之后你的#include块,但在你的任何功能或namespace之前。

MSDN KB article on this issue下面的示例将保证LNK2019错误:

// LNK2019.cpp 
// LNK2019 expected 
extern char B[100]; // B is not available to the linker 
int main() { 
    B[0] = ' '; 
} 
相关问题