Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Soft links and xcode projects

In other unix environments using soft links ("ln -s") is a handy way of "abstracting away" at the file system level what a file or directory actually contains, so that its contents can be easily changed without having to modify the original file or directory. In other words, if I have eg. three versions of the same file, and several projects share the usage of one of those files, I can easily change which version of the file those projects will use by simply making a softlink that points to the file I want, and make those projects depend on that softlink (they see it as a regular file). If I later want to change the file in question, I only need to change the softlink to point to another version of the file.


This is especially useful when dealing with a third-party library that gets regular updates. I can install the third-party library somewhere, with the version number of the library in the directory name, and have a more generic directory name as a softlink (as a concrete example, I could have a softlink named "cocos2d" pointing to a directory named "cocos2d-iphone-0.99.5"). If I update the library, I can install it in a new directory (eg. "cocos2d-iphone-1.0.1") and simply change the softlink to point to the new directory, and then recompile the projects that depend on it.


The problem is that Xcode doesn't like softlinks. I don't know if this is a feature of MacOS X in general, or a quirk in Xcode in particular. The problem is that Xcode doesn't want any softlinks in any of its paths, and instead always resolves where the softlink is really pointing to. Thus if I add, for example, the file "libraries/cocos2d/cocos2d-ios.xcodeproj" to the project, what ends up in the project is actually a reference to "libraries/cocos2d-iphone-0.99.5/cocos2d-ios.xcodeproj". Thus the whole softlink is circumvented, making it useless. If I update the library in question, I have to go through all the projects that use it and change the references to point to the new directory. This causes only needless extra work.


This resolving of softlinks only happens when adding a new file to the xcode project. Xcode doesn't seem to change them afterwards, if they already exist in the project. In the past I could get around this problem by editing the project file directly with a text editor and forcing the path to refer to the softlink. However, all the paths in xcode 4 projects seem to be obfuscated, making this impossible. Another possibility is to rename the directory in question with the name of the softlink, then add it to the project, then restore its original name and then add the soft link.


Is there any better way of doing this?

Posted on Aug 5, 2011 3:36 AM

Reply
5 replies

Aug 6, 2011 7:04 PM in response to WarpRulez

It is definitely an Xcode quirk. MacOS X uses that same system for dynamic libraries. I don't see any better way of doing it than your last suggestion of giving Xcode a real directory at first and then swapping that out with a link.


I think Xcode is designed for the "modern" programmer, who always uses the latest alpha and would never consider using some ancient, 4 month-old stable version. Greenhorns.

Aug 9, 2011 1:19 AM in response to etresoft

There's an additional problem with the trick of renaming the library directory, adding it to Xcode, then naming it back and creating the soft link, and it's related to svn. The problem is that svn breaks if you rename a versioned directory (which is a real pain in the a**). This wasn't really a problem before. However, now that Xcode 4 wants to support svn, it starts behaving in all kinds of strange ways if I try to use the renaming trick on a versioned directory. (We should really use git instead of svn, as git doesn't have this annoying problem, but I don't think that's going to happen anytime soon.)


So neither of the old tricks seem to be feasible anymore. Editing the Xcode project directly doesn't work anymore because for whatever reason paths are not in plaintext, and svn messes up the renaming trick.

Aug 26, 2011 8:36 AM in response to WarpRulez

Hello I have probably exact same problem with source files whereas a constant location (my softlink) points to different version of the sources in a repository. For example:

../MyProject/DependantProjetXyz could point to

../Repository/DependantProjectXyz/V1.0

../Repository/DependantProjectXyz/V1.1


My xcode project is setup with ../MyProject/DependantProjetXyz which is pretty useful as I don't need to update all the include and lib path everytime I update the dependancies.


The main problem I am facing is that if I have a compilation error in the dependancies, xcode isn't able to automatically bring me to the error. It simply open the file and position at the very first line in the file. No highlight.


I am forced to use contextual menu on the error then reveal in the log to find the line number and manually navigate to that line. In other words, I am almost back to good old command line compilation with separate text editor...


BTW, this was all working fine before upgrade to xcode 4.


Was a bug filed on this issue?

Soft links and xcode projects

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.