main.cc:5:30: fatal error: folder/file.h: No such file or directory
Solution 1
This depends a bit on your C compiler, but "typically" when you include a file using the < ... >
syntax the compiler will only look for those header files in directories you have specified on the command line with the -I
flag, plus various built-in system directories.
Notably, it usually will not look in the current working directory, unless you explicitly add -I.
to the compile line.
Alternatively, if you use the " ... "
form of #include
, then it will look in the current working directory as well.
So, either switch to #include "folder/file.h"
, or else add -I.
to your compile line.
Solution 2
You need to use quotes instead of <>
for the include, this makes it that the compiler searches in the source file's directory first:
#include "folder/file.h"
Alternatively explicitly add the current directory to your include paths
g++ c -I. main.cc
Solution 3
Regarding you question, I think first you need tell the compiler, where is you head file, since you write your code as:
#include <folder/file.h>
I assumed that you store your file.h in $you/include/path/folder
, therefore, you need pass -I ${your/include/path/}
to compiler like:
gcc -I${your/include/path/} ...
be aware, you specified in your code the include as <dir/file.h>
, I think this kinds of define show following idea:
$main_include_path
|
+----folder1
|
+----folder2
|
.
.
.----folderN
Then, you can ONLY write makefile
to specified the include path to it father
razorsyntax
Time Traveller. I wrote and created Fire - Cryptocurrency Portfolio using Nativescript. https://www.biomance.com/
Updated on September 12, 2021Comments
-
razorsyntax over 2 years
When I use type
make
into Ubuntu terminal I get:main.cc:5:30: fatal error: folder/file.h: No such file or directory
The folder exists in the working directory and the file.h exists in the specified folder.
When I type
ls
it lists the folder and file in my working directory as well.Oddly enough, when I open it in geany and ask it to find the file in the
#include <folder/file.h>
it finds it without issue but when it builds it I get the error.
Is there a flag I need to set so it so it includes the folder? If so, what would that look like exactly?