Kevin217
Kevin217

Reputation: 752

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.

Upvotes: 0

Views: 44

Answers (1)

2501
2501

Reputation: 25752

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.

Upvotes: 1

Related Questions