Tool/software: Code Composer Studio 12
Hello,
my question is not micricontroller specific, but a general programming question about header files, project structure and the error I got.
What I've learned about the structure so far: A header file (.h) contains the declaration of variables and functions, the source file (.c) contains the definition of variables and functions. The source files contain inclusions of header files, which contain the declaration of variables and functions, they use after the #include
. As various source files may include the same header file, the header file contains the following code to avoid multiple declarations:
#ifndef SOMETHING
#define SOMETHING
// code
#endif
I am trying to implement the lwIP library into my own project (I know about the example). I copied the complete lwIP folder into my project. During the building process I get multiple errors like this:
#10056 symbol "autoip_arp_reply" redefined: first defined in "./lwip/lwip-2.1.2/src/core/ipv4/autoip.obj"; redefined in "./lwip/utils/lwiplib.obj"
Only ./lwip/lwip-2.1.2/src/core/ipv4/autoip.c
contains a definition of autoip_arp_reply()
, but both files are including ./lwip/lwip-2.1.2/src/include/autoip.h
, which contains the declaration of autoip_arp_reply()
. And autoip.h
contains the structure shown above to avoid multiple declarations. For these reasons I don't understand the error message. First, it should be "redeclared", not "redefined" and even that shouldn't happen, because the #ifndef
code should prevent this.
Where is my mistake? How can this error happen? I want to understand this in general, not only to solve this particular issue. Thank you!