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.
Related
I'm not having any success with #include <opencv>, no matter what I try. [EDIT: I've also tried #include <opencv2> and #include <opencv4>, but there was no difference].
For context, I'm on Ubuntu 20.04, using Sublime Text 3, the latest version of OpenCV is installed on the system (at /usr/local/include/opencv4/opencv2), and I've tried something like six different build systems for cpp, including the default.
no matter what I try and how I fiddle with files, I always get the same error:
/home/user/Projects/Mind/CScript/Script.cpp:5:10: fatal error: opencv: No such file or directory
5 | #include <opencv>
| ^~~~~~~~
compilation terminated.
[Finished in 0.1s with exit code 1]
[shell_cmd: g++ "/home/user/Projects/Mind/CScript/Script.cpp" -o "/home/user/Projects/Mind/CScript/Script" && "/home/user/Projects/Mind/CScript/Script"]
[dir: /home/user/Projects/Mind/CScript]
[path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games]
I even tried to copy the whole opencv folder into the file path, but there was no change at all.
EDIT: The solution that worked was to paste the opencv2 folder from /usr/local/include/opencv4/ to /usr/local/include/. Apparently that additional folder wasn't supposed to be there.
An #include refers to a file, not a folder. A file so specified is looked for in the list of include paths.
-I /usr/local/include/opencv4/opencv2 adds that path to the list of include paths. The path, however, looks broken to me -- OpenCV has the legacy API in opencv/, and the updated API in opencv2/, but in either case there should be no opencv4/ in the path. (Double-checked with my APT.) Are you sure you did the OpenCV setup correctly?
The actual header's name is opencv2/opencv.hpp (note the .hpp at the end; generally, only the standard library's includes are without .hpp, all the third party libs I have seen so far use the .hpp extension).
Best practice is to leave the include path alone and write #include "opencv2/opencv.hpp" (with the subdirectory name) in your sources to avoid ambiguity.
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.
I'm trying to set up precompiled headers in a large C++ project compiled with GCC 5.4.
There is a file "PrecompiledHeaders.h", which includes all the other relevant headers. I've added the compile flag -include PrecompiledHeaders.h, but when compiling, the header is not found:
cc1plus: fatal error: PrecompiledHeaders.h: No such file or directory
compilation terminated.
CMakeFiles/Project.dir/build.make:62: recipe for target 'CMakeFiles/Project.dir/NetworkGameState.cpp.o' failed
But I'm sure it exists, in the same directory as all other h and cpp files. What's more, manually adding #include "PrecompiledHeaders.h" to the top of "NetworkGameState.cpp" does not produce an error.
What could go wrong?
This is a CMake, out-of-source build, by the way.
It's likely an issue with the path. From the GCC 5.4 manual (emphasis mine):
-include file
Process file as if #include "file" appeared as the first line of the primary source file. However, the first directory searched for file is the preprocessor's working directory instead of the directory containing the main source file. If not found there, it is searched for in the remainder of the #include "..." search chain as normal.
You need to either supply the full (relative or absolute) path to the header as the argument of the -include flag, or add its parent directory to the search chain using e.g. -I or -iquote.
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 want to build a cuda plugin for an other project written in C++ using MPI.
I got the following situation:
startingpoint.cpp is a c++ file including the cudaintegrator.h and
includes datastructure.h
cudaintegrator.h is the header file for a
cuda file including datastructure.h
cudaintegrator.cpp is the
implemenation of cudaintegrator.h
datastructure.h is a header file
specifing some datastructures
the files are organized like that:
/trunk/
/src
/folder1
/folder2
/startingpoint.cpp
/folder3
/cudaintegrator.h
/cudaintegrator.cpp
/folder4
/folder5
/datastructure.h
When I run nvcc from my trunk dir with the following command:
/usr/local/cuda/bin/nvcc -c -o src/folder1/folder3/cudaintegrator.o src/folder1/folder3/cudaintegrator.cu
the included file `#include "folder4/folder5/datastructure.h" is not found:
src/folder1/folder2/cudaintegrator.h:12:33: fatal error: folder4/folder5/datastructure.h: No such file or directory
When I run mpic++ for the compilation of startingpoint.cpp, which uses the same include, the datastructure.h is found.
I suspect that the working directory of nvcc and mpic++ are somehow different(?) even both are run from the trunk directory.
When I change the include to ../../folder4/folder5/datastructure.h the file itself is found, but subsequent includes fail for the same reason. I can not change the includes in all subsequent files because they can't be found by mpic++ in this case.
Does anyone have a suggestion how I should include the files in this situation correctly, or how to instruct nvcc to find the included files?
Providing include paths (-I) to the nvcc invocation should be enough (if not, it uses relative include paths only, that's why adding ../.. works for a single include).