0

I have the following project structure:

/source:
-- data_module_entry.c (main.c)
-- /data_module
-- -- data_process.c
-- -- data_process.h
-- /data_libs
-- -- data_stat.c
-- -- data_stat.h
-- -- data_io.c
-- -- data_io.h

I have functions from data_io.c and from data_process.c in data_module_entry.c.

Also data_process.c uses functions from data_stat.c.

But I can't properly set up a links between those files to make it work.

What should be the exact sequences of #include ""?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Arzental
  • 103
  • 6
  • `#include "../data_libs/data_io.h"` if including from a source file in one of your subdirectories. If including from the "main" file / root directory, then simply `#include "data_libs/data_io.h"` _etc_... – paddy Jul 26 '21 at 04:52
  • 2
    I disagree with the suggestion to use relative paths (see also [What are the benefits of a relative path such as `"../include/header"` for a header?](https://stackoverflow.com/q/597318/15168)). In this context, I think you should write `#include "data_module/data_process.h"` and `#include "data_libs/data_io.h"` (and `#include "data_libs/data_stat.h"`) in the source files (and in any headers that include other headers), and ensure that you specify `-I/source` or equivalent on the compiler command line. – Jonathan Leffler Jul 26 '21 at 05:49
  • 1
    "But I can't properly set up a links between those files to make it work." okay but... what problem do you see? What is your current include-sequence? How does the .h-files look? – Support Ukraine Jul 26 '21 at 06:13
  • Assuming that your .h files are written correctly (which we can't know), it's very simple. If X.c needs to call a function from Y.c then X.c must include Y.h. No magic... – Support Ukraine Jul 26 '21 at 06:18

1 Answers1

0

Actually I did it all fine, it wasn't really a problem. However, when I used gcc I specified only the file with main.c instead of enumerating all of the .c files.

Arzental
  • 103
  • 6