Saifallah
Saifallah

Reputation: 56

Lexical or preprocessor error: file not found using box2d & cocos2d

I'm having this weird issue when building my project. The problem is as follows:

My friend and I are working on a project and we're exactly using the same xcode, cocos2d and box2d versions. His project compiles (builds) fine while mine gives this error when I do: cassert file not found.

I took a copy of his xcode.project but no problems whatsoever.

I hope this code summarizes better what I'm trying to say:

GameLayer.h
#import bla bla //the usual required files
@class myOwnClass1;
@class myOwnClass2;

myOwnClass1 *test1;
myOwnClass2 *test2;

Now I wanna include the GameLayer.h in either myOwnClass1.h or myOwnClass2.h using #import but it would give me the error! If I did @class GameLayer; no problems at all.

The thing is in my friend's project he's doing the #import without the error, which is super weird (at least for me)

Advice?

P.S. I know that changing the .m to .mm would solve it but, again, in my friend's project he's using the .m

Upvotes: 0

Views: 1616

Answers (3)

Madhav Sbss
Madhav Sbss

Reputation: 325

Here is how I fixed the issue. Cleaning up and recreating the project didn't seem to be a good idea for me.

There are a couple of answers on the web for this issue but they in each didn't help me solve the problem. One is on SO at

cassert file not found but i use Box2d template and the other is on cocos2d-iphone forum,

http://www.cocos2d-iphone.org/forums/topic/cannot-include-box2d-cassert-file-not-found-despite-every-file-being-mm/

Combining the two suggestions kind of worked for me -

  1. Rename all YOUR (not cocos2d or box2d files, just your project files) from .m to .mm
  2. Make sure that on each of the files, on the right pane, “Type” option is set to “Default – Objective C++ Source”

There was another issue for me specifically, may not be an issue for you, I was using the following signature for CCLabelTTF

CCLabelTTF *title = [CCLabelTTF labelWithString:@"Hello" dimensions:CGSizeMake(720.0f, 880.0f) alignment:UITextAlignmentLeft fontName:@"Arial" fontSize:34];

This is deprecated and caused errors all over the place. I am now using the following slightly modified version and the errors fixed -

CCLabelTTF *title = [CCLabelTTF labelWithString:@"Hello" dimensions:CGSizeMake(720.0f, 880.0f) hAlignment:kCCTextAlignmentRight fontName:@"Arial" fontSize:34];

My most recent writeup of this fix can be found at - http://indiangamer.com/how-i-fixed-the-cocos2d-box2d-include-file-not-found-error/

Upvotes: 0

Saifallah
Saifallah

Reputation: 56

For some reason it turned out that creating a new project from scratch solved the problem, I'll mark this as the correct answer for now unless someone else has another opinion.

Upvotes: 0

sergio
sergio

Reputation: 69027

I guess there is a mismatch of compiler settings between your project and your friend's.

In short: cassert is a C++ header file; you definitely need a C++ compiler to compile it.

Now, my guess is that in your friend's project, the GameLayer.m file is marked as a C++ file, though it has got a .m extension.

To verify that, open your project's (and your friend's) project.pbxproj file in a text editor and look for the GameLayer.m file. You will get this kind of entry:

    347F5D94158BA4840058BC21 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };

as you see, the lastKnownFileType key says sourcecode.c.objc: this identifies an Objective-C file. If you see sourcecode.cpp.objcpp, that means objective c++.

Hope this helps clarifying it.

Upvotes: 1

Related Questions