How Do You Troubleshoot the C Error “No such file or directory…compilation terminated”?

Problem scenario
You try to compile a C program, but it fails with "compilation terminated." The error message says "foobar/foobar.h No such file or directory." What should you do?

Solution
This solution does not address where should header files for c go. But it addresses the problem.
Find where foobar.h is: sudo find / -name foobar.h

Run the gcc command again, but with the flag -I/path/to/ nameofc.c

# where /path/to/ is the directory that houses "foobar" that has the file "foobar.h" in it.
# and "nameofc.c" is the name of the c program you are trying to compile.

Leave a comment

Your email address will not be published. Required fields are marked *