zoukankan      html  css  js  c++  java
  • Qt Creator 修复The code model could not parse an include file

    在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
  • 相关阅读:
    Lesson_strange_words6
    Lesson_strange_words3
    Lesson_strange_words4
    Lesson_strange_words1
    Lesson_strange_words2
    关于我们子页面
    关于我们页面
    走进龙门石窟子页面
    3.用户登陆注册
    2.项目初始化
  • 原文地址:https://www.cnblogs.com/coding-my-life/p/12905729.html
Copyright © 2011-2022 走看看