clang-tidy with precompiled headers and cmake does not work - c++

I have a simple setup where CMake produces the following compile command:
cd /workspaces/cmake-general/tests/project/build/examples/hello-world && /usr/local/bin/cmake -E __run_co_compile
--iwyu=/usr/local/bin/include-what-you-use
--tidy="/usr/bin/clang-tidy;-extra-arg=-Wno-unknown-warning-option;-warnings-as-errors=*;--extra-arg-before=--driver-mode=g++"
--source=/workspaces/cmake-general/tests/project/build/examples/hello-world/CMakeFiles/example-hello-world.dir/cmake_pch.hxx.cxx --
/usr/bin/c++
-I/workspaces/cmake-general/tests/project/examples/hello-world/src
-I/workspaces/cmake-general/tests/project/build -O3 -DNDEBUG -stdlib=libc++
-fcolor-diagnostics -Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wunused -Woverloaded-virtual -Wpedantic -Wconversion
-Wsign-conversion -Wnull-dereference -Wdouble-promotion
-Wformat=2 -Werror -std=c++20 -Winvalid-pch -fpch-instantiate-templates
-Xclang -emit-pch -Xclang -include
-Xclang /workspaces/cmake-general/tests/project/build/examples/hello-world/CMakeFiles/example-hello-world.dir/cmake_pch.hxx
-x c++-header -MD -MT examples/hello-world/CMakeFiles/example-hello-world.dir/cmake_pch.hxx.pch -MF
CMakeFiles/example-hello-world.dir/cmake_pch.hxx.pch.d -o CMakeFiles/example-hello-world.dir/cmake_pch.hxx.pch
-c /workspaces/cmake-general/tests/project/build/examples/hello-world/CMakeFiles/example-hello-world.dir/cmake_pch.hxx.cxx
which errors our with not finding
/workspaces/cmake-general/tests/project/build/examples/example-sanitizer/CMakeFiles/example-sanitizer-address.dir/cmake_pch.hxx:5:10: error: 'iostream' file not found [clang-diagnostic-error]
#include <iostream>
^
3 errors generated.
When I take --tidy="..." stuff out of the command. It fully compiles, (also if I dont specify PCHs in the CMakeLists.txt) it works.
I am not sure what the problem is exactly.
Do PCH and clang-tidy somehow not work? Why are the include directories somehow missing? I am using LLVM-12, clang-12 on Ubuntu.
Also adding -I/usr/lib/llvm-12/include/c++/v1 does not help.

Related

compile simple github fails at ext submodule

