How to use modularized functions inside other modularized functions in C

44 views Asked by At

I'm doing a more complex project in c, but this example here is the same for what i need and the names of examples will just changed, but, again, is the same thing from what i am doing. Let's say I have this file structure:

|--project/
|--main.c
|--modules/
|   |--include/
|      |--module1.h
|      |--module2.h
|      |--module3.h
|   |--impl/
|      |--module1.c
|      |--module2.c
|      |--module3.c

Module2 uses functions I created and the implementated of my module1. Therefore, there is a dependence of module2 on module1. In other words, my module2 calls module1.

module1.h

#ifndef MODUL1_H
#define MODUL1_H

void functionModule1();

#endif

module2.h

#ifndef MODUL2_H
#define MODUL2_H

void functionModule2();

#endif

module3.h

#ifndef MODUL3_H
#define MODUL3_H

void functionModule3();

#endif

module1.c

#include "module1.h"
#include <stdio.h>

void functionModule1() {
    (...)
}

module2.c

#include "module2.h"
#include "module1.h"
#include <stdio.h>

void functionModule2() {
    functionModule1();
    (...)
}

module3.c

#include "module3.h"
#include "module2.h"
#include "module1.h"
#include <stdio.h>

void functionModule3() {
    functionModule2();
    (...)
}

main.c

#include "module3.h"
#include <stdio.h>

int main() {
    functionModule2();
    (...)
    return 0;
}

I am compiler the files in this way: gcc main.c module/impl/* -o a.out

But i receive an error:

fatal error: module1.h: Nonexistent file or directory
    1 | #include "module1.h"
      |          ^~~~~~~~~~~
compilation terminated.

fatal error: module2.h: Nonexistent file or directory
    1 | #include "module2.h"
      |          ^~~~~~~~~~~
compilation terminated.

fatal error: module3.h: Nonexistent file or directory
    1 | #include "module3.h"
      |          ^~~~~~~~~~~
compilation terminated.

What am i doing wrong?

I tried what I explained above;

0

There are 0 answers