clang-tidy does not recognize standard libraries
I have a simple program that compiles and runs successfully, but I can't get clang-tidy to work.
My program:
#include <iostream>
int main() {
return 0;
}
CMakeLists.txt:
cmake_minimum_required(VERSION 3.1)
project(myProg CXX)
set(CMAKE_CXX_COMPILER "/usr/bin/clang++")
set(CMAKE_CXX_STANDARD 14)
add_executable(myProg test.cpp)
I produce a compile_commands.json
using -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
to be used with clang-tidy:
[
{
"directory": "/Users/me/myProj/build",
"command": "/usr/bin/clang++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -mmacosx-version-min=10.15 -o CMakeFiles/myProg.dir/test.cpp.o -c /Users/me/myProj/test.cpp",
"file": "/Users/me/myProj/test.cpp"
}
]
This compiles and runs successfully.
Now, when I run clang-tidy -p=/Users/me/myProj/build /Users/me/myProj/test.cpp
, I get this:
test.cpp:1:10: error: 'iostream' file not found [clang-diagnostic-error]
When writing this question, I realized that when I add the following line to the compile_commands.json
, clang-tidy can successfully find iostream:
-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
Also, when I don't specify the compiler in my cmake file and I use the default compiler in /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
, clang-tidy runs with no error.
from Recent Questions - Stack Overflow https://ift.tt/3svRgmT
https://ift.tt/eA8V8J
Comments
Post a Comment