在Ubuntu20.04上使用Qt Creator(4.11.0)时,程序运行起来没问题,但编辑器会提示头文件找不到,界面上提示各种错误。我以为是我的工程太过复杂,部分头文件路径设置错误,但是查了半天,没有发现问题,google查了半天,也没找到解决办法。于是创建了一个很简单的工程来测试,ro工程文件:
QT -= gui

CONFIG += c++11
CONFIG -= app_bundle

SOURCES += \
        main.cpp

main.cpp文件:

#include <iostream>

int main(int argc, char *argv[])
{
    std::cout << "hello world" << std::endl;
    return 0;
}

这么简单的文件,编译、运行都没有问题,偏偏提示找不到头文件

Warning:The code model could not parse an included file,which might lead to incorrent code completion and hightlighting,for example.

wchar.h:35:10: fatal error: 'stddef.h' file not found
main.cpp:1:1: note: in file included from /home/xzc/Documents/code/qt_test/main.cpp:1:
main.cpp:1:10: note: in file included from /home/xzc/Documents/code/qt_test/main.cpp:1:
iostream:39:10: note: in file included from /usr/include/c++/9/iostream:39:
ostream:38:10: note: in file included from /usr/include/c++/9/ostream:38:
ios:38:10: note: in file included from /usr/include/c++/9/ios:38:
iosfwd:40:10: note: in file included from /usr/include/c++/9/iosfwd:40:
postypes.h:40:10: note: in file included from /usr/include/c++/9/bits/postypes.h:40:
cwchar:44:10: note: in file included from /usr/include/c++/9/cwchar:44:

而且,wchar.h这个文件明明在 /usr/lib/gcc/x86_64-linux-gnu/9/include 里,没有理由找不到,而且,我手动用G++、clang++编译程序,都是没有问题的,说明它们都认这个路径,就是Qt Creator不认。更气人的是,我手动include这个文件,它是找得到的,而且C++ Code Model Inspector也是认这个路径的

这个提示是ClangCodeModel的,网上给出的解决办法就是到 帮助->插件 那里把这个插件关掉,但是关掉之后,一些clang相关的功能也被关掉了,这不可接受啊。后来发现这些认不到的头文件都是glibc的,大概是Qt Creator调用clang的时候,include参数没设置好(或者是我没设置好?),导致clang不认gcc的默认路径,于是强制在pro工程文件里指定glibc的include路径,问题解决:
INCLUDEPATH += /usr/lib/gcc/x86_64-linux-gnu/9/include

 

PS: 2021-05-03

根据https://bugreports.qt.io/browse/QTCREATORBUG-19667?attachmentOrder=desc,sudo apt install libclang-common-8-dev安装libclang-common-8-dev即可解决。

posted on 2020-05-17 16:39  coding my life  阅读(3018)  评论(0编辑  收藏  举报