6

I'm trying to use clang-tidy to parse my project, compiled by arm-none-eabi-g++.

Unfortunately, clang-tidy is not able to find compiler headers, even when given the include path to them.

My compile_commands.json is

  [   
    {
    "directory": "C:/LMA/repo/clang-tidy",
    "arguments": [
      "arm-none-eabi-c++",
      "-IC:/nxp/MCUXpressoIDE_11.2.1_4149/ide/tools/arm-none-eabi/include/c++/9.2.1",
      "-IC:/nxp/MCUXpressoIDE_11.2.1_4149/ide/tools/arm-none-eabi/include/c++/9.2.1/arm-none-eabi/arm/v5te/hard",
      "test.cpp"
    ],
    "file": "./test.cpp"   } ]

And the example test.cpp file is:

#include <cstdint>
#include <cstdlib>

int test()
{
  int temp;
  return 0;
}

Clang-tidy shows error:

C:/nxp/MCUXpressoIDE_11.2.1_4149/ide/tools/arm-none-eabi/include/c++/9.2.1\cstdlib:75:15: error: 'stdlib.h' file not found [clang-diagnostic-error]
#include_next <stdlib.h>

So, it properly finds and includes cstdlib, however it is not able to find stdint.h, which is located in the exactly same folder. What's even more irritaiting, it does not include stdlib.h, even when I add

-include C:/nxp/MCUXpressoIDE_11.2.1_4149/ide/tools/arm-none-eabi/include/c++/9.2.1/stdlib.h to compiler arguments in order to force preinclude.

Any suggestions how to fix this issue are very much appreciated.

MLapaj
  • 371
  • 3
  • 11

1 Answers1

1

This is a bit old, but I was having a similar issue so I figured I'd report an answer here in case anyone else comes across this while searching. It appears clang doesn't know where to find the standard library headers when compiling using arm-none-eabi. I succeeded by simply adding them.

In your case you're still missing the C headers directory, so you need to add this: C:/nxp/MCUXpressoIDE_11.2.1_4149/ide/tools/arm-none-eabi/include/

(assuming the directory structure is similar to mine).

So your compile_commands.json would be:

[ {
  "directory": "C:/LMA/repo/clang-tidy",
  "arguments": [
      "arm-none-eabi-g++",
      "-IC:/nxp/MCUXpressoIDE_11.2.1_4149/ide/tools/arm-none-eabi/include",
      "-IC:/nxp/MCUXpressoIDE_11.2.1_4149/ide/tools/arm-none-eabi/include/c++/9.2.1",
      "-IC:/nxp/MCUXpressoIDE_11.2.1_4149/ide/tools/arm-none-eabi/include/c++/9.2.1/arm-none-eabi/arm/v5te/hard",
      "test.cpp"
  ],
  "file": "./test.cpp"
} ]

You should also have arm-none-eabi-g++ instead of arm-none-eabi-c++ I believe.

Adam
  • 2,726
  • 1
  • 9
  • 22
Lurgypai
  • 31
  • 6
  • Thanks, but we eventually ended up using PC-lint as our static code analyzer and I'm not able to check this solution – MLapaj Jan 24 '22 at 08:16