我正在尝试使用QtCreator中的te WinAPI编译一个类似于helloworld的简单非Qt C ++应用程序。这是代码:
#include <windows.h>
int main()
{
HWND cons = GetConsoleWindow();
SetWindowText(cons, L"I am the console window");
MessageBox(cons, L"Hello world!", L"I am the MessageBox", MB_OK | MB_ICONERROR);
return 0;
}
看起来很简单,但是当我尝试构建它时,编译失败并显示:
main.obj:-1: error: LNK2019: unresolved external symbol __imp__MessageBoxW@16 referenced in function _main
main.obj:-1: error: LNK2019: unresolved external symbol __imp__SetWindowTextW@8 referenced in function _main
我开始寻找,发现了这个东西,但是对我没有任何帮助,因为当我写这篇文章时:
LIBS += -L"C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\Lib"
甚至这样:
LIBS += -L"C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\Lib\\shell32.lib"
在我的文章中.pro
,这些“符号”仍未解决。我跑后qmake的每一个变化的.pro
-file内容。那么,有什么想法吗?
-L
设置DLL的搜索路径,但实际上并没有链接任何内容。实际的链接是通过进行的-l
。不必为系统库设置搜索路径,但是您需要针对user32进行链接:
win32:LIBS += -luser32
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句