Qt:Windows函数是无法解析的外部符号 [英] Qt: windows functions are unresolved external symbols

查看:568
本文介绍了Qt:Windows函数是无法解析的外部符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用QtCreator中的te WinAPI编译一个类似helloworld的简单非Qt C ++应用程序。代码如下:

I'm trying to compile a simple helloworld-like non-Qt C++ application using te WinAPI in QtCreator. Here's the code:

#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;
}

看起来很简单,但是当我尝试构建它时,编译失败并显示以下内容:

Looks very simple, but when I've tried to build it, the compilation fails with:

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



<中未解析的外部符号__imp__SetWindowTextW @ 8

我开始寻求,发现了,但对我没有任何帮助,因为当我写这篇文章时:

I started to seek, and I found this, but it wasn't helping me at all, because when I had written this:

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 中,这些符号仍然无法显示留恋。在每次更改之后,我对 .pro 文件内容运行了qmake。那么,有什么想法吗?

in my .pro, these "symbols" still stand unresolved. I ran qmake after each change to the .pro-file contents. So, any ideas?

推荐答案

-L 设置搜索路径DLL,但实际上并没有链接任何东西。实际的链接是通过 -l <​​/ code>完成的。不必为系统库设置搜索路径,但是您需要针对user32进行链接:

-L sets the search paths for DLLs, but it doesn't actually link anything. The actual linking is done via -l. Setting the search path for system libraries shouldn't be necessary, but you'll need to link against user32:

win32:LIBS += -luser32

这篇关于Qt:Windows函数是无法解析的外部符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