Alexander Kolbeko
Alexander Kolbeko

Reputation: 63

clangd false positive '<quadmath.h>' not found

I have a C++ project, using CMake, GCC and Arch Linux. I am using GCC and the project is compiling correctly (both in IDE and command line), but I have these errors in Qt Creator:

heat_transfer_explicit_scheme.cpp:1:10: In included file: 'quadmath.h' file not found
float128.hpp:54:10: error occurred here
...
heat_transfer_explicit_scheme.cpp:1:10: In included file: no member named 'value' in 'boost::multiprecision::number_category<backends::float128_backend>'
number.hpp:131:399: error occurred here

But this header is present in /usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/include, and clicking on #include <quadmath.h> will open it in the IDE.

As I understand, /usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/include is not the default sysroot, and clangd does not know about this location, so I tried to add CMAKE_SYSROOT /usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/include like on this forum thread: Qt Forum — Qt Creator - clang code model doesn't find types, even though code compiles. But it doesn't make <quadmath.h> location accessible to clangd.

Moreover, after setting CMAKE_SYSROOT in CMakeLists.txt pointing to their location, other project dependencies (like boost) can't be found by find_package.

Also, I tried to add /usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/include to PATH of current terminal session and open Qt Creator from this env, but it seems to have no effect.

Qt Creator version 14.0.1 based on Qt 6.7.2 (GCC 14.2.1 20240805, x86_64).

Clangd not indexing these files with clang++ compiler because he have his own realizations and not needed gcc intrinsic headers codechecker. But I am using g++ in project and want clangd to handle the indexing.

Upvotes: 0

Views: 313

Answers (2)

Mizux
Mizux

Reputation: 9309

This is a GCC header only, If I were you, I would try to use some preprocessor to disable the #include <quadmath.h> on Clang, and fix the code accordingly (and send PR to upstream project?).

#if defined(__GNUC__)
#include <quadmath.h>
#endif

Ref: https://github.com/gcc-mirror/gcc/blob/master/libquadmath/quadmath.h

Upvotes: 0

HighCommander4
HighCommander4

Reputation: 52847

/usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/include is gcc 14's "built-in include directory". Clangd deliberately ignores this, even if you point it at the gcc 14 installation using --query-driver, because many files in this directory contain gcc-only intrinsics that the clang frontend cannot parse.

(If you're curious, the reasons for clangd ignoring this directory are discussed in more detail at https://github.com/clangd/clangd/issues/1695)

You can override this behaviour by adding this directory to the include path in the compile commands used by clangd. A simple way to do this is to create a .clangd file in the project root containing:

CompileFlags:
  Add: -I/usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/include

Upvotes: 0

Related Questions