-2

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"

Patrick Jeeves
  • 357
  • 2
  • 13
  • are you missing a header file (or path to it)? – Sourav Ghosh Jul 04 '16 at 14:12
  • 2
    Perhaps you could add the `struct` code to the question. – Groo Jul 04 '16 at 14:13
  • 3
    _Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example._ – Sourav Ghosh Jul 04 '16 at 14:14
  • 1
    It says it's incomplete, because it CANNOT find the forward declaration, so it cannot tell you where it should be :) We need actual code to help you. – Koshinae Jul 04 '16 at 14:20
  • The line that yielded the compiler error is GCC pointing out to you which variable type that is the cause. GCC can't tell you where code it cannot find is located, for obvious reasons. – Lundin Jul 04 '16 at 14:21
  • @Patrick Jeeves The problem is that the compiler is unable to think.:) – Vlad from Moscow Jul 04 '16 at 14:29
  • @Groo added the code... – Patrick Jeeves Jul 04 '16 at 14:52

1 Answers1

1

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;.

Groo
  • 45,930
  • 15
  • 109
  • 179