In fact, this problem can find a lot of solutions on the Internet. Everyone's unified answer is
Otool-l Yourapp.app/contents/macos/yourapp
Run Install_name_tool According to the output information
How to use the Install_name_tool here
It's more complicated when you rely on a lot of third-party libraries, especially for libraries like Qt. Packing that call a trouble.
QT has an official document that tells you how to manually package a program, and also provides a MACDEPOTQT such a program. To help you pack.
However, MACDEPOTQT does not support other third-party libraries, and is not flexible, according to the official document of the way of manual packaging, Pit dad ah.
Say he is not a fake father, when you meet the symbols need you to knock orders, want to die in the mood arises spontaneously.
That's good. Do it yourself. Here I give a packaged Python script I write semi-finished, the idea is the same as the manual Knock Command, but with the script to automate the simultaneous recursive check and the missing library to the bundle directory. The library for QT is packaged in the script, and if you want to pack other dependent libraries, add the corresponding keywords in the keywordlist. Hope to be helpful to everyone.
[Python]View PlainCopy
- Import OS
- Import Sys
- Import commands
- Binaryname = "YourApp"
- Bundlename = "Yourapp.app"
- Bundleframeworkdir = "contents/frameworks/"
- Bundlebinarydir = "contents/macos/"
- Bundlelibrarylist = [];
- Systemframeworkdir = "/library/frameworks/"
- KeywordList = ["Qt"]
- #add more keywords to work better
- def haskeyword (word):
- For it in keywordlist:
- if Word.find (IT)! =-1:
- return True
- return False
- def findapp (name):
- return Name+bundlebinarydir+binaryname
- def getbundledependsinfo (APP):
- Dependlist = Commands.getoutput ("otool-l" + app). Replace ("\T", ""). Split ("\ n");
- del (dependlist[0])
- Dependlist = [Item.split ("") [0] for item in dependlist if Haskeyword (item)];
- return dependlist
- def copylibrary (base, SRC, DST):
- Systemfullpath = src
- print "library%s depend%s"% (Os.path.basename (base), Os.path.basename (DST))
- If not os.path.exists (DST):
- Bundlefullpath = Os.path.dirname (DST)
- Os.system ("mkdir-p%s"% (Bundlefullpath))
- Os.system ("cp%s%s"% (Systemfullpath, bundlefullpath))
- Infolist = Getbundledependsinfo (DST)
- Copydependfiles (DST, infolist)
- Os.system ("Install_name_tool-id @executable_path/... /frameworks/%s%s "% (src, DST))
- Os.system ("Install_name_tool-change%s @executable_path/.. /frameworks/%s%s "% (src, src, base))
- def getframeworkname (dirname):
- if Dirname.find ("framework") = =-1:
- return
- While not Dirname.endswith ("framework"):
- DirName = Os.path.dirname (dirname)
- return dirname
- def copyframeworkextdir (SRC):
- Syspath = Systemframeworkdir + src
- DestPath = ""
- If not os.path.exists (syspath):
- return
- Frameworkpath = Getframeworkname (Syspath)
- FrameworkName = Getframeworkname (src)
- Bundlepath = bundlename + "/" + Bundleframeworkdir + frameworkname + "/"
- For it in bundleframeworkextdir:
- DestPath = Bundlepath + it
- Srcpath = Frameworkpath + "/" + It
- If not os.path.exists (destpath) and os.path.exists (srcpath):
- print "copying%s%s"% (FrameworkName, it)
- Os.system ("cp-r%s%s"% (Srcpath, destpath))
- def copyframework (base, SRC, DST):
- Print "Framework%s depend%s"% (Os.path.basename (base), Os.path.basename (DST))
- Systemfullpath = Systemframeworkdir+src
- If not os.path.exists (DST):
- Bundlefullpath = Os.path.dirname (DST)
- Os.system ("mkdir-p%s"% (Bundlefullpath))
- Os.system ("cp%s%s"% (Systemfullpath, bundlefullpath))
- Copyframeworkextdir (SRC)
- Infolist = Getbundledependsinfo (DST)
- Copydependfiles (DST, infolist)
- ("Install_name_tool-id @executable_path/... /frameworks/%s%s "% (src, DST))
- Os.system ("Install_name_tool-id @executable_path/... /frameworks/%s%s "% (src, DST))
- Os.system ("Install_name_tool-change%s @executable_path/.. /frameworks/%s%s "% (src, src, base))
- def copydependfiles (Base, infolist):
- TargetDir = ""
- For it in infolist:
- TargetDir = bundlename + "/" + Bundleframeworkdir + it
- if It.find ("framework")! =-1:
- Copyframework (base, it, TargetDir)
- Else:
- Copylibrary (base, it, TargetDir)
- Def makebundledirs ():
- Os.system ("mkdir-p" + bundlename + "/" + Bundleframeworkdir)
- if __name__ = = "__main__":
- target = Findapp (Bundlename + "/")
- Makebundledirs ()
- Infolist = Getbundledependsinfo (target)
- Copydependfiles (target, infolist)
http://blog.csdn.net/livemylife/article/details/7294778
Application publishing and packaging under Mac (Python-written script, can be packaged with third party libraries)