17

I am trying to integrate a large legacy C++ library with an iOS app. We are able to build and run on device but we are not able to archive the app. Archiving fails with the following error.

Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip failed with exit code 1

I did a -v on the strip and get a series of warnings similar to

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip: symbols referenced by relocation entries that can't be stripped in: /MyApp/DerivedData/SmartMusic_iPad/Build/Intermediates/ArchiveIntermediates/MyApp/IntermediateBuildFilesPath/UninstalledProducts/libMyLib-iOS.a(MyWhatever.o)

It is not clear if this message is a warning or the reason for the failure. There are no other indications of problems in the strip output. Any clues?

mfaani
  • 33,269
  • 19
  • 164
  • 293
HatAndBeard
  • 1,416
  • 3
  • 18
  • 31

9 Answers9

9

Under build settings for the static library target, select NO for 'deployment postprocessing' and 'strip debug symbols during copy'. It is compiled code so it doesn't need symbols stripped. I was experiencing the same error ('usr/bin/strip failed with exit code 1') and this fixed it for me.

donnadupuis
  • 91
  • 1
  • 2
6

In my case I added the following to my library Target build settings and started working fine:

  • Dead Code Stripping: NO

  • Strip Debug Symbols During Copy: NO for all configurations

  • Strip Style: Non-Global Symbols

Roberto Ferraz
  • 2,511
  • 24
  • 43
3

The default Strip Style in Xcode is All Symbols, which is okay for an executable but for a library you need to set this to Non-Global Symbols as global symbols must be be preserved.

Since stripping is only done as part of the deployment post processing, debug builds are usually not affected by this option as for them the setting DEPLOYMENT_POSTPROCESSING is usually set to NO. But when archiving, you create a release build and here DEPLOYMENT_POSTPROCESSING is set to YES by default and thus you need to have the correct strip style set.

Mecki
  • 125,244
  • 33
  • 244
  • 253
  • for me to have the smallest binary, is there a general rule for what I should strip and what I shouldn't strip? Asking for both my app and a linked binary (xcframework) – mfaani Jan 18 '23 at 14:52
  • @mfaani You can strip all symbols that are not required for dynamic linking. When a binary loads a library, it wants to access symbols of that library (functions, global variables, Obj-C classes, etc.) and those cannot be stripped, otherwise they would not be found when the binary loads the library. Usually the library does not access symbols of the loading binary, so these can all be stripped. Theoretically all symbols that you don't want to ever access could also be stripped from the library, e.g. functions you never call. The library itself can still call them directly (needs to symbol). – Mecki Jan 18 '23 at 23:52
  • @mfaani `All Symbols` will indeed strip everything. `Non-Global Symbols` strips all symbols that are only visible to the library itself, which is almost always okay as a binary cannot access those symbols anyway. You'd only need them if you want to dynamically access such a symbol from within the library itself (get the symbol by name, then use it) or for debugging purposes. If you access it statically (just use the symbol in your library code directly), this still works even after that symbol got stripped because the symbol is then referenced by address, not by name. – Mecki Jan 18 '23 at 23:56
  • @mfaani Note that instead of using one of the symbol classes above, you can also tell `strip` what exactly to strip or what exactly to keep. You can create a symbol file (just a text file, listing one symbol a line) and then tell `strip` to strip all symbols in that file or to strip all symbols except those in that file (if you like, combined with stripping debug or non-global ones). See setting `Additional Strip Flags` in Xcode and check the man page of `strip`: https://www.unix.com/man-page/osx/1/strip/ – Mecki Jan 19 '23 at 00:02
  • I opened a chat room. Because I thought we might be going back and forth https://chat.stackoverflow.com/rooms/251253/ios-stripping-symbols . I'm just not sure if I was able to add you to it correctly. Can you chime in whenever you get a chance? Or you prefer I follow up here... – mfaani Jan 19 '23 at 16:23
  • I didn't realize you replied to the chat. I checked it for the first day or two. Then I never checked it again. If you add replies into chats, but don't mention me, then I won't get notified. Nonetheless **Fantastic answer**. Thank you so much. I just placed a bounty on this question. It's for you :D. Do you mind just copying that detail into your answer here? – mfaani Apr 10 '23 at 15:36
  • @mfaani Sorry that I forgot to mention you. I'm glad the answer was useful for you. I also know to appreciate your bounty offer but my answer in the chat doesn't really fit the question that has been asked here and thus also would not fit my answer, so I decided against adding it here, as that would seem rather misplaced to me. – Mecki Apr 19 '23 at 08:50
2

I have same your problem, but I edit DEPLOYMENT POSTPROCESSING to NO but it doesn't work.

I just went to Build Phases tab in my target, and in Copy Bundle Resources I removed Foundation.framework, and then I add Foundation.framework into Link Binary With Libraries, it works for me!

Hope that will be solve your problem!

Tai Le
  • 8,530
  • 5
  • 41
  • 34
2

On Xcode 11.5, I solved this by setting Strip Linked Product to No in Build Settings of the Framework target.

Emre Eran
  • 236
  • 2
  • 4
1

There are different options to strip (see manpage) and I think you'll want to use the -r option. You can set the type of stripping to perform from within the Xcode project settings. See if you can relate the options in Xcode with the options in the manpage.

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
  • 1
    Note: you can explicitly set command line parameters for strip via the "Additional Strip Flags" option in Build Settings. Unfortunately, strip with "-r" still fails. – HatAndBeard Jul 31 '12 at 17:59
1

What worked for me was when I decided to fix another issue in Xcode 10.1, my simulator hadn't been booting up and I ignored until I really needed it, running the command below helped fix this issue

sudo chmod 1777 /private/tmp
Olli
  • 512
  • 3
  • 6
  • 22
1

I fixed this error by freeing up more space

Gbaba
  • 41
  • 2
0

In our project we have used InjectHotReload library to enable hot reload mechanism. This library caused for strip error. We removed from pod and also removed other linker flags which needed when setup InjectHotReload.

May someone see this and fix problem.

Good luck.