Honestly I'm not used to working in c and maybe I'm wrong as I approach the problem.
I have 3 files and I need to pass data from one to another
//main.c #include <stdio.h> #include "process.h" #include "readFile.h" int main() { int numIn=2, numOut=1; struct data *allData=readData(numIn, numOut); process(allData, numIn, numOut); return 0; } // readFile.h #include <stdio.h> #include <stdlib.h> struct data { double *in; double *out; }; struct data * readData(int numIn, int numOut) { //here I initialize and fill an "allData" array of struct data return allData; } //process.h #include <stdio.h> #include <stdlib.h> #include "readFile.h" int process(struct data * allData, int numIn, int numOut) { return 0; } If I delete "process.h" and try to print "allData" in the main, the correct data are printed without errors, but when I try to process the data in "process.h" I get this compilation error:
In file included from C:\...\main.c:4:0: C:\...\readFile.h:11:8: error: redefinition of 'struct data' struct data ^ In file included from C:\...\process.h:11:0, from C:\...\main.c:2: C:\...\readFile.h:11:8: note: originally defined here struct data ^ In file included from C:\...\main.c:4:0: C:\...\readFile.h:24:15: error: conflicting types for 'readData' struct data * readData(int numIn, int numOut) ^ In file included from C:\...\process.h:11:0, from C:\...\main.c:2: C:\...\readFile.h:24:15: note: previous definition of 'readData' was here struct data * readData(int numIn, int numOut) ^
structs. Your issue is that you've defined a non-inline function in a header file, so it gets compiled and linked multiple times. Function definitions must either be in source (.c) files or must be inline.