Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-31029

Bogus warnings/errors in Qt Creator from clangd

    XMLWordPrintable

Details

    Description

      Qt Creator doesn't play nice using clangd and a Yocto SDK, so we instruct developers to disable it. It's possible to make this work anyway, but it's ugly. Ultimately there are two problems we need to solve here:

      1. Qt Creator doesn't use compile_commands generated by CMake - it generates its own, and it does so poorly. This is likely because there are often issues with clangd when you build using gcc because there are unexpected command line arguments, and because qmake doesn't natively support compile_commands , so this has historically been necessary.
      2. We need to pass extra arguments to clangd to tell it that it's safe to run the compiler out of our toolchain (which is a non-standard location for GCC); and Qt Creator doesn't provide a way to pass arguments to clangd.

      So - the workaround is to create a shim script that invokes clangd for us, but modifies the arguments so that it's happy. Additionally, it's necessary to create a clangd config file that defines some compiler intrinsics that GCC uses but clang doesn't, resulting in "undefined" variables way down in the guts of the C++ standard library.

      Without this workaround, after wevfinish configuring a kit in Qt Creator, you'll be met with a view like this - "warnings" all over:
      Unfortunately, this is caused by Qt Creator not using the real compile_commands.json file that is generated by CMake.

       
      Qt Creator does not support passing extra command line arguments to clangd. The --query-driver​ option is the most important one, because it allows clangd​ to run GCC out of our Yocto SDK to inspect machine type for the target machine (and if you're using multiple SDKs, you need to pass this multiple times) - additionally, you cannot specify it in the Config file, for security reasons. I personally prefer a couple other command line arguments  -clang-tidy​ and --header-insertion=iwyu​. If the Qt Creator config supported a generic "add command line arguments for clangd" sort of option, that covers our uses; but these last two options could potentially be checkbox or dropdown items in the Qt Creator config; however, since the query-driver​ option is a path and might be included multiple times, it probably needs to be a text input.
       
      Qt Creator creates a compile_commands.json​ file in the .qtc_clangd​ folder in the build directory. As noted in those docs, I suspect this is largely related to the fact that qmake​ can't generate this file, but having Clangd work for QMake projects is valuable - but the file that Qt Creator generates is not quite correct. This could be entirely due to us configuring our kits wrong - but when using our Yocto SDK, that file does not quite match the one that CMake generates, which works correctly. I think this is primarily caused by the fact that the way a Yocto SDK works is by setting a bunch of common environment variables like CXX​. When you use the SDK, make​ or cmake​ incorporates those, and the Yocto-Qt layers account for it with the qmake​ profile files that get added - but when we use the SDK in Qt Creator, it means we have a kit where most of the details are defined in the Environment Variables​ options, not in the kit itself, and I think these details aren't taken into account when Qt Creator creates the compile_commands​ file.
      Specifically there are a couple pretty significant items Qt Creator got wrong: *
      The version from Qt Creator includes -m32​ instead of -m64


      • The version from Qt Creator uses Include paths that aren't in the SDK - under /home/ads/Qt

      • The version from Qt Creator does not include the --sysroot​ argument. This is somewhat accounted for by the -isystem​ options directing into the SDK, but it doesn't handle all cases; for example, if we put something in {{/usr/local/include }}within the SDK

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            kandeler Christian Kandeler
            pendletonic Corey Pendleton
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes