I\'ve been learning c++ and encountered the following question: I have a directory structure like:
- current directory
- Makefile
- include
- he
You can either add a -I
option to the command line to tell the compiler to look there for header files. If you have header files in include/
directory, then this command should work for you.
gcc -Iinclude/
Since, you are using makefile
, you can include this option in CFLAGS
macro in your makefile.
CFLAGS = -Iinclude/ -c -Wall
OR
You can include header files using #include "../include/header.h"
.
Perhaps change your include line:
#include "include/header.h"
Assuming that's where your header exists - I'm making that assumption from your makefile
You told the Makefile that include/header.h
must be present, and you told the C++ source file that it needs header.h
… but you did not tell the compiler where such headers live (i.e. in the "include" directory).
Do this:
CFLAGS = -c -Wall -Iinclude