Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode not rebuilding app when source file updated in dependent static library

Tags:

xcode

xcode4

I have encountered an issue with Xcode's implicit dependency checking and static libraries, which I believe to be a bug in Xcode (and have reported as such); I'm raising it here in case anyone else has any ideas about it. In brief, if an application depends on a static library, and a source file that is a component of the library is modified, Xcode rebuilds the library but does not relink the application, so the change is not seen in the application.

More specifically: I have a workspace that contains an application project and a static library project, such that the application calls a function in the library (and the result is visible in the application: e.g. the function returns text that is displayed in a label in the application). The static library is included in the "Link Binary with Libraries" build phase of the application target. Building from scratch causes the library to be built first, then the application, as expected (in other words, Xcode has detected the dependency).

Now, if I modify the text of the message in the library source file, then click the "build and run" button, Xcode correctly rebuilds the library, but fails to relink the application, so when the application runs, the unmodified message text is displayed.

I am running Xcode 4.5.1 under Mac OS X 10.8.2. In the scenario I reported, the application is an iOS single-view application and the static library function being called happens to be implemented in C++.

Currently I know of no workaround other than cleaning and rebuilding. Has anyone else seen this, or has any other insight? Thanks in advance.

like image 422
rsfinn Avatar asked Oct 19 '12 16:10

rsfinn


1 Answers

I had originally searched SO without success, but I must not have phrased my searches properly. However, while writing up my question, the "Similar Questions" list offered much better results, and I was able to find a workaround. In brief:

  • select the library in the Project Navigator
  • find the location in the File Inspector; it is probably "Relative to Group"
  • change it to "Relative to Build Products"

This fixed the issue in my test case; now the application is correctly rebuilt whenever the library's source code is modified. I did not find it necessary to manually edit the project.pbxproj file as suggested.

I would still claim this is a bug in Xcode, but at least now I have a workaround.

like image 179
rsfinn Avatar answered Nov 09 '22 21:11

rsfinn