forked from LiangliangNan/PolyFit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
How_to_deploy_for_mac.txt
115 lines (91 loc) · 11.8 KB
/
How_to_deploy_for_mac.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
Note:
This is a log of the steps the first time I depolyed PolyFit on macOS. There are tools that can do all the tricks automatically.
0. Go to the directory where the bundle file locates.
1. Check what other libraries PolyFit links to using 'otool':
otool -L /Users/lnan/Projects/PolyFit/binary/PolyFit.app/Contents/MacOs/PolyFit
2. Create a Frameworks directory inside the bundle. This follows the macOS application convention. Then copy the frameworks into the new directory. As frameworks contain symbolic links, we use the -R option.
mkdir PolyFit.app/Contents/Frameworks
cp -R /Users/lnan/Qt5.11.0/5.11.0/clang_64/lib/QtCore.framework PolyFit.app/Contents/Frameworks/
cp -R /Users/lnan/Qt5.11.0/5.11.0/clang_64/lib/QtGui.framework PolyFit.app/Contents/Frameworks/
cp -R /Users/lnan/Qt5.11.0/5.11.0/clang_64/lib/QtOpenGL.framework PolyFit.app/Contents/Frameworks/
cp -R /Users/lnan/Qt5.11.0/5.11.0/clang_64/lib/QtWidgets.framework PolyFit.app/Contents/Frameworks/
cp -R /Users/lnan/Qt5.11.0/5.11.0/clang_64/lib/QtXml.framework PolyFit.app/Contents/Frameworks/
3. Then run 'install_name_tool' to set the identification names for the frameworks. The first argument after -id is the new name, and the second argument is the framework that we want to rename. The text @executable_path is a special dyld variable telling dyld to start looking where the executable is located. The new names specifies that these frameworks are located in the directory directly under the Frameworks directory.
install_name_tool -id @executable_path/../Frameworks/QtCore.framework/Versions/5/QtCore PolyFit.app/Contents/Frameworks/QtCore.framework/Versions/5/QtCore
install_name_tool -id @executable_path/../Frameworks/QtGui.framework/Versions/5/QtGui PolyFit.app/Contents/Frameworks/QtGui.framework/Versions/5/QtGui
install_name_tool -id @executable_path/../Frameworks/QtOpenGL.framework/Versions/5/QtOpenGL PolyFit.app/Contents/Frameworks/QtOpenGL.framework/Versions/5/QtOpenGL
install_name_tool -id @executable_path/../Frameworks/QtWidgets.framework/Versions/5/QtWidgets PolyFit.app/Contents/Frameworks/QtWidgets.framework/Versions/5/QtWidgets
install_name_tool -id @executable_path/../Frameworks/QtXml.framework/Versions/5/QtXml PolyFit.app/Contents/Frameworks/QtXml.framework/Versions/5/QtXml
4. Now, the dynamic linker knows where to look for QtCore and so on. We must ensure that PolyFit also knows where to find the library, using install_name_tool's -change mode. This basically comes down to string replacement, to match the identification names that we set earlier to the frameworks.
install_name_tool -change @rpath/QtCore.framework/Versions/5/QtCore @executable_path/../Frameworks/QtCore.framework/Versions/5/QtCore PolyFit.app/Contents/MacOS/PolyFit
install_name_tool -change @rpath/QtGui.framework/Versions/5/QtGui @executable_path/../Frameworks/QtGui.framework/Versions/5/QtGui PolyFit.app/Contents/MacOS/PolyFit
install_name_tool -change @rpath/QtOpenGL.framework/Versions/5/QtOpenGL @executable_path/../Frameworks/QtOpenGL.framework/Versions/5/QtOpenGL PolyFit.app/Contents/MacOS/PolyFit
install_name_tool -change @rpath/QtWidgets.framework/Versions/5/QtWidgets @executable_path/../Frameworks/QtWidgets.framework/Versions/5/QtWidgets PolyFit.app/Contents/MacOS/PolyFit
install_name_tool -change @rpath/QtXml.framework/Versions/5/QtXml @executable_path/../Frameworks/QtXml.framework/Versions/5/QtXml PolyFit.app/Contents/MacOS/PolyFit
5. Copy the .dylib files into the Contents/Frameworks inside the .app folder. The trick after that is convincing the executable to look for the library in its new location rather than the location it was in when you linked the executable. (If you do a "otool -L ./MyProgram.app/Contents/MacOS/MyProgram" you will see the places where the program is looking for shared libraries, and you will see that it is not looking for your .dylib file in the Frameworks folder, yet). To do that you use the 'install_name_tool' command, e.g.:
install_name_tool -change /the/old/path/to/the_library_name.dylib "@executable_path/../Frameworks/the_library_name.dylib" ./MyProgram.app/Contents/MacOS/MyProgram
NOTE: the "/the/old/path/to/the_library_name.dylib" should be that seen from the "otool -L" result.
For PolyFit, it is:
(Resolve dependencies for the lib3rd_qglviewer dylib)
----------------------
install_name_tool -change @rpath/QtOpenGL.framework/Versions/5/QtOpenGL @executable_path/../Frameworks/QtOpenGL.framework/Versions/5/QtOpenGL PolyFit.app/Contents/Frameworks/lib3rd_qglviewer.1.dylib
install_name_tool -change @rpath/QtWidgets.framework/Versions/5/QtWidgets @executable_path/../Frameworks/QtWidgets.framework/Versions/5/QtWidgets PolyFit.app/Contents/Frameworks/lib3rd_qglviewer.1.dylib
install_name_tool -change @rpath/QtGui.framework/Versions/5/QtGui @executable_path/../Frameworks/QtGui.framework/Versions/5/QtGui PolyFit.app/Contents/Frameworks/lib3rd_qglviewer.1.dylib
install_name_tool -change @rpath/QtCore.framework/Versions/5/QtCore @executable_path/../Frameworks/QtCore.framework/Versions/5/QtCore PolyFit.app/Contents/Frameworks/lib3rd_qglviewer.1.dylib
install_name_tool -change @rpath/QtXml.framework/Versions/5/QtXml @executable_path/../Frameworks/QtXml.framework/Versions/5/QtXml PolyFit.app/Contents/Frameworks/lib3rd_qglviewer.1.dylib
(Resolve dependencies for the main program)
----------------------
install_name_tool -change libbasic.1.dylib "@executable_path/../Frameworks/libbasic.1.dylib" PolyFit.app/Contents/MacOS/PolyFit
install_name_tool -change librenderer.1.dylib "@executable_path/../Frameworks/librenderer.1.dylib" PolyFit.app/Contents/MacOS/PolyFit
install_name_tool -change libmath.1.dylib "@executable_path/../Frameworks/libmath.1.dylib" PolyFit.app/Contents/MacOS/PolyFit
install_name_tool -change lib3rd_qglviewer.1.dylib "@executable_path/../Frameworks/lib3rd_qglviewer.1.dylib" PolyFit.app/Contents/MacOS/PolyFit
install_name_tool -change libmodel.1.dylib "@executable_path/../Frameworks/libmodel.1.dylib" PolyFit.app/Contents/MacOS/PolyFit
install_name_tool -change libmethod.1.dylib "@executable_path/../Frameworks/libmethod.1.dylib" PolyFit.app/Contents/MacOS/PolyFit
(Resolve dependencies for the librenderer dylib)
----------------------
install_name_tool -change libbasic.1.dylib "@executable_path/../Frameworks/libbasic.1.dylib" PolyFit.app/Contents/Frameworks/librenderer.1.dylib
install_name_tool -change libmath.1.dylib "@executable_path/../Frameworks/libmath.1.dylib" PolyFit.app/Contents/Frameworks/librenderer.1.dylib
install_name_tool -change libmodel.1.dylib "@executable_path/../Frameworks/libmodel.1.dylib" PolyFit.app/Contents/Frameworks/librenderer.1.dylib
(Resolve dependencies for the libmath dylib)
----------------------
install_name_tool -change libbasic.1.dylib "@executable_path/../Frameworks/libbasic.1.dylib" PolyFit.app/Contents/Frameworks/libmath.1.dylib
(Resolve dependencies for the libmodel dylib)
----------------------
install_name_tool -change libbasic.1.dylib "@executable_path/../Frameworks/libbasic.1.dylib" PolyFit.app/Contents/Frameworks/libmodel.1.dylib
install_name_tool -change libmath.1.dylib "@executable_path/../Frameworks/libmath.1.dylib" PolyFit.app/Contents/Frameworks/libmodel.1.dylib
(Resolve dependencies for the libmethod dylib)
----------------------
install_name_tool -change libbasic.1.dylib "@executable_path/../Frameworks/libbasic.1.dylib" PolyFit.app/Contents/Frameworks/libmethod.1.dylib
install_name_tool -change libmath.1.dylib "@executable_path/../Frameworks/libmath.1.dylib" PolyFit.app/Contents/Frameworks/libmethod.1.dylib
install_name_tool -change libmodel.1.dylib "@executable_path/../Frameworks/libmodel.1.dylib" PolyFit.app/Contents/Frameworks/libmethod.1.dylib
6. Plugins. We can put the plugins anywhere we want in the bundle, but the best location is to put them under Contents/Plugins.
mkdir PolyFit.app/Contents/Plugins
cp -R /Users/lnan/Qt5.11.0/5.11.0/clang_64/plugins/imageformats PolyFit.app/Contents/Plugins
cp -R /Users/lnan/Qt5.11.0/5.11.0/clang_64/plugins/platforms PolyFit.app/Contents/Plugins
Then using 'otool', we see that the plugin links to the Qt frameworks it was built against. As we want the plugins to use the framework in the application bundle, we change them the same way as we did for the application.
install_name_tool -change @rpath/QtGui.framework/Versions/5/QtGui @executable_path/../Frameworks/QtGui.framework/Versions/5/QtGui PolyFit.app/Contents/Plugins/platforms/libqcocoa.dylib
install_name_tool -change @rpath/QtCore.framework/Versions/5/QtCore @executable_path/../Frameworks/QtCore.framework/Versions/5/QtCore PolyFit.app/Contents/Plugins/platforms/libqcocoa.dylib
install_name_tool -change @rpath/QtWidgets.framework/Versions/5/QtWidgets @executable_path/../Frameworks/QtWidgets.framework/Versions/5/QtWidgets PolyFit.app/Contents/Plugins/platforms/libqcocoa.dylib
install_name_tool -change @rpath/QtPrintSupport.framework/Versions/5/QtPrintSupport @executable_path/../Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport PolyFit.app/Contents/Plugins/platforms/libqcocoa.dylib
7. CGAL dylib.
cp -R /opt/local/lib/libCGAL.13.dylib PolyFit.app/Contents/Frameworks/
cp -R /opt/local/lib/libgmp.10.dylib PolyFit.app/Contents/Frameworks/
cp -R /opt/local/lib/libmpfr.6.dylib PolyFit.app/Contents/Frameworks/
install_name_tool -change /opt/local/lib/libgmp.10.dylib "@executable_path/../Frameworks/libgmp.10.dylib" PolyFit.app/Contents/Frameworks/libmpfr.6.dylib
install_name_tool -change /opt/local/lib/libCGAL.13.dylib "@executable_path/../Frameworks/libCGAL.13.dylib" PolyFit.app/Contents/Frameworks/libmethod.1.dylib
install_name_tool -change /opt/local/lib/libgmp.10.dylib "@executable_path/../Frameworks/libgmp.10.dylib" PolyFit.app/Contents/Frameworks/libmethod.1.dylib
install_name_tool -change /opt/local/lib/libmpfr.6.dylib "@executable_path/../Frameworks/libmpfr.6.dylib" PolyFit.app/Contents/Frameworks/libCGAL.13.dylib
install_name_tool -change /opt/local/lib/libgmp.10.dylib "@executable_path/../Frameworks/libgmp.10.dylib" PolyFit.app/Contents/Frameworks/libCGAL.13.dylib
8. Boost dylib.
cp -R /opt/local/lib-/libboost_thread-mt.dylib PolyFit.app/Contents/Frameworks/
cp -R /opt/local/lib-/libboost_system-mt.dylib PolyFit.app/Contents/Frameworks/
cp -R /opt/local/lib-/libboost_chrono-mt.dylib PolyFit.app/Contents/Frameworks/
cp -R /opt/local/lib-/libboost_date_time-mt.dylib PolyFit.app/Contents/Frameworks/
cp -R /opt/local/lib-/libboost_atomic-mt.dylib PolyFit.app/Contents/Frameworks/
install_name_tool -change /opt/local/lib/libboost_thread-mt.dylib "@executable_path/../Frameworks/libboost_thread-mt.dylib" PolyFit.app/Contents/Frameworks/libCGAL.13.dylib
install_name_tool -change /opt/local/lib/libboost_system-mt.dylib "@executable_path/../Frameworks/libboost_system-mt.dylib" PolyFit.app/Contents/Frameworks/libCGAL.13.dylib
install_name_tool -change /opt/local/lib/libboost_chrono-mt.dylib "@executable_path/../Frameworks/libboost_chrono-mt.dylib" PolyFit.app/Contents/Frameworks/libCGAL.13.dylib
install_name_tool -change /opt/local/lib/libboost_date_time-mt.dylib "@executable_path/../Frameworks/libboost_date_time-mt.dylib" PolyFit.app/Contents/Frameworks/libCGAL.13.dylib
install_name_tool -change /opt/local/lib/libboost_atomic-mt.dylib "@executable_path/../Frameworks/libboost_atomic-mt.dylib" PolyFit.app/Contents/Frameworks/libCGAL.13.dylib
install_name_tool -change /opt/local/lib/libboost_system-mt.dylib "@executable_path/../Frameworks/libboost_system-mt.dylib" PolyFit.app/Contents/Frameworks/libboost_thread-mt.dylib
install_name_tool -change /opt/local/lib/libboost_system-mt.dylib "@executable_path/../Frameworks/libboost_system-mt.dylib" PolyFit.app/Contents/Frameworks/libboost_chrono-mt.dylib