3

I'm using QtCreator 4.11.2 , installed via MSYS2, with ClangCodeModel enabled.

Here is my program (this is the result of creating a New Non-QT Plain C Application):

#include <stdio.h>
#include <stdbool.h>

_Bool a;
bool b;

int main()
{
    printf("Hello World!\n");
    return 0;
}

The .pro file is unchanged from the default:

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += \
    main.c

The annotation compiler highlights an error saying stdbool.h cannot be found. screenshot of problem

But it does not give an error for _Bool a; , so it is clearly running in C99 mode but has some problem with include paths. The "Follow symbol under cursor" option works, opening stdbool.h.

My question is: How do I configure include paths for the annotation compiler or otherwise fix this problem?

I have been unable to figure out how to set options for the annotation compiler or even which compiler binary it is using . Under Tools > Options > C++ > Code Model > Diagnostic Configuration it lets me add -W flags but does not let me add -I flags, a red message pops up saying the option is invalid.

Under Tools > Options > C++ Code Model inspector, there are no diagnostic messages, and the Code Model Inspecting Log shows stdbool.h being correctly found and parsed, as msys64/mingw64/lib/gcc/x86_64-w64-mingw32/9.3.0/include/stdbool.h.

If I disable the ClangCodeModel plugin then there are no errors , but I would like to use the clang version if it can be made to work as in general it has good diagnostics.

The result of clang --version in a shell prompt is:

clang version 10.0.0 (https://github.com/msys2/MINGW-packages.git 3f880aaba91a3d9cdfb222dc270274731a2119a9)
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: F:\Prog\msys64\mingw64\bin

and if I compile this same source code using clang outside of QtCreator, it compiles and runs correctly with no diagnostics. So the annotation compiler is clearly not the same as the commandline clang?

The Kit I have selected in QtCreator is the autodetected Desktop Qt MinGW-w64 64bit (MSYS2)

The exact same symptoms occur if I make a Plain C++ project and try to include stdbool.h (which is required to exist by the C++ Standard, although deprecated), although interestingly it does accept <cstdbool>.


I have found a workaround of sorts: including in the .pro file the line:

INCLUDEPATH += F:/Prog/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/9.3.0/include/

causes the annotation compiler to work correctly, however this is undesirable as I'd have to keep changing it whenever I switch Kits because it also passes this to the actual build compiler, not just the annotation compiler.

M.M
  • 138,810
  • 21
  • 208
  • 365
  • I don't have experience with QtCreator, but you could use Process Monitor to see if which Clang is invoked and with what arguments. – David Macek May 07 '20 at 19:24
  • I'm having the exact same problem with `bool` and `stdbool.h` not found in an imported CMake project. Additionally, I'm also seeing the same thing with `NULL` and `stddef.h`. – smf68 May 10 '20 at 17:49
  • Does [disabling the clang code model](https://stackoverflow.com/a/69137528/11942268) work for you? – stackprotector Dec 02 '21 at 07:54

1 Answers1

-1

Create file stdbool.h in C:\msys64\mingw64\x86_64-w64-mingw32\include and copy paste this code:

/* Copyright (C) 1998-2017 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
<http://www.gnu.org/licenses/>.  */
/*
 * ISO C Standard:  7.16  Boolean type and values  <stdbool.h>
 */
#ifndef _STDBOOL_H
#define _STDBOOL_H
#ifndef __cplusplus
#define bool        _Bool
#define true        1
#define false        0
#else /* __cplusplus */
/* Supporting _Bool in C++ is a GCC extension.  */
#define _Bool        bool
#if __cplusplus < 201103L
/* Defining these macros in C++98 is a GCC extension.  */
#define bool        bool
#define false        false
#define true        true
#endif
#endif /* __cplusplus */
/* Signal that all the definitions are present.  */
#define __bool_true_false_are_defined        1
#endif        /* stdbool.h */

Note

Creating a manual file stdbool.h works for me but its a sketchy and a temporary solution for now. Don't use this if you feel its too sketcy. I would rather use a alternative solution than this hack if it exist. This solution might not be good but it still works for me.

Jossi
  • 1,020
  • 1
  • 17
  • 28
  • Looks sketchy. The file should already exist as `/mingw64/include/c++/11.2.0/tr1/stdbool.h`, there is no need to roll your own. – HolyBlackCat Nov 06 '21 at 19:10
  • It's not my own I just copied it from web because it did not exist in `C:\msys64\mingw64\x86_64-w64-mingw32\include`. This is the *Clang Code Mode* path MSYS2 qtcreator uses. qtcreator can compile just fine without `stdbool.h` because it uses another path that contain `stdbool.h` – Jossi Nov 06 '21 at 19:44
  • You are right I also think its sketchy. I would appreciate alternative solution. – Jossi Dec 09 '21 at 12:40