3

I am trying to run clang-tidy in my project for a submodule, but it throws errors for the standard libraries, like 'string' file not found or the same for 'cmath'. Development is under Windows with Qt Creator and MinGW.

This is my Cmake file

option(RUN_CLANG_TIDY "Run clang-tidy with the compiler." ON)
if(RUN_CLANG_TIDY)
  if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
    message(FATAL_ERROR "CMake_RUN_CLANG_TIDY requires an out-of-source build!")
  endif()

file(GLOB CLION_PATH
    "C:/Program Files/JetBrains/CLion*/bin/clang/win"
    )
find_program(CLANG_TIDY_EXE NAMES clang-tidy
    HINTS
    "C:/Program Files/LLVM/bin"
    "C:/Qt/Tools/QtCreator/bin/clang/bin"
    "${CLION_PATH}"
    )
if(NOT CLANG_TIDY_EXE)
  message(WARNING "CMake_RUN_CLANG_TIDY is ON but clang-tidy is not found!")
  set(CMAKE_CXX_CLANG_TIDY "" CACHE STRING "" FORCE)
else()
    set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}")
    message("-- Clang-tidy found: ${DO_CLANG_TIDY}")
  endif()
endif()

...

add_library(...)
if(DO_CLANG_TIDY)
  set_target_properties(${PROJECT_NAME} PROPERTIES
    CXX_CLANG_TIDY "${DO_CLANG_TIDY}"
    )
endif()
target_include_directories(...)

I already tried some stuff and checked everything under the clang-tidy tag here in stackoverflow.

What I tried:

1) Setting the Cmake C++ include path by

set(CPLUS_INCLUDE_PATH C:/Qt/Tools/mingw730_64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++)

2) Generating the compile_commands.json with

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
...
set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" "-p C:/Users/User04/Documents/Projekte/build-my-project-Desktop_Qt_5_12_6_MinGW_64_bit-Debug")

and pointing clang-tidy with -p to it. Error: for the -p option: may not occur within a group

3) Using the -extra-arg parameter like

set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" "-extra-arg=-I C:/Qt/Tools/mingw730_64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++")

also instead of -I I tried -isystem with same result: Error 'string' file not found [clang-diagnostic-error]

4) Trying to pass the stdlib to clang-tidy

set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" "-extra-arg=-stdlib==libc++")

But nothing works.

  • 1
    "But nothing works." - how does it not work? Please show us the errors you are getting. Otherwise it's really hard to help you with this. – pablo285 Mar 19 '20 at 10:25
  • Well, 1) doesn't do anything, I get the usual "undefined reference" errors. The error for 2) is below the code, 3) says: 'string' file not found (and many more stdlib references) and 4) says: Error: Did you mean ' --stats=libc++'? – Programmierkartoffel Mar 19 '20 at 10:37
  • It's much better if you provide error texts within the question (and properly formatted) rather than in the comments. As for 4) - you have a double equals sign in the extra-arg. – pablo285 Mar 20 '20 at 08:41
  • Thanks for the advice. Removing one of he equals signs does not change anything. As before the error is: 'string' file not found [clang-diagnostic-error] – Programmierkartoffel Mar 23 '20 at 07:27
  • I solved it with `--extra-arg`. But you have an extra space in this arg which might break it the extra-arg? – veio Dec 29 '20 at 13:26
  • In attempt 4, you wrote "stdlib==libc++" with two equal signs but it should be "stdlib=libc++" with a single "=". – CNugteren Aug 25 '23 at 14:28

0 Answers0