i am trying to compile this git https://github.com/yapb/yapb locally
i am using ubuntu 64bit, and it says i must compile 32bit
i am using now
CC=clang CXX=clang meson build-clang
but get this error
FAILED: yapb.so.p/src_chatlib.cpp.o
clang -Iyapb.so.p -I. -I.. -fvisibility=hidden -flto
-fcolor-diagnostics -DNDEBUG -D_FILE_OFFSET_BITS=64 -Wall
-Winvalid-pch -Wnon-virtual-dtor -Wextra -Wpedantic -Werror -std=c++14
-fno-exceptions -O3 -DVERSION_GENERATED -fno-threadsafe-statics
-fno-exceptions -fno-rtti -m32 -pedantic -fdata-sections
-ffunction-sections -mtune=generic -fno-builtin -funroll-loops
-fomit-frame-pointer -fno-stack-protector -fvisibility=hidden
-fvisibility-inlines-hidden -msse2 -mfpmath=sse -fPIC
-isystem../ext/crlib -isystem../ext -isystem../inc -isystem..
-isystem. -MD -MQ yapb.so.p/src_chatlib.cpp.o -MF
yapb.so.p/src_chatlib.cpp.o.d -o yapb.so.p/src_chatlib.cpp.o -c
../src/chatlib.cpp
In file included from ../src/chatlib.cpp:8:
In file included from ../inc/yapb.h:10:
In file included from ../ext/hlsdk/extdll.h:28:
In file included from ../ext/crlib/crlib/string.h:17:
../ext/crlib/crlib/array.h:15:10: fatal error: 'initializer_list' file not found
#include <initializer_list>```
Double-check the pre-requisites mentioned in YaPB Building the Bot page.
Try and open a regular CMD (instead of Powershell), making sure it inherits all your previous setups (meaning its %PATH% does reference g++.exe, pip.exe, and so on.

Why this .c file just have one line "../xx/xx.c"?

I want to build mesa3d source code for some reason. I follow the guide on https://mesa3d.org/install.html and the build environment is fedora31 and gcc9.2, but there are some build error when I trying to build the code with running ninja install.
FAILED: src/mesa/drivers/dri/r200/58cd8d4##r200#sta/radeon_buffer_objects.c.o
cc -Isrc/mesa/drivers/dri/r200/58cd8d4##r200#sta -Isrc/mesa/drivers/dri/r200 -I../src/mesa/drivers/dri/r200 -Iinclude -I../include -Isrc -I../src -Isrc/mapi -I../src/mapi -Isrc/mesa -I../src/mesa -I../src/gallium/include -Isrc/gallium/auxiliary -I../src/gallium/auxiliary -Isrc/mesa/drivers/dri/common -I../src/mesa/drivers/dri/common -Isrc/util -I../src/util -I../src/mesa/drivers/dri/r200/server -Isrc/util/xmlpool -I/usr/include/libdrm -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -std=c99 -O2 -g -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS '-DPACKAGE_VERSION="20.0.0-devel"' '-DPACKAGE_BUGREPORT="https://gitlab.freedesktop.org/mesa/mesa/issues"' -DUSE_ELF_TLS -DHAVE_ST_VDPAU -DENABLE_ST_OMX_BELLAGIO=0 -DENABLE_ST_OMX_TIZONIA=0 -DHAVE_X11_PLATFORM -DGLX_INDIRECT_RENDERING -DGLX_DIRECT_RENDERING -DGLX_USE_DRM -DHAVE_DRM_PLATFORM -DHAVE_SURFACELESS_PLATFORM -DENABLE_SHADER_CACHE -DHAVE___BUILTIN_BSWAP32 -DHAVE___BUILTIN_BSWAP64 -DHAVE___BUILTIN_CLZ -DHAVE___BUILTIN_CLZLL -DHAVE___BUILTIN_CTZ -DHAVE___BUILTIN_EXPECT -DHAVE___BUILTIN_FFS -DHAVE___BUILTIN_FFSLL -DHAVE___BUILTIN_POPCOUNT -DHAVE___BUILTIN_POPCOUNTLL -DHAVE___BUILTIN_UNREACHABLE -DHAVE_FUNC_ATTRIBUTE_CONST -DHAVE_FUNC_ATTRIBUTE_FLATTEN -DHAVE_FUNC_ATTRIBUTE_MALLOC -DHAVE_FUNC_ATTRIBUTE_PURE -DHAVE_FUNC_ATTRIBUTE_UNUSED -DHAVE_FUNC_ATTRIBUTE_WARN_UNUSED_RESULT -DHAVE_FUNC_ATTRIBUTE_WEAK -DHAVE_FUNC_ATTRIBUTE_FORMAT -DHAVE_FUNC_ATTRIBUTE_PACKED -DHAVE_FUNC_ATTRIBUTE_RETURNS_NONNULL -DHAVE_FUNC_ATTRIBUTE_VISIBILITY -DHAVE_FUNC_ATTRIBUTE_ALIAS -DHAVE_FUNC_ATTRIBUTE_NORETURN -DHAVE_UINT128 -D_GNU_SOURCE -DUSE_SSE41 -DUSE_GCC_ATOMIC_BUILTINS -DUSE_X86_64_ASM -DMAJOR_IN_SYSMACROS -DHAVE_SYS_SYSCTL_H -DHAVE_LINUX_FUTEX_H -DHAVE_ENDIAN_H -DHAVE_DLFCN_H -DHAVE_EXECINFO_H -DHAVE_SYS_SHM_H -DHAVE_CET_H -DHAVE_STRTOF -DHAVE_MKOSTEMP -DHAVE_TIMESPEC_GET -DHAVE_MEMFD_CREATE -DHAVE_RANDOM_R -DHAVE_FLOCK -DHAVE_STRTOK_R -DHAVE_PROGRAM_INVOCATION_NAME -DHAVE_POSIX_MEMALIGN -DHAVE_STRTOD_L -DHAVE_DLADDR -DHAVE_DL_ITERATE_PHDR -DHAVE_ZLIB -DHAVE_PTHREAD -DHAVE_PTHREAD_SETAFFINITY -DHAVE_LIBDRM -DLLVM_AVAILABLE '-DMESA_LLVM_VERSION_STRING="9.0.0"' -DHAVE_VALGRIND -DHAVE_WAYLAND_PLATFORM -DWL_HIDE_DEPRECATED -DHAVE_DRI3 -DHAVE_DRI3_MODIFIERS -Werror=implicit-function-declaration -Werror=missing-prototypes -Werror=return-type -Werror=empty-body -Werror=incompatible-pointer-types -Wno-missing-field-initializers -Wno-format-truncation -fno-math-errno -fno-trapping-math -Werror=format -Wformat-security -fPIC -fvisibility=hidden -DRADEON_R200 -MD -MQ 'src/mesa/drivers/dri/r200/58cd8d4##r200#sta/radeon_buffer_objects.c.o' -MF 'src/mesa/drivers/dri/r200/58cd8d4##r200#sta/radeon_buffer_objects.c.o.d' -o 'src/mesa/drivers/dri/r200/58cd8d4##r200#sta/radeon_buffer_objects.c.o' -c ../src/mesa/drivers/dri/r200/radeon_buffer_objects.c
../src/mesa/drivers/dri/r200/radeon_buffer_objects.c:1:1: error: expected identifier or '(' before '.' token
1 | ../radeon/radeon_buffer_objects.c
| ^
Then I check the radeon_buffer_objects.c, and this file just have one file path in it.
../radeon/radeon_buffer_objects.c
I'm not very familier with gcc and clang. What is that mean? And how can I resolve this build error?
As AnthonySottile's comment said, this error is about the symbol link support. I have cloned this repo to windows before and upload to my own git server. And the error occured when I trying to build the source code from my git.
I try to clone the repo from mesa3d.org, and the issue resolved.
Thanks for the help, guys.

Errors while build cpprestsdk using gcc-8.2

When I try building cpprestsdk with a cross compiler gcc I've the following issue:
cd /home/ubuntu/projects/cpprestsdk/Release/build_qamf-dev/src && /opt/qamf-dev/x86_64-qamf/bin/x86_64-qamf-linux-gnu-g++ -DCPPREST_EXCLUDE_BROTLI=1 -DCPPREST_FORCE_HTTP_CLIENT_ASIO -DCPPREST_FORCE_HTTP_LISTENER_ASIO -DCPPREST_NO_SSL_LEAK_SUPPRESS -Dcpprest_EXPORTS -I/home/ubuntu/projects/cpprestsdk/Release/include -I/home/ubuntu/projects/cpprestsdk/Release/src/pch -I/home/ubuntu/projects/cpprestsdk/Release/libs/websocketpp -isystem /opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/sysroot/usr/include -std=c++11 -fno-strict-aliasing -O3 -DNDEBUG -fPIC -Werror -pedantic -Wall -Wextra -Wunused-parameter -Wcast-align -Wcast-qual -Wconversion -Wformat=2 -Winit-self -Winvalid-pch -Wmissing-format-attribute -Wmissing-include-dirs -Wpacked -Wredundant-decls -Wunreachable-code -o CMakeFiles/cpprest.dir/http/oauth/oauth2.cpp.o -c /home/ubuntu/projects/cpprestsdk/Release/src/http/oauth/oauth2.cpp
cd /home/ubuntu/projects/cpprestsdk/Release/build_qamf-dev/src && /opt/qamf-dev/x86_64-qamf/bin/x86_64-qamf-linux-gnu-g++ -DCPPREST_EXCLUDE_BROTLI=1 -DCPPREST_FORCE_HTTP_CLIENT_ASIO -DCPPREST_FORCE_HTTP_LISTENER_ASIO -DCPPREST_NO_SSL_LEAK_SUPPRESS -Dcpprest_EXPORTS -I/home/ubuntu/projects/cpprestsdk/Release/include -I/home/ubuntu/projects/cpprestsdk/Release/src/pch -I/home/ubuntu/projects/cpprestsdk/Release/libs/websocketpp -isystem /opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/sysroot/usr/include -std=c++11 -fno-strict-aliasing -O3 -DNDEBUG -fPIC -Werror -pedantic -Wall -Wextra -Wunused-parameter -Wcast-align -Wcast-qual -Wconversion -Wformat=2 -Winit-self -Winvalid-pch -Wmissing-format-attribute -Wmissing-include-dirs -Wpacked -Wredundant-decls -Wunreachable-code -o CMakeFiles/cpprest.dir/json/json.cpp.o -c /home/ubuntu/projects/cpprestsdk/Release/src/json/json.cpp
[ 7%] Building CXX object src/CMakeFiles/cpprest.dir/http/oauth/oauth1.cpp.o
cd /home/ubuntu/projects/cpprestsdk/Release/build_qamf-dev/src && /opt/qamf-dev/x86_64-qamf/bin/x86_64-qamf-linux-gnu-g++ -DCPPREST_EXCLUDE_BROTLI=1 -DCPPREST_FORCE_HTTP_CLIENT_ASIO -DCPPREST_FORCE_HTTP_LISTENER_ASIO -DCPPREST_NO_SSL_LEAK_SUPPRESS -Dcpprest_EXPORTS -I/home/ubuntu/projects/cpprestsdk/Release/include -I/home/ubuntu/projects/cpprestsdk/Release/src/pch -I/home/ubuntu/projects/cpprestsdk/Release/libs/websocketpp -isystem /opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/sysroot/usr/include -std=c++11 -fno-strict-aliasing -O3 -DNDEBUG -fPIC -Werror -pedantic -Wall -Wextra -Wunused-parameter -Wcast-align -Wcast-qual -Wconversion -Wformat=2 -Winit-self -Winvalid-pch -Wmissing-format-attribute -Wmissing-include-dirs -Wpacked -Wredundant-decls -Wunreachable-code -o CMakeFiles/cpprest.dir/http/oauth/oauth1.cpp.o -c /home/ubuntu/projects/cpprestsdk/Release/src/http/oauth/oauth1.cpp
[ 10%] Building CXX object src/CMakeFiles/cpprest.dir/uri/uri_builder.cpp.o
[ 7%] Building CXX object src/CMakeFiles/cpprest.dir/json/json_serialization.cpp.o
[ 8%] Building CXX object src/CMakeFiles/cpprest.dir/uri/uri.cpp.o
In file included from /opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/include/c++/8.2.0/ext/string_conversions.h:41,
from /opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/include/c++/8.2.0/bits/basic_string.h:6391,
from /opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/include/c++/8.2.0/string:52,
from /home/ubuntu/projects/cpprestsdk/Release/src/pch/stdafx.h:55,
from /home/ubuntu/projects/cpprestsdk/Release/src/http/client/http_client_msg.cpp:13:
/opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/include/c++/8.2.0/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
#include_next <stdlib.h>
^~~~~~~~~~
In file included from /opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/include/c++/8.2.0/ext/string_conversions.h:41,
from /opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/include/c++/8.2.0/bits/basic_string.h:6391,
from /opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/include/c++/8.2.0/string:52,
from /home/ubuntu/projects/cpprestsdk/Release/src/pch/stdafx.h:55,
from /home/ubuntu/projects/cpprestsdk/Release/src/http/client/http_client.cpp:16:
/opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/include/c++/8.2.0/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
#include_next <stdlib.h>
^~~~~~~~~~
compilation terminated.
In file included from /opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/include/c++/8.2.0/ext/string_conversions.h:41,
from /opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/include/c++/8.2.0/bits/basic_string.h:6391,
from /opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/include/c++/8.2.0/string:52,
from /home/ubuntu/projects/cpprestsdk/Release/src/pch/stdafx.h:55,
from /home/ubuntu/projects/cpprestsdk/Release/src/http/common/http_compression.cpp:14:
/opt/qamf-dev/x86_64-qamf/x86_64-qamf-linux-gnu/include/c++/8.2.0/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
#include_next <stdlib.h>
^~~~~~~~~~
compilation terminated.
If I replace -isystem with a simple -I everything works well...
I know the gcc is working well cos I already built zlib openssl opencv and boost 1.69.
EDIT
To avoid the problem I edited the Makefile generated by cmake and removed -isystem from cxx flags

Code base not finding standard C++ library header

I am compiling an example application from the SDK repository of a third party vendor. I receive an error that one of the C++ header's (algorithm) cannot be found:
if [ ! -d .deps/ ]; then mkdir -p .deps/; fi
/opt/llvm-3.8.0/bin/clang++ -M -isystem/opt/tbricks/sdk/include64 -I../../.. -I../../../.. -I./../../../.. -DLINUX -DLINUX64 -DTB_USE_RCU -DURCU_INLINE_SMALL_FUNCTIONS -DU_USING_ICU_NAMESPACE=0 -DNDEBUG -D_POSIX_PTHREAD_SEMANTICS -fPIC -D_GNU_SOURCE -DTB_USE_RCU -DTB_USE_RCU -D_GLIBCXX_USE_CXX11_ABI=0 -m64 --gcc-toolchain=/opt/gcc-5.2.0 -flto=full -std=gnu++14 -D_GLIBCXX_DEPRECATED= -pipe -fno-omit-frame-pointer -ffast-math -fno-finite-math-only -pthread -march=core2 -mtune=corei7 -g -O3 -Qunused-arguments -fnon-call-exceptions -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Wextra -Wshadow -Wpointer-arith -Wno-self-assign -Wno-unused-function -Wno-gnu-empty-initializer -Wno-unused-parameter -Wno-ignored-qualifiers -Wno-mismatched-tags -Wno-unused-local-typedef -Wno-parentheses-equality -Wno-unused-private-field -Wno-missing-field-initializers -Wno-missing-braces -Werror=return-type -Werror=overloaded-virtual -DSTRATEGY_BUILD_PROFILE=\"release\" ../../../../shared/Helpers.cpp > .deps/Helpers.o.d
../../../../shared/Helpers.cpp:14:10: fatal error: 'algorithm' file not found
#include <algorithm>
What sets the location path to search for C++ header files, such as algorithm? Is there anything I can grep for within makefiles?
Either install g++ alongside (you need libstdc++) or use LLVM libc++ and specify it with -stdlib=libc++

What could cause clang to not find the unordered_map header?

I'm trying to compile a program I found on the web using Clang++. The Makefile generates this command:
clang++ -c -arch x86_64 -msse3 -std=c++11 -stdlib=libstdc++
-Wno-missing-field-initializers -Wno-missing-prototypes -Wreturn-type
-Wno-non-virtual-dtor -Wno-exit-time-destructors -Wformat -Wmissing-braces
-Wparentheses -Wno-switch -Wunused-function -Wunused-label -Wno-unused-parameter
-Wunused-variable -Wunused-value -Wno-empty-body -Wuninitialized -Wunknown-pragmas
-Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion
-Wint-conversion -Wno-shorten-64-to-32 -Wenum-conversion -Wno-newline-eof
-Wno-c++11-extensions -Wno-logical-op-parentheses -Wno-trigraphs
-Wno-invalid-offsetof -Wno-sign-conversion -Wdeprecated-declarations
-fmessage-length=0 -fno-exceptions -fstrict-aliasing -fvisibility=hidden
-fvisibility-inlines-hidden -funsafe-math-optimizations -ftrapping-math -fno-rtti
-fpascal-strings -fasm-blocks -O3 -Iinclude/ src/main.cpp
But I get
src/main.cpp:23:10: fatal error: 'unordered_map' file not found
#include <unordered_map>
^
1 error generated.
If I compile a simple program that includes <unordered_map> running clang++ test.cpp, it compiles fine.
I'm on
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.3.0
Thread model: posix
I had the same issue when compiling glogg.
As the comments have pointed out. it was stdlib.
In the makefile after running qmake. Change this line from
CXXFLAGS = -g -Wextra -std=c++11 -DGLOGG_VERSION=\"`cat .tarball-version`\" -O2 -arch x86_64 -Wall -W $(DEFINES)
To this line below
CXXFLAGS = -g -Wextra -std=c++11 -stdlib=libc++ -DGLOGG_VERSION=\"`cat .tarball-version`\" -O2 -arch x86_64 -Wall -W $(DEFINES)
notice "-stdlib=libc++" was specified in the cxxflags. It's autospecified in the linker flags, I guess it also needs to be specified in for the C++ flags.
It says -Wno-c++11-extensions. What wrote that makefile?