• 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
  • 相关阅读:
    hibernate>悲观锁和乐观锁 小强斋
    hibernate>查询语言hql 小强斋
    hibernate>查询语言hql 小强斋
    hibernate>Collection映射 小强斋
    【java&&jni】jni入门篇
    【C++ Primer】第十三章 类继承
    【android&&jni&&NDk】详细介绍每一步,让你轻松掌握android JNI NDk
    【android】错误集锦及解决办法
    【Android】入门级连接网络示例: 网页浏览和播放网络MP3
    【python】入门第一篇
  • 原文地址:https://www.cnblogs.com/coding-my-life/p/12905729.html
Copyright © 2020-2023  润新知