开发者

Adding an existing implementation file to an Xcode project won't work

As I write most of my code using MacVIM, I need to add the new files to the XCode project in order to compile them into the executable. Today however I encountered an implementation file (.m) which XCode won't allow to be added. It appears light gray in the appropriate finder w开发者_如何转开发indow as if it were already included in the project, but when I try to build, I get a linker error, stating that the symbol defined this implementation file could not be found. The corresponding header file could be added without problems.

Any idea what could have caused this problem?

Btw. I deleted a former version of the same file from the "Classes" tree before, as well as many others which were successfully re-added.


I think I saw a similar problem once with an old version of Xcode. IIRC the way I resolved it was to:

  • rename the source file (temporarily)
  • add the renamed file to the project
  • do a "Save As..." on the renamed file to get it back to the original name


The file is probably already in your project, but not in the target you're building. Use the Detail view and Search bubble to find it, Get Info, and in the Targets tab of the info window, check the check box for the target you're building.

The other answer (removing and re-adding) works because you end up removing it from the project, then when you re-add it, it's added to the current target by default.


I found that deleting my pbxuser file from inside the .xcodeproj solved the problem for me. There were references to the files I couldn't add in there, surprisingly. This has happened to me many times over the years.

Another trick is to:

  • Move the file into a different directory

  • Add it to the XCode project from there

  • Move it to the desired location

  • Select the file in Groups & Files

  • Choose File > Get Info from the menu bar. The full path will appear in red.

  • Press the Choose... button and select the file at the new location.


If you are using Xcode 4, you can do the following steps to add an existing file into your target:

1) Select your file in "Project navigator" view (aka. click your myfile.m file in the folder tree of Xcode)

2) Click menu item "View" => "Utilities" => "Show File inspector" (or use the shortcut "Alt + Command + 1)

3) There is one section called "Target Membership", check the target you want


I fixed this by deleting the .xcuserstate file and restarting the project. I am using a workspace file, for all it's worth.

You can find any and all referencing files via

grep -r -h [NameOfFileThatYouAreTryingToAdd] *

from within your project directory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