Page 1 of 1

compile errors w/ ShipDesign

Posted: Thu May 30, 2013 6:13 pm
by Dilvish
Hi, so today I'm getting compile errors apparently related to ShipDesign.cpp and/or Condition.cpp. I'm not sure what's up though since it looks like neither of those was touched for over a week. It's been a few days or so since I last compiled, but I thought it was within the past week, while sorting out the issue with Version.cpp.

Later today I'll try to step through revisions to see where the trouble starts, but just in case anything comes to mind for someone, here's the errors I'm getting (and I already tried clearing out all cmake cache files):

Code: Select all

FO@amber:~/Downloads/FreeOrion$ make -j2
[  1%] Building CXX object CMakeFiles/core.dir/universe/Condition.cpp.o
[ 16%] Built target parse
[ 17%] Built target ltdl
[ 23%] Built target log4cpp
[ 24%] Building CXX object CMakeFiles/core.dir/universe/PopCenter.cpp.o
/home/FO/Downloads/FreeOrion/universe/Condition.cpp:3215:69: error: incomplete type ‘ShipDesign’ used in nested name specifier
/home/FO/Downloads/FreeOrion/universe/Condition.cpp: In function ‘int {anonymous}::NumberOnQueue(const ProductionQueue&, BuildType, int, const string&, int)’:
/home/FO/Downloads/FreeOrion/universe/Condition.cpp:3229:34: error: incomplete type ‘ShipDesign’ used in nested name specifier
/home/FO/Downloads/FreeOrion/universe/Condition.cpp:3235:80: error: ‘GetShipDesign’ was not declared in this scope
/home/FO/Downloads/FreeOrion/universe/Condition.cpp:3236:50: error: invalid use of incomplete type ‘const class ShipDesign’
In file included from /home/FO/Downloads/FreeOrion/universe/Fleet.h:5:0,
                 from /home/FO/Downloads/FreeOrion/universe/Condition.cpp:7:
/home/FO/Downloads/FreeOrion/universe/Universe.h:30:7: error: forward declaration of ‘const class ShipDesign’
/home/FO/Downloads/FreeOrion/universe/Condition.cpp: In member function ‘virtual void Condition::Enqueued::Eval(const ScriptingContext&, Condition::ObjectSet&, Condition::ObjectSet&, Condition::SearchDomain) const’:
/home/FO/Downloads/FreeOrion/universe/Condition.cpp:3304:77: error: incomplete type ‘ShipDesign’ used in nested name specifier
/home/FO/Downloads/FreeOrion/universe/Condition.cpp: In member function ‘virtual bool Condition::Enqueued::Match(const ScriptingContext&) const’:
/home/FO/Downloads/FreeOrion/universe/Condition.cpp:3428:73: error: incomplete type ‘ShipDesign’ used in nested name specifier
/home/FO/Downloads/FreeOrion/universe/Condition.cpp: In member function ‘virtual bool Condition::DesignHasHull::Match(const ScriptingContext&) const’:
/home/FO/Downloads/FreeOrion/universe/Condition.cpp:3800:27: error: invalid use of incomplete type ‘const class ShipDesign’
In file included from /home/FO/Downloads/FreeOrion/universe/Fleet.h:5:0,
                 from /home/FO/Downloads/FreeOrion/universe/Condition.cpp:7:
/home/FO/Downloads/FreeOrion/universe/Universe.h:30:7: error: forward declaration of ‘const class ShipDesign’
/home/FO/Downloads/FreeOrion/universe/Condition.cpp: In member function ‘bool {anonymous}::DesignHasPartSimpleMatch::operator()(const UniverseObject*) const’:
/home/FO/Downloads/FreeOrion/universe/Condition.cpp:3850:59: error: invalid use of incomplete type ‘const class ShipDesign’
In file included from /home/FO/Downloads/FreeOrion/universe/Fleet.h:5:0,
                 from /home/FO/Downloads/FreeOrion/universe/Condition.cpp:7:
/home/FO/Downloads/FreeOrion/universe/Universe.h:30:7: error: forward declaration of ‘const class ShipDesign’
/home/FO/Downloads/FreeOrion/universe/Condition.cpp: In member function ‘bool {anonymous}::DesignHasPartClassSimpleMatch::operator()(const UniverseObject*) const’:
/home/FO/Downloads/FreeOrion/universe/Condition.cpp:3975:59: error: invalid use of incomplete type ‘const class ShipDesign’
In file included from /home/FO/Downloads/FreeOrion/universe/Fleet.h:5:0,
                 from /home/FO/Downloads/FreeOrion/universe/Condition.cpp:7:
/home/FO/Downloads/FreeOrion/universe/Universe.h:30:7: error: forward declaration of ‘const class ShipDesign’
/home/FO/Downloads/FreeOrion/universe/Condition.cpp:3978:21: error: expected primary-expression before ‘const’
/home/FO/Downloads/FreeOrion/universe/Condition.cpp:3978:21: error: expected ‘)’ before ‘const’
/home/FO/Downloads/FreeOrion/universe/Condition.cpp:3979:25: error: ‘part_type’ was not declared in this scope
/home/FO/Downloads/FreeOrion/universe/Condition.cpp: In member function ‘virtual bool Condition::PredefinedShipDesign::Match(const ScriptingContext&) const’:
/home/FO/Downloads/FreeOrion/universe/Condition.cpp:4100:25: error: invalid use of incomplete type ‘const class ShipDesign’
In file included from /home/FO/Downloads/FreeOrion/universe/Fleet.h:5:0,
                 from /home/FO/Downloads/FreeOrion/universe/Condition.cpp:7:
