Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

main.cc:5:30: fatal error: folder/file.h: No such file or directory

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?

like image 972
razorsyntax Avatar asked Jan 28 '14 14:01

razorsyntax


2 Answers

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.

like image 154
MadScientist Avatar answered Nov 02 '22 11:11

MadScientist


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
like image 42
rubenvb Avatar answered Nov 02 '22 11:11

rubenvb