daniel
daniel

Reputation: 439

Compiling C file which includes other header files

I am trying to compile a file Mv.c like - g++ microtime.c Mv.c It gives an error - v.c:2:10: fatal error: microtime.h: No such file or directory 2 | #include <microtime.h>
My current directory has both microtime.h and microtime.c and Mv.c includes microtime.h I am not sure how to go about compiling it.
Since my main program Mv.c is using microtime.h do I need to compile microtime.c first and pass it as an argument to g++?
I got it compiled by using the command g++ -I. Mv.c microtime.o
where microtime.o I generated using g++ -c microtime.c
I am not sure why this command works and why we need to specify the extra -I. option when I have already created the compiled object file microtime.o

Upvotes: 0

Views: 592

Answers (1)

the busybee
the busybee

Reputation: 12683

If you write #include <microtime.h>, the compiler uses its list of system directories to look for the header file. By the option -I you add a directory to this list, and the compiler is happy.

To include project-local header files, use #include "microtime.h".

Read the chapter "Directory Options" in GCC's documentation to learn more.

Upvotes: 1

Related Questions