import "cocos2d.h" works in some files, but not all

Rahul Iyer picture Rahul Iyer · Mar 21, 2012 · Viewed 7.3k times · Source

Here is what I did:

In Xcode 4.3.1

File -> New -> Project -> Single view application

Dragged the file cocos2d-ios.xcodeproj into navigator.

In build phases settings : Added : libcocos2d.a (becomes highlighted in red), as a linked library (required).

Added OpenGles.framework, Quartzcore, and libz.dylib

Changed build settings - Set "Always Search User Paths" to YES Added cocos2d source directory to "User Header Search Paths"

Now, it seems I can type: import "cocos2d.h" , in the app delegate and root view controller that Xcode created. But if I create a new file, and I add the line "import "cocos2d.h"" to the top, Xcode complains that the file is not found. But it seems to build fine. Also, in this new file code sense does not work.

What should I do? Why can I import only in the files that Xcode created? Is there some setting I need to change so that in the files I create, I can import cocos2d ?

EDIT: It seems to build and run fine. I can call methods in the cocos2d api. code sense just doesn't seem to see cocos2d.h in the new files I create.

EDIT - it seems that code sense suggests cocos2d.h when i type : import " But it does not suggest classes / methods from the cocos2d api.

Answer

Rahul Iyer picture Rahul Iyer · Mar 22, 2012

Turns out I had only added the "user header search paths" to my target, but not in the project settings.

Adding it fixed the problem. I guess the reason it compiled fine was because I had added it to the target, but it didn't work in the text editor since I hadn't added it to the project.