How_to_build_Slic3r.txt 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. How to build Slic3r on Mac OS X 10.7 Lion 64bit
  2. ---------------------------------------------
  3. Vojtech Bubnik, 2016-04-26
  4. 1) Install Mac OS X 10.7 Lion 64 bit with X Code
  5. ------------------------------------------------
  6. One has to build the OSX Slic3r on a real Mac, either directly on the system, or on a virtualized OSX. On Mac, two commercial solutions are available to legally virtualize MacOS on MacOS:
  7. http://www.parallels.com/eu/products/desktop/
  8. http://www.vmware.com/products/workstation/
  9. Installation of a X Code on an OS X 10.7 Lion needs a bit of work. The latest X Code supported by the Lion on a Virtual Box is 4.21. The trouble is, the certificates of the X Code 4.21 installation package expired. One way to work around the certificate is to flatten the installation package by unpacking and repacking it:
  10. pkgutil --expand Foobar.pkg foobar
  11. pkgutil --flatten foobar barfoo.pkg
  12. The flattened package is available here:
  13. \\rs.prusa\Development\Slic3r-Prusa\installxcode_421_lion_fixed.pkg
  14. This installer does not install the X Code directly. Instead, it installs another installer with a set of 47 pkg files. These files have their certificates expired as well. You will find the packages on your MacOS here:
  15. /Applications/Install Xcode.app/Contents/Resources/Packages/
  16. It is best to flatten them in a loop:
  17. cd /Applications/Install\ Xcode.app/Contents/Resources/Packages/
  18. for f in *.pkg; do
  19. pkgutil --expand $f /tmp/$f
  20. rm -f $f
  21. pkgutil --flatten /tmp/$f $f
  22. done
  23. After that, you may finish the installation of Xcode by running
  24. /Applications/Install\ Xcode.app
  25. 1b) Installing the Xcode on a newer system
  26. -------------------------------------------
  27. You will need to register as an Apple developer on
  28. https://developer.apple.com/
  29. log in and download and install Xcode
  30. https://developer.apple.com/downloads/
  31. You will likely need to download and install Xcode Command Line Tools, though the Xcode 4.1 came with the command line tools installed.
  32. 2) Prepare the development environment
  33. --------------------------------------
  34. Install the brew package manager:
  35. http://brew.sh/
  36. The brew package manager requires the git command line tool. Normally the git tool is installed as part of the Xcode command line tools.
  37. Copy and execute a command line from the top of http://brew.sh/ . It is possible, that the invocation of git fails because of some parameters the old git does not recognize. If so, invoke the git call manually.
  38. Compile the boost library using brew. Following line compiles a 64bit boost with both static and shared libraries.
  39. brew install boost --universal
  40. Install dylibbundler tool. The dylibbundler tool serves to collect dependent dynamic libraries and fix their linkage. Execute
  41. brew install dylibbundler
  42. 3) Install perl
  43. ---------------
  44. We don't want to distribute perl pre-installed on the Mac OS box. First, the system perl installation is not correct on some Mac OS versions, second it is not rellocatable. To compile a 64bit rellocatable perl, we use the perlbrew distribution. The perlbrew distribution installs into a user home directory and it allows switching between multiple versions of perl.
  45. http://perlbrew.pl/
  46. First install perlbrew
  47. \curl -L http://install.perlbrew.pl | bash
  48. Then compile the newest perl with the rellocatable @INC path and with multithreading enabled, execute following line:
  49. perlbrew install --threads -Duserelocatableinc --switch perl-5.22.0
  50. The --switch parameter switches the active perl to the currently compiled one.
  51. Available perl versions could be listed by calling
  52. perlbrew available
  53. Initialize CPAN, install PAR and PAR::Packer modules
  54. execute cpan command, from the cpan prompt, run
  55. install App::cpanminus
  56. install PAR
  57. install PAR::Packer
  58. quit
  59. 4) Download and install Slic3r
  60. ------------------------------
  61. git clone git://github.com/alexrj/Slic3r
  62. cd Slic3r
  63. perl Build.PL
  64. Now Slic3r shall be compiled. You may try to execute
  65. perl slic3r.pl
  66. to get a help screen, or
  67. perl slic3r.pl some_model.stl
  68. to have the model sliced.
  69. 5) Download and compile the GUI libraries needed to execute Slic3r in GUI mode
  70. ------------------------------------------------------------------------------
  71. For the current Slic3r 1.2.30 code base, set the environment variable SLIC3R_STATIC to link a static version of the boost library:
  72. export SLIC3R_STATIC=1
  73. then execute
  74. perl Build.PL --gui
  75. and keep your fingers crossed. The Build.PL script downloads and compiles the WxWidgets 3.0 through a Alien::Wx PERL package. The WxWidget shared libraries will land into
  76. ~/perl5/perlbrew/perls/perl-5.22.1/lib/site_perl/5.22.1/darwin-thread-multi-2level/Alien/wxWidgets/
  77. On Maverics, we experienced following issue compiling WxPerl:
  78. http://wiki.bolay.net/doku.php?id=acdsn:acdsn-a:mac
  79. Now you could run the GUI version of slic3r by calling
  80. perl slic3r.pl --gui
  81. If some dependency is missing, the MacOS system will let you know.
  82. 6) Packing the Slic3r
  83. ---------------------
  84. Perl is an operating system on its own. Many modules are shared among multiple applications and it is difficult to extract a stand-alone application from a perl installation manually. Fortunately, tools are available, which automate the process to some extent. One of the tools is the PAR::Packer. The PAR::Packer tool (pp executable) is able to create a standalone executable for a perl script. The standalone executable contains a PAR archive (a zip file) bundled with a perl interpreter. When executed, the bundled executable will decompress most of the PAR archive into a temp folder. Because of that, we will use the PAR::Packer to resolve and collect the dependencies, but we will create an installer manually.
  85. The PAR::Packer could analyze the dependencies by a statical analysis, or at a runtime. The statical analysis does not resolve the dynamically loaded modules. On the other side, the statical analysis is pessimistic, therefore it often collects unneeded packages. The dynamic analysis may miss some package, if not all branches of a code are executed. We will try to solely depend on the dynamic analysis to keep the installation size minimal. We may need to develop a protocol or an automatic UI tool to exercise as much as possible from the Slic3r GUI to pack the GUI version reliably. Once a reliable list of dependencies is collected, we may not need the PAR::Packer anymore.
  86. To create a PAR archive of a command line slic3r, execute
  87. pp -e -p -x slic3r.pl --xargs cube.stl -o slic3r.par
  88. and let the slic3r slice a cube.stl to load the dynamic modules.
  89. To create a PAR archive of a GUI slic3r, execute
  90. pp -e -p -x slic3r.pl --xargs --gui -o slic3r.par
  91. and exercise the slic3r gui to load all modules.
  92. Rename the slic3r.par file to slic3r.zip and decompress. Most of the code needed to execute Slic3r is there, only the perl executable is missing for the command line slic3r, and the WxWidgets shared libraries and the liblzma shared library are missing for the GUI version.
  93. 7) Collecting the dependent shared libraries, making the link paths relative
  94. ----------------------------------------------------------------------------
  95. We have linked Slic3r against a static boost library, therefore the command line slic3r is not dependent on any non-system shared library. The situation is different for the GUI slic3r, which links dynamically against WxWidgets and liblzma.
  96. The trick developed by Apple to allow rellocable shared libraries is to addres a shared library relatively to the path of the executable by encoding a special token @executable_path at the start of the path. Unfortunately the libraries requried by Slic3r are compiled with absolute paths.
  97. Once the slic3r.par archive is unpacked, one may list the native shared libraries by
  98. find ./ -name '*.bundle'
  99. and one may list the dependencies by running
  100. otool -L somefile.bundle
  101. Most of the dependencies point to system directores and these dependences are always fulfilled. Dependencies pointing to the WxWidget libraries need to be fixed. These have a form
  102. ~/perlbrew/perls/perl-5.22.1/lib/site_perl/5.22.1/darwin-thread-multi-2level/Alien/wxWidgets/osx_cocoa_3_0_2_uni/lib/libwx_*.dylib
  103. and we need to replace them with
  104. @executable_path/../Frameworks/libwx_*.dylib
  105. Another dependency, which needs our attention is
  106. /usr/local/Cellar/xz/5.2.2/lib/liblzma.5.dylib
  107. Fortunately, a tool dylibbundler was developed to address this problem.
  108. First install dylibbundler by calling
  109. brew dylibbundler
  110. For some installations, the dylibbundler tool sufficiently fixes all dependencies. Unfortunately, the WxWidgets installation is inconsistent in the versioning, therefore a certain clean-up is required. Namely, the WxWidgets libraries are compiled with the full build number in their file name. For example, the base library is built as libwx_baseu-3.0.0.2.0.dylib and a symlink is created libwx_baseu-3.0.dylib pointing to the full name. Then some of the Wx libraries link against the full name and some against the symlink, leading the dylibbundler to pack both. We solved the problem by whipping up a following script:
  111. \\rs.prusa\Development\Slic3r-Prusa\How_to_build_on_MacOSX_Lion\fix_dependencies.sh
  112. call
  113. slic3r_dependencies.sh --fix
  114. to collect the shared libraries into Content/Frameworks and to fix their linkage.
  115. call
  116. slic3r_dependencies.sh --show
  117. to list dependent libraries in a sorted order. All the non-system dependencies shall start with @executable_path after the fix.
  118. 8) Packing Slic3r into a dmg image using a bunch of scripts
  119. -----------------------------------------------------------
  120. Instead of relying on the PAR::Packer to collect the dependencies, we have used PAR::Packer to extract the dependencies, we manually cleaned them up and created an installer script.
  121. \\rs.prusa\Development\Slic3r-Prusa\How_to_build_on_MacOSX_Lion\Slic3r-Build-MacOS
  122. First compile Slic3r, then call build_dmg.sh with a path to the Slic3r source tree as a parameter.
  123. The script will collect all dependencies into Slic3r.app and it will create Slic3r.dmg.
  124. If SLIC3R_GUI variable is defined, a GUI variant of Slic3r will be packed.
  125. How to build on Windows
  126. -----------------------
  127. The prefered perl distribution on MS Windows is the Strawberry Perl 5.22.1.3 (32bit)
  128. http://strawberryperl.com/
  129. Let it install into c:\strawberry
  130. You may make a copy of the distribution. We recommend to make following copies:
  131. For a release command line only build: c:\strawberry-minimal
  132. For a release GUI build: c:\strawberry-minimal-gui
  133. For a development build with debugging information: c:\strawberry-debug
  134. and to make one of them active by making a directory junction:
  135. mklink /d c:\Strawberry c:\Strawberry-debug
  136. Building boost:
  137. Slic3r seems to have a trouble with the latest boost 1.60.0 on Windows. Please use 1.59.
  138. Decompress it to
  139. c:\dev\
  140. otherwise it will not be found by the Build.PL on Windows. You may consider to hack xs\Build.PL with your prefered boost path.
  141. run
  142. bootstrap.bat mingw
  143. b2 toolset=gcc
  144. Install git command line
  145. https://git-scm.com/
  146. Download Slic3r source code
  147. git clone git://github.com/alexrj/Slic3r.git
  148. Run compilation
  149. cd Slic3r
  150. perl Build.PL
  151. perl Build.PL --gui
  152. With a bit of luck, you will end up with a working Slic3r including GUI.
  153. Packing on Windows
  154. ------------------
  155. Life is easy on Windows. PAR::Packer will help again to collect the dependencies. The basic procedure is the same as for MacOS:
  156. To create a PAR archive of a command line slic3r, execute
  157. pp -e -p -x slic3r.pl --xargs cube.stl -o slic3r.par
  158. and let the slic3r slice a cube.stl to load the dynamic modules.
  159. To create a PAR archive of a GUI slic3r, execute
  160. pp -e -p -x slic3r.pl --xargs --gui -o slic3r.par
  161. and exercise the slic3r gui to load all modules.
  162. The standalone installation is then created from the PAR archive by renaming it into a zip and adding following binaries from c:\strawberry to the root of the extracted zip:
  163. perl5.22.1.exe
  164. perl522.dll
  165. libgcc_s_sjlj-1.dll
  166. libstdc++-6.dll
  167. libwinpthread-1.dll
  168. The GUI build requires following DLLs in addition:
  169. libglut-0_.dll
  170. wxbase30u_gcc_custom.dll
  171. wxmsw30u_adv_gcc_custom.dll
  172. wxmsw30u_core_gcc_custom.dll
  173. wxmsw30u_gl_gcc_custom.dll
  174. wxmsw30u_html_gcc_custom.dll
  175. and the var directory with the icons needs to be copied to the destination directory.
  176. To run the slic3r, move the script\slic3r.pl one level up and create a following tiny windows batch in the root of the unpacked zip:
  177. @perl5.22.1.exe slic3r.pl %*
  178. A windows shortcut may be created for the GUI version. Instead of the perl.exe, it is better to use the wperl.exe to start the GUI Slic3r, because it does not open a text console.
  179. The strawberry perl is already rellocatable, which means that the perl interpreter will find the perl modules in the lib directory,
  180. and Windows look up the missing DLLs in the directory of the executable, therefore no further rellocation effort is necessary.
  181. Packing on Windows, a single EXE solution
  182. -----------------------------------------
  183. One may try to create a PAR executable for command line slic3r:
  184. pp -M Encode::Locale -M Moo -M Thread::Semaphore -M Slic3r::XS -M Unicode::Normalize -o slic3r.exe slic3r.pl
  185. One may as well create a PAR executable for Windows GUI:
  186. pp -M Encode::Locale -M Moo -M Thread::Semaphore -M OpenGL -M Slic3r::XS -M Unicode::Normalize -M Wx -M Class::Accessor -M Wx::DND -M Wx::Grid -M Wx::Print -M Wx::Html -M Wx::GLCanvas -M Math::Trig -M threads -M threads::shared -M Thread::Queue -l C:\strawberry\perl\site\lib\auto\Wx\Wx.xs.dll -o -l C:\strawberry\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxbase30u_gcc_custom.dll -l C:\strawberry\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_core_gcc_custom.dll -l C:\strawberry\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_gl_gcc_custom.dll -l C:\strawberry\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_adv_gcc_custom.dll -l C:\strawberry\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_html_gcc_custom.dll -o slic3r.exe slic3r.pl
  187. Remember, that these executables will unpack into a temporary directory. The directory may be declared by setting an environment variable PAR_GLOBAL_TEMP. Otherwise the temporaries are unpacked into
  188. C:\Users\xxx\AppData\Local\Temp\par-xxxxxx
  189. Debugging the perl, debugging on Windows
  190. ----------------------------------------
  191. It is possible to debug perl using the integrated debugger. The EPIC plugin for Eclipse works very well with an older eclipse-SDK-3.6.2. There is a catch though: The Perl debugger does not work correctly with multiple threads running under the Perl interpreter. If that happens, the EPIC plugin gets confused and the debugger stops working. The same happens with the Komodo IDE.
  192. Debugging the C++ code works fine using the latest Eclipse for C++ and the gdb of MinGW. The gdb packed with the Strawberry distribution does not contain the Python support, so pretty printing of the stl containers only works if another gdb build is used. The one of the QT installation works well.
  193. It is yet a bit more complicated. The Strawberry MINGW is compiled for a different C++ exception passing model (SJLJ) than the other MINGWs, so one cannot simply combine MINGWs on Windows. For an unknown reason the nice debugger of the QT Creator hangs when debugging the C++ compiled by the Strawberry MINGW. Mabe it is because of the different exception passing models.
  194. And to disable optimization of the C/C++ code, one has to manually modify Config_heavy.pl in the Perl central installation. The SLIC3R_DEBUG environment variable did not override all the -O2 and -O3 flags that the perl build adds the gcc execution line.