Mac app integration and call zipalign, Throw An Error dyld: Library not loaded: @rpath/libc++.dylib

Recently Packtool(an App create by electron) added autoupdate feature ,The premise is You have to sign your app。

There was something wrong with the android group today😂。

The problem was caused by using zipalign(a tool for optimizing the apk) which integration in Packtool optimized the apk.

Error:

dyld: Library not loaded: @rpath/libc++.dylib
  Referenced from: myAppName.app/Contents/Resources/tool/mac/zipalign
  Reason: image not found

Obviously, these log was printed by zipalign could not found libc++.dylib.

The reason is @rpath, for explaining of @rpath maybe this blog helpful.

In short,@rpath like a shell variable. zipalign will get the value of @rpath at runtime then join the /libc++.dylib.

In fact, at this, @rpath’value should be /usr/lib, So why couldn’t zipalign find the library. Finde answer in this blog

Follow these steps to solve:

open Terminal.app

install_name_tool -change @rpath/libc++.dylib /usr/lib/libc++.dylib myAppName.app/Contents/Resources/tool/mac/zipalign

The simple instructions of install_name_tool

what params install_name_tool support?

install_name_tool -h
Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool
 [-change old new] ... [-rpath old new] ... [-add_rpath new] ... [-delete_rpath old] ... [-id name] input

modify dynamic lib’s path

install_name_tool -change <app'@rpath value> <real value of dynamic lib> <app’s path>

Refer to the link

  1. MAC:@rpath的坑
  2. Xcode Build Settings中的变量@rpath,@loader_path,@executable_path
  3. install_name_tool解决dyld: Library not loaded