XCode 4 Autocomplete with C++ library?
I am using Cocos2D Box2D template for my project.
When I type , "b2**" the autocomplete doesnt show any Box2开发者_Go百科D classes. (pressing ESC also doesnt show any ) I have included Box2D.h and Cocos2d.h in "Prefix.pch" file.
Is there any feature like "rebuild index" in "Eclipse CDT" ?
Any tips?
You can force Xcode to rebuild index by deleting it's service folder (DerivedData for Xcode 4.x):
- Close Xcode
- Remove service folder
- Open your project and Xcode will rebuild index again
In my case this always works and I can call b2... autosuggest.
The DerivedData folder can be found in ~/Library/Developer/Xcode/DerivedData
This may be an obvious suggestion, but have you tried to type out a class that you know exists with what you have included, and see if it recognizes it(With both colorization and/or quick help)? Also, do you have the necessary frameworks included, etc? As far as reloading goes, the only thing that you can do in XCode that I know of is clean(shift+cmd+k) and re-build. Are you getting any sort of warnings, errors, etc? Another potentially obvious issue, is XCode set to c++ as the language? Anyways hopefully you haven't already tried all of this and it helps you get somewhere.
Assuming you're using XCode 4, you can rebuild the index rather simply:
- Open the Organizer (Command+Shift+2)
- Click 'Projects' in the top section
- Select the project you want to rebuild the index for in the left sidebar
- Click 'Delete' next to 'Derived Data' in the center portion of the Organizer
This is easier than traversing through the directories and manually deleting a series of folders.
This page lists the steps another user went through to get code completion working for Xcode 4 and Box2D – the steps include deleting the derived data folder, but also changing user header search paths, making sure there were no spaces in the path to the project, and other things. Some of these steps may be random or unrelated, but apparently they fixed the problem for two people on that forum.
Combining all the above posts together, this is how I went about solving my issue:
1) Make sure that all files are in 1 folder. This may sound obvious, but I had my Box2D files not in the same folder as my other code. When creating a new project with XCode, it creates a folder with the name of your project, then another folder within that that has the name of the project again. Example: "{path of project}/TempProject/TempProject". I had my Box2D files in the first TempProject directory and not with the rest of my code that is created under the sub-directory of TempProject.
2) Open your project's settings by double clicking your project in XCode
3) Scroll down to "Search Paths"
4) Edit the "Header Search Paths" value to be: ${SOURCE_ROOT}/${PROJECT_NAME}/** (Note: If your Xcode does NOT create a subdirectory like mine does "TempProject/TempProject", then just use ${SOURCE_ROOT}/**)
5) Delete your project's Derived Data by doing 1 of the 2 following ways:
a) Open Organizer -> Select Projects -> Select your Project -> Select Delete next to Project's Derived Data
b) Open Finder -> Select Go from the toolbar -> type in "~/Library/Developer/XCode/DerivedData" -> Find and Delete desired project's folder
6) Restart Xcode
7) Clean and rebuild code
8) Code sense should now work!
精彩评论