3

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 window 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.

5 Answers 5

4

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
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot! Worked immediately. I appreciate the quick response, this thing was driving me nuts ;-)
Spooky coincidence - I haven't seen this problem for ages and then it happened to me again today - I had a .h file that refused to be added to the project and I had to resort to the above trick.
0

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.

1 Comment

@cdespinosa: Hi Chris - that might be the explanation in some cases, but I have definitely seen this as apparently buggy behaviour in Xcode. Today I noticed it because a global search and replace failed to modify a certain header, because it wasn't in the project - however I couldn't add it to the project without using the above trick - after that the search and replace worked fine.
0

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.

Comments

0

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.