Yet More Reasons for Box2D Compilation IssuesPosted: February 4, 2012
And a one-shot, elegant solution.
More reasons for Box2D projects not compiling mostly boil down to a) various C++ vs. Objective C conventions and practices and b) build settings. If you are getting zillions of compile issues from a project, especially a tutorial or sample you pulled down from the web (and must have worked for someone, somewhere, once), the major culprits are often:
- wrong version of Box2D. Cocos2d and Box2D and all the various open source and 3rd party supplied tools you might use to “leverage” your productivity bring with them varying degrees of stability and varying practices with regard to “backward compatibility”. My initial impression is that, for most of the tools I am looking at or using, they are too new to be worried (yet?) about “installed base” and inconvenience for users (who are all, for the most part, using “free” stuff, I should note.) The wrong version may manifest itself with different API’s — different method names, different arguments, different assumptions about data types both internal and external (e.g. in a particular version of a package it is integrated with, but for which you have already installed a newer or different version — probably to work with some other project!). [I think there is a small point here related to how “free” open source stuff can turnout to be in some circumstances…]
- Objective C vs. C++ conventions. Where [ #import “constants.h” ] might compare in your brain to be congruent to [ #import <constants.h> ], look closely — they are different. It is easier to spot when you see these forms of compiler directives mixed together in the same code module — as they are in Cocos2DS and elsewhere. So this should lead to a check of “compiler directives” in your build settings. This should be the first thing you think of when you are getting “include file not found” even as you are staring at your project folder with ALL the necessary files in place.
- Code file naming conventions. With .h and .m files typically used in Xcode for Objective C, C++ conventions and compiler approaches to code type detection may vary. Remember C++ files should be .mm or .cpp — and in any event it is worth learning how to find read Xcode build file settings. There are specific directives about how the compiler should determine source code language, including what rules to use and how to apply them. Check it out.
- Near the top of my list of errors that were particularly strange — like “include file is missing” when it clearly is not — are error messages that say “Could not validate build due to missing Icon.png file. Icon.png must be 57×57 pixels and found as 0 x 0 pixels”. The file was there of course and easily verified to be the right size. In the end this, too, was a build file setting issue — in Xcode 4.2+ i “fixed” a project by setting “pre-compress png files” to “NO”. Not that i’d ever heard of that setting or tried to set it myself before.