Note: This is done in RHEL 7.2 with clang 8.0.1.
I'm running the command
clang-tidy test.C -- -I/path/to/header.h
and I get the following error:
1 error generated.
Error while processing test.C.
test.C:28:10: error: 'header.h' file not found [clang-diagnostic-error]
#include "header.h"
^
Found compiler error(s).
When I build using g++, it works fine. The above include is the first include statement of the file, and there's some more after it. The file structure is complicated, so it'd be difficult to show where the files are located. I thought the -I argument would find the header, but it doesn't. So, how do I get clang-tidy to find those headers?
Clang tools usually need a compilation database : the compile_commands.json.
It provides information required to build your cpp units (g.e the include directories).
You can generate this file from Make, CMake, etc. by using some external tools.
https://github.com/rizsotto/Bear is one of them.
Related
I am following the course "Introduction to Deep Learning with Xilinx SoCs Technical Training Course" for the Ultra96v2 board and reached Lab No. 5.
I am able to follow along until I am supposed to build the project in the SDK.
It fails and tells me errors like these:
15:49:06 **** Incremental Build of configuration Debug for project mnist_file_io ****
make all
Building file: ../src/mnist_file_io.cc
Invoking: ARM v8 Linux g++ compiler
aarch64-linux-gnu-g++ -Wall -O0 -g3 -I/media/user/6b04b610-ff80-4702-a575-b0b1a78fbafb/training/AvnetTTC/DPU/U96AI_student_20200115/U96AI/2018_3/work/lab5/workspace/ExtraIncludes -I/usr/include -c -fmessage-length=0 -MT"src/mnist_file_io.o" --sysroot=YSROOT -MMD -MP -MF"src/mnist_file_io.d" -MT"src/mnist_file_io.o" -o "src/mnist_file_io.o" "../src/mnist_file_io.cc"
In file included from ../src/mnist_file_io.cc:9:0:
/tools/Xilinx/SDK/2018.3/gnu/aarch64/lin/aarch64-linux/aarch64-linux-gnu/include/c++/7.3.1/cmath:45:15: fatal error: math.h: No such file or directory
#include_next <math.h>
^~~~~~~~
compilation terminated.
src/subdir.mk:21: recipe for target 'src/mnist_file_io.o' failed
make: *** [src/mnist_file_io.o] Error 1
It doesnt find the header file, although it is included in the paths which were provided by the tutorial as well as by me. Actually, two additional files haven't been found:
#include <opencv2/opencv.hpp>
#include <dnndk/dnndk.h>
I was able to include them by picking them by hand from the directories where they were in and adding them to an extra directory in which the Xilinx SDK should search for headers.
But this brings up the question: Why aren't they found in the first place? After correct installation and following the instructions in the above mentioned tutorial, shouldn't I be all set up to just build it?
Actually, by using the installer on the Xilinx Download website (Xilinx_SDK_2018.3_1207_2324_Lin64.bin), the SDK didn't start because there were some files missing for the SDK program (eclipse and some other stuff). So it just started once I copied those files from the other installation (Vivado, etc.). Isn't this also supposed to work just out of the box? Reinstalling, etc. didn't work unfortunately.
So I guess one question that crystallizes here is: Is there a possibility to give Eclipse/Xilinx SDK a path to a directory for all required standard header files and it searches in them? Because in some standard headers, they include other headers, which in turn aren't found by the Xilinx SDK. And will that fix my issues?
Funnily enough, when I use the Ctrl+Click action to jump from header to header, all headers are found and it's no problem. It's only in the build process where embedded further headers aren't found anymore. Also, when I change the #include_next to #include, the whole thing starts working again. The same with changing #include <header> to #include "header.h". Then it works. But that can't be the solution, changing every header that throws an error, since it was generated like this for a reason, right?
This is really annoying and disrupts any workflow.
Is there someone who had this problem as well and may help me?
I am using Ubuntu 16.04 and the Ultra96v2 board.
Update
What I've investigated so far with no avail:
https://e2e.ti.com/support/wireless-connectivity/wi-fi-group/wifi/f/wi-fi-forum/993711/cc3235sf-why-is-ccs-eclipse-unable-to-see-the-c-standard-header-files
Eclipse can't find header file, even though include paths are set
Where are the headers of the C++ standard library
https://www.eclipse.org/forums/index.php/t/1088833/
I have included the path for my C++ gcc standard library as a path in which Eclipse/the Xilinx IDE is supposed to search for headers, but the headers inside the files aren't being found.
Update 2
Here you can see where the problem starts. It's really weird, since everything is auto-generated and thus should just work, especially since those are predefined headers and sources, which haven't been altered by me.
Here, you can see that I included the usual standard header location in the inclusion paths, so the files in question should be found.
I've found that a small C++ project, with no dependencies, won't compile under Cygwin with either GCC or Clang. Under Ubuntu there are no problems; and I've been working with this code for a couple of years. I'll introduce a MWE.
The problem arises when including a header in a subdirectory, which itself includes another header, found in that same subdirectory, but specified with the subdirectory in the path provided to the include directive. Executing the following commands can replicate the error:
mkdir foo
echo \#include \"foo/includes.hpp\" > inc.hpp
echo \#include \"foo/bar.hpp\" > foo/includes.hpp
touch foo/bar.hpp
g++ -c inc.hpp
On 64-bit Ubuntu 18.10, the final GCC (or Clang) invocation will produce no errors. On 64-bit Cygwin under Windows 10, the following error message is displayed.
In file included from inc.hpp:1:0:
foo/includes.hpp:1:10: fatal error: foo/bar.hpp: No such file or directory
#include "foo/bar.hpp"
^~~~~~~~~~~~~
compilation terminated.
Can anyone shed some light on the issue? (By the way, I myself do well understand how to properly include header files - this is about the difference between Cygwin and Ubuntu.)
foo/includes.hppshould have local includes if you use "".
That would be:
#include "bar.hpp"
The specification for what paths are used for searching headers is custom for all compilers, although includes with "" should be considered as local for the file where you have the include, not the one that you are compiling.
Basically, it's:
look in the current folder of the current header being processed for a file with that name
use the same paths as <>after
Of course, as I've said, this could change for a new compiler one day. But it is quite safe to assume that this is the behavior for all compilers (What is the difference between #include <filename> and #include "filename"?).
I am trying to cross-compile OpenImageIO for 64-bit Windows on Fedora 26 using MinGW. After using yum to retrieve the mingw versions of the dependencies, I ran mingw64-cmake followed by make. However, right away I receive a compile error about stdlib.h not being found.
[ 0%] Built target CopyFiles
[ 0%] Building CXX object src/libutil/CMakeFiles/OpenImageIO_Util.dir/argparse.cpp.obj
In file included from .../oiio/src/libutil/argparse.cpp:36:0:
/usr/x86_64-w64-mingw32/sys-root/mingw/include/c++/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
#include_next <stdlib.h>
^~~~~~~~~~
compilation terminated.
I have confirmed that stdlib.h is found at least in /usr/include/ and in /usr/x86_64-w64-mingw32/sys-root/mingw/include/c++/ where the file giving the compiler error also is located.
Why do I still receive the error stdlib.h: No such file or directory?
Update:
I did additional research and learned the following: The preprocessor directive #include_next behaves like the #include directive, except that it specifically excludes the directory of the including file from the paths to be searched for the named file.
This would explain why cstdlib does not find stdlib.h from the same folder. But cstdlib is part of MinGW and not any part of the code I am trying to compile. So I still have no idea what is wrong here or how to fix this error.
Edit: Here is the compiler version info in case it is of any use: https://pastebin.com/PZiXS2fg. This is a fresh install so there shouldn't be anything unusual there, though.
I solved it, i can compile again.
The solution (for me) is add to path the variable CPLUS_INCLUDE_PATH and set it to the MinGW c++ include directory, for me: C:\MinGW\lib\gcc\mingw32\6.3.0\include\c++.
I hope it works for you too.
The use of #include_next appears to cause lots of issues based on my Googling. Try directly including stdlib.h using the following syntax:
-isystem /usr/x86_64-w64-ming32/sys-root/mingw/include/c++
This syntax was added in gcc 6.0 to solve issues with third-party libraries. See here for the approach and reasoning.
Edit: Changed answer to reflect new information about gcc wrapper_headers and #include_next
I have downloaded the source code to do some benchmark for couple of C++ library. I don't have much knowledge in C++. I downloaded the libraries. When I try to compile the code
g++ test_matrix_pseudoinverse.cpp -o test_matrix_pseudoinverse
I get this error
test_matrix_pseudoinverse.cpp:26:64: fatal error:
opencv2.4/modules/core/include/opencv2/core/core.hpp: No such file or
directory #include
^ compilation terminated.
The source code with all the libraries are in github
https://github.com/shiblybcc/linear-algebra-benchmark
I have downloaded the code from here. It would be nice if someone could tell me why I am getting this error and how to run the code without any error.
I am on linux and I have added opencv2 folder in /usr/local/include directory.
I guess this is resulted from not setting the include path if the file complained by the compiler does exist. Suppose your OpenCV source code tree is under /home/yourhome (i.e the full path to the file reported not existed should be /home/yourhome/opencv2.4/modules/core/include/opencv2/core/core.hpp), you need to specify the include path by -I/home/yourhome argument. Therefore the full command line to build should be as:
g++ -I/home/yourhome test_matrix_pseudoinverse.cpp -o test_matrix_pseudoinverse
I created a simple Flex file to read and return tokens from a file. I generated the scanner file using the command flex -c++ scanner.l. When trying to compile the generated lex.yy.cc file I am getting the error as:
Fatal error: FlexLexer.h: No such file or directory
The include folder of flex contains the FlexLexer.h file. I also tried by copying the file to the same folder where lex.yy.cc resides. Still the error exists.
I am using Windows7.
How can I solve this problem. Thank You
The generated scanner uses the line:
#include <FlexLexer.h>
which means that the FlexLexer.h file will be searched for in system include directories. If you correctly install flex, the installation should put the FlexLexer.h file in some system include directory. If you just download the flex source and compile it without installing it, that won't work. And it might not work in the Windows environment either; I've never tried.
If you have no other alternative, and you're using gcc, you can tell gcc to use the include directory in the flex source tree as a system include directory using the command-line option -isystem /path/to/flex/include. There's almost certainly a VS2010 equivalent but I have no idea what it is.