7

I just upgraded to Xcode 5.1, and all of a sudden there is a new warning:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk/usr/lib/libz.dylib is a dynamic library, not added to the static library

The target which generates this warning is the cocos2d-iphone v2 static library (rather than use cocos2d templates, I create a static library). To create the static library all I did was add the cocos2d project to my workspace, have my project link to the libraries that cocos2d links to, and thats it. This all worked fine prior to this update, but now there is a warning.

How do I fix this ? I do not want to mess with the cocos2d project, because there are some projects in which I use the cocos2d template and not the static library.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
Rahul Iyer
  • 19,924
  • 21
  • 96
  • 190

1 Answers1

11

Static library targets can not link against dylibs. Previously this was simply ignored. You need to remove said dylib from the static library target and, if necessary, add it to each target that is building the actual app.

Look into the Link Binary with Libraries Build Phase. Knowing cocos2d there's probably an Other Linker Flag "-lz" that you need to remove from Build Settings of the cocos2d target.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • 2
    You should mention that static libraries aren't linked at all and that a `.a` file is a simple archive of object files, packaged from convenience and nothing else. – trojanfoe Mar 22 '14 at 10:08
  • 1
    True, if a static library target A requires static library target B then A does not need to link against it (it is ignored when building A). Consequently linking fails if the app target does not link against both static libs A and B, regardless of whether B is listed in the "link binary with libraries" build phase of target A. – CodeSmile Mar 22 '14 at 10:16
  • Indeed. This seems to be a constant source of confusion for many people. – trojanfoe Mar 22 '14 at 10:28
  • 1
    I found your answer unclear on exactly what I needed to do (since I don't have much xp with static libraries). If what I did makes sense perhaps you can update it for the benefit of others. I went to "Link Binary with Libraries" build phase of cocos2d's static library target, and I removed libz.dylib. The warning went away. I did not modify any linker flags. – Rahul Iyer Mar 23 '14 at 03:20
  • 1
    I did this but then I got a linker error. It did not work for me. – Xander Jul 24 '14 at 05:45
  • @LearnCocos2D what about system frameworks, what is the difference, why is there no warning? – entonio Nov 05 '14 at 13:21