Search code examples
cgccincomplete-type

C Field has incomplete type, without forward declaration


I keep getting the "field has incomplete type error," but I can't find any forward declarations for that type in my code, or for any of the types in it's struct--aside from pointer fields. I tried recursive grep the folder, and still couldn't find any forward declarations.

How do I make GCC tell me where it thinks the forward declaration is? or why it's incomplete?

trying to compile this file:

https://github.com/pdJeeves/CreaturesLib/blob/master/src/biochemistry/emitter.c

gets the error on this include:

https://github.com/pdJeeves/CreaturesLib/blob/master/src/creature/creature.h

with the member

"struct Brain brain"


Solution

  • Your brain.h and organ.h both start with

    #ifndef _organ_h_
    #define _organ_h_
    

    This means the second one will not be included after you include the first one.

    It's unusual that you used #ifndef _something_h_ at several places inside brain.h. You should simply include relevant headers, instead of redefining their contents. I.e. simply #include lobe.h, instead of declaring an empty forward declaration like struct BrainLobe;.