Kevin217 Kevin217 - 28 days ago 16
C Question

C Makefile with header in other directories

Here's the sample structure.

main.c
|
--------------
|
dir0-"sum.h","sum.c"


sum
and
sub
are just two simple functions, located in
dir0
. They're called in
main.c
.

I'm trying to compile using gcc
gcc -Idir0 main.c sum.c -o main
.
But it throws an error that it cannot find
sum.c
.

Besides, how to use
-I
flag with two sub-directory.

Answer

The command should be:

 gcc -Idir0 main.c dir0/sum.c -o main 

Notice that sum.c is in a sub-directory and you have to tell the compiler that.

Comments