/home/FO/Downloads/FreeOrion/universe/Universe.h:30:7: error: forward declaration of ‘const class ShipDesign’
/home/FO/Downloads/FreeOrion/universe/Condition.cpp:4104:39: error: invalid use of incomplete type ‘const class ShipDesign’
In file included from /home/FO/Downloads/FreeOrion/universe/Fleet.h:5:0,
                 from /home/FO/Downloads/FreeOrion/universe/Condition.cpp:7:
/home/FO/Downloads/FreeOrion/universe/Universe.h:30:7: error: forward declaration of ‘const class ShipDesign’
/home/FO/Downloads/FreeOrion/universe/Condition.cpp: In member function ‘bool {anonymous}::NumberedShipDesignSimpleMatch::operator()(const UniverseObject*) const’:
/home/FO/Downloads/FreeOrion/universe/Condition.cpp:4135:32: error: incomplete type ‘ShipDesign’ used in nested name specifier
/home/FO/Downloads/FreeOrion/universe/Condition.cpp: In member function ‘virtual bool Condition::PredefinedShipDesign::Match(const ScriptingContext&) const’:
/home/FO/Downloads/FreeOrion/universe/Condition.cpp:4105:1: warning: control reaches end of non-void function [-Wreturn-type]
make[2]: *** [CMakeFiles/core.dir/universe/Condition.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
[ 27%] Built target pagedgeometry
make[1]: *** [CMakeFiles/core.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 52%] Built target GiGi
make: *** [all] Error 2

Re: compile errors w/ ShipDesign

Posted: Thu May 30, 2013 7:16 pm
by adrian_broher
Revision 6087 removes the MultiplayerCommon.h include from the ValueRef.h header. Just add a ShipDesign.h include to Condition.cpp.

Re: compile errors w/ ShipDesign

Posted: Thu May 30, 2013 8:20 pm
by Dilvish
adrian_broher wrote:Revision 6087 removes the MultiplayerCommon.h include from the ValueRef.h header. Just add a ShipDesign.h include to Condition.cpp.
Ah, great -- that plus in ValueRef.h a <set> (which had also been provided via MultiplayerCommon.h) fixed things up for me. I went ahead and committed those two additions.

Thanks!

Re: compile errors w/ ShipDesign

Posted: Fri May 31, 2013 9:08 am
by em3
I don't want to sound offensive, but I always thought that relying on header files to include other header files you need is a bad programming practice... Is there a reason to group the headers into one common header?

Re: compile errors w/ ShipDesign

Posted: Fri May 31, 2013 12:16 pm
by Bigjoe5
em3 wrote:I don't want to sound offensive, but I always thought that relying on header files to include other header files you need is a bad programming practice... Is there a reason to group the headers into one common header?
It's (probably) less a question of intentionally grouping all the headers together into one common header, but rather one of someone needing to use a class that was already included in a previously included header, and not bothering to add the header to the file they were working on directly, because it already worked.

There is something to be said for including a file directly everywhere it's needed (i.e. we avoid issues like this), but there's not really any good way that I know of to do so, without checking your includes every time you use a particular datatype, and I'm certainly not aware of any quick way to apply such a policy to a large, existing project (though perhaps adrian_broher has something up his sleeve - he seems to know a lot of project-refactoring tricks).

Re: compile errors w/ ShipDesign

Posted: Fri May 31, 2013 1:23 pm
by adrian_broher
Bigjoe5 wrote:There is something to be said for including a file directly everywhere it's needed (i.e. we avoid issues like this), but there's not really any good way that I know of to do so, without checking your includes every time you use a particular datatype, and I'm certainly not aware of any quick way to apply such a policy to a large, existing project (though perhaps adrian_broher has something up his sleeve - he seems to know a lot of project-refactoring tricks).
Not really. You can use serveral tools like iwyu or deheader to solve this automatically, but those are usually compiler specific (CLANG in this case).

You can do the same manually by creating a dependency graph from the includes (it's a bit of bash and graphviz magic) after that you just look up the include highest in the hierarchy and remove it. After that you recompile and add the missing includes in the cpp files, and add forward declarations and includes as needed to the header files. You repeat this until the unnecessary includes are gone. It's a bit tedious but with ccache not that time consuming as you would expect.

Re: compile errors w/ ShipDesign

Posted: Fri May 31, 2013 1:49 pm
by em3
Bigjoe5 wrote:
em3 wrote:I don't want to sound offensive, but I always thought that relying on header files to include other header files you need is a bad programming practice... Is there a reason to group the headers into one common header?
It's (probably) less a question of intentionally grouping all the headers together into one common header, but rather one of someone needing to use a class that was already included in a previously included header, and not bothering to add the header to the file they were working on directly, because it already worked.
Yeah, that IS the best practice, I think.