views:

207

answers:

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 encoutered an implementation file (.m) wich 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 wich were successfully re-added.

Thanks in advance.

+3  A: 

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
Paul R
Thanks a lot! Worked immediately. I appreciate the quick response, this thing was driving me nuts ;-)
karsten
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.
Paul R
A: 

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.

cdespinosa
@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.
Paul R
A: 

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.