-2
I was wondering how to divide a project into several files. I had created a project divided into 3 files first, one main. c (containing main function), a lib.c (implementing functions used in main.c) and a lib.h (containing prototypes of functions), "uniting" files using #include "lib.h" in main. c and lib.c - and it worked perfectly.
However, now I need to split the project (the same one I finished using only 3 files) into more files, e.g., main. c, lib1.c, lib1.h, lib2.c, lib2.h ... almost all functions being the same. But now I can’t 'make it work' and I get messages like:
"error: Dereferencing Pointer to incomplete type"
I would like to know how to "join" these files when compiling.
More information about my project: Many of the functions use implementations that are in other "file. c". I am using Codeblock and Devc++. A example of how the code is now:
main. c:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lib1.h"
#include "lib2.h"
#include "lib3.h"
...
int main()
{
...
[uso das funções...]
...
}
lib1.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lib1.h"
#include "lib2.h"
#include "lib3.h"
...
struct item1{
...
};
ITEM1* funcao1(ITEM2* lista, int valor)
{
...
}
ITEM1* funcao2(ITEM1* lista)
{
...
}
...
lib1.h
typedef struct item1 ITEM1;
ITEM1* funcao1(ITEM2* lista, int valor);
ITEM1* funcao1(ITEM1* lista);
...
lib2.h
typedef struct item2 ITEM2;
ITEM2* funcao5(...);
...
... (other files. c and file. h)
How do I make it work?
Po, who edits there my question edits wrong, together libraries. HAS MORE THAN ONE LIB... LIB1.H, LIB2.H, LIB3.H...
– Hobbit
Hobbit @L. edition does not seem to have removed anything http://answall.com/revisions/160260/2, but if something goes wrong just edit again, the edit only occurred because you used the Stacksnippets unnecessarily. Ps: I edited the title to be more intuitive to the problem ;)
– Guilherme Nascimento
@Hobbit I just normalized your post, didn’t remove anything, you just posted the 2 file snippet
.h
,lib1
andlib2
– Laerte
I’ve already edited, but I may have made a mistake, in which case I’m sorry.
– Hobbit
I understood that this is wrong. You should put the structs inside the files . h, because it is as if the main. c knows that there is a typedef struct but does not know what it has in struct.. (more or less that).
– Hobbit