How_to_build_Slic3r.txt 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. How to build Slic3r on Mac OS X 10.9 Maveric
  2. ---------------------------------------------
  3. Vojtech Bubnik, 2017-12-12
  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. Install cmake
  43. brew install cmake
  44. 3) Install perl
  45. ---------------
  46. 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.
  47. http://perlbrew.pl/
  48. First install perlbrew
  49. curl -L http://install.perlbrew.pl | bash
  50. Then compile the newest perl with the rellocatable @INC path and with multithreading enabled, execute following line:
  51. perlbrew install --threads -Duserelocatableinc --switch perl-5.26.1
  52. The --switch parameter switches the active perl to the currently compiled one.
  53. Available perl versions could be listed by calling
  54. perlbrew available
  55. Switch to the newly compiled perl
  56. perl5/perlbrew/bin/perlbrew switch perl-5.26.1
  57. Install cpanm
  58. perlbrew install-cpanm
  59. Initialize CPAN, install PAR and PAR::Packer modules
  60. execute cpan command, from the cpan prompt, run
  61. install App::cpanminus
  62. install ExtUtils::CppGuess
  63. install ExtUtils::Typemaps
  64. install ExtUtils::Typemaps::Basic
  65. install PAR
  66. install PAR::Packer
  67. install Module::Build
  68. install Module::Pluggable
  69. install Module::Runtime
  70. install Moo
  71. install Test::Pod
  72. install Test::Pod::Coverage
  73. quit
  74. 4) Download and install Slic3r
  75. ------------------------------
  76. git clone git://github.com/alexrj/Slic3r
  77. cd Slic3r
  78. perl Build.PL
  79. Now Slic3r shall be compiled. You may try to execute
  80. perl slic3r.pl
  81. to get a help screen, or
  82. perl slic3r.pl some_model.stl
  83. to have the model sliced.
  84. 5) Download and compile the GUI libraries needed to execute Slic3r in GUI mode
  85. ------------------------------------------------------------------------------
  86. Building the Perl Alien-Wx containing a wxWidgets library:
  87. We use wxWidgets-3.0.3.
  88. patch wxWidgets-3.0.3//src/osx/cocoa/textctrl.mm , see https://github.com/prusa3d/Slic3r/issues/600
  89. perl -I. Build.PL --wxWidgets-extraflags="--with-osx_cocoa --with-macosx-version-min=10.9 --with-macosx-sdk=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk --with-libjpeg=builtin --with-libpng=builtin --with-regex=builtin --with-libtiff=builtin --with-zlib=builtin --with-expat=builtin --with-opengl"
  90. perl -I. Build
  91. perl -I. Build test
  92. perl -I. Build
  93. Building the Perl Wx package:
  94. cpan install Wx
  95. Building the Perl OpenGL package:
  96. OpenGL needs to be patched to support MSAA, see the Windows patch.
  97. For the current Slic3r 1.2.30 code base, set the environment variable SLIC3R_STATIC to link a static version of the boost library:
  98. export SLIC3R_STATIC=1
  99. then execute
  100. perl Build.PL --gui
  101. 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
  102. ~/perl5/perlbrew/perls/perl-5.22.1/lib/site_perl/5.22.1/darwin-thread-multi-2level/Alien/wxWidgets/
  103. On Maverics, we experienced following issue compiling WxPerl:
  104. http://wiki.bolay.net/doku.php?id=acdsn:acdsn-a:mac
  105. Now you could run the GUI version of slic3r by calling
  106. perl slic3r.pl --gui
  107. If some dependency is missing, the MacOS system will let you know.
  108. 6) Packing the Slic3r
  109. ---------------------
  110. 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.
  111. 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.
  112. To create a PAR archive of a command line slic3r, execute
  113. pp -e -p -x slic3r.pl --xargs cube.stl -o slic3r.par
  114. and let the slic3r slice a cube.stl to load the dynamic modules.
  115. To create a PAR archive of a GUI slic3r, execute
  116. pp -e -p -x slic3r.pl --xargs --gui -o slic3r.par
  117. and exercise the slic3r gui to load all modules.
  118. 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.
  119. 7) Collecting the dependent shared libraries, making the link paths relative
  120. ----------------------------------------------------------------------------
  121. 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.
  122. 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.
  123. Once the slic3r.par archive is unpacked, one may list the native shared libraries by
  124. find ./ -name '*.bundle'
  125. and one may list the dependencies by running
  126. otool -L somefile.bundle
  127. 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
  128. ~/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
  129. and we need to replace them with
  130. @executable_path/../Frameworks/libwx_*.dylib
  131. Another dependency, which needs our attention is
  132. /usr/local/Cellar/xz/5.2.2/lib/liblzma.5.dylib
  133. Fortunately, a tool dylibbundler was developed to address this problem.
  134. First install dylibbundler by calling
  135. brew dylibbundler
  136. 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:
  137. \\rs.prusa\Development\Slic3r-Prusa\How_to_build_on_MacOSX_Lion\fix_dependencies.sh
  138. call
  139. slic3r_dependencies.sh --fix
  140. to collect the shared libraries into Content/Frameworks and to fix their linkage.
  141. call
  142. slic3r_dependencies.sh --show
  143. to list dependent libraries in a sorted order. All the non-system dependencies shall start with @executable_path after the fix.
  144. 8) Packing Slic3r into a dmg image using a bunch of scripts
  145. -----------------------------------------------------------
  146. 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.
  147. \\rs.prusa\Development\Slic3r-Prusa\How_to_build_on_MacOSX_Lion\Slic3r-Build-MacOS
  148. First compile Slic3r, then call build_dmg.sh with a path to the Slic3r source tree as a parameter.
  149. The script will collect all dependencies into Slic3r.app and it will create Slic3r.dmg.
  150. If SLIC3R_GUI variable is defined, a GUI variant of Slic3r will be packed.
  151. How to build on Windows
  152. -----------------------
  153. The prefered perl distribution on MS Windows is the Strawberry Perl 5.22.1.3 (32bit)
  154. http://strawberryperl.com/
  155. Let it install into c:\strawberry
  156. You may make a copy of the distribution. We recommend to make following copies:
  157. For a release command line only build: c:\strawberry-minimal
  158. For a release GUI build: c:\strawberry-minimal-gui
  159. For a development build with debugging information: c:\strawberry-debug
  160. and to make one of them active by making a directory junction:
  161. mklink /d c:\Strawberry c:\Strawberry-debug
  162. Building boost:
  163. Slic3r seems to have a trouble with the latest boost 1.60.0 on Windows. Please use 1.59.
  164. Decompress it to
  165. c:\dev\
  166. 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.
  167. run
  168. bootstrap.bat mingw
  169. b2 toolset=gcc
  170. Install git command line
  171. https://git-scm.com/
  172. Download Slic3r source code
  173. git clone git://github.com/alexrj/Slic3r.git
  174. Run compilation
  175. cd Slic3r
  176. perl Build.PL
  177. perl Build.PL --gui
  178. With a bit of luck, you will end up with a working Slic3r including GUI.
  179. Packing on Windows
  180. ------------------
  181. Life is easy on Windows. PAR::Packer will help again to collect the dependencies. The basic procedure is the same as for MacOS:
  182. To create a PAR archive of a command line slic3r, execute
  183. pp -e -p -x slic3r.pl --xargs cube.stl -o slic3r.par
  184. and let the slic3r slice a cube.stl to load the dynamic modules.
  185. To create a PAR archive of a GUI slic3r, execute
  186. pp -e -p -x slic3r.pl --xargs --gui -o slic3r.par
  187. and exercise the slic3r gui to load all modules.
  188. 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:
  189. perl5.22.1.exe
  190. perl522.dll
  191. libgcc_s_sjlj-1.dll
  192. libstdc++-6.dll
  193. libwinpthread-1.dll
  194. The GUI build requires following DLLs in addition:
  195. libglut-0_.dll
  196. wxbase30u_gcc_custom.dll
  197. wxmsw30u_adv_gcc_custom.dll
  198. wxmsw30u_core_gcc_custom.dll
  199. wxmsw30u_gl_gcc_custom.dll
  200. wxmsw30u_html_gcc_custom.dll
  201. and the var directory with the icons needs to be copied to the destination directory.
  202. 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:
  203. @perl5.22.1.exe slic3r.pl %*
  204. 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.
  205. The strawberry perl is already rellocatable, which means that the perl interpreter will find the perl modules in the lib directory,
  206. and Windows look up the missing DLLs in the directory of the executable, therefore no further rellocation effort is necessary.
  207. Packing on Windows, a single EXE solution
  208. -----------------------------------------
  209. One may try to create a PAR executable for command line slic3r:
  210. pp -M Encode::Locale -M Moo -M Thread::Semaphore -M Slic3r::XS -M Unicode::Normalize -o slic3r.exe slic3r.pl
  211. One may as well create a PAR executable for Windows GUI:
  212. 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
  213. 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
  214. C:\Users\xxx\AppData\Local\Temp\par-xxxxxx
  215. Debugging the perl, debugging on Windows
  216. ----------------------------------------
  217. 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.
  218. 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.
  219. 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.
  220. 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.
  221. ----------------------------------------------------------------------
  222. Building boost.
  223. One may save compilation time by compiling just what Slic3r needs.
  224. ./bootstrap.sh --with-libraries=system,filesystem,thread,log,locale,regex
  225. The -fPIC flag is required on Linux to make the static libraries rellocatable,
  226. so they could be embedded into a shared library.
  227. It is important to disable boost.locale.icu=off when compiling the static boost library.
  228. ./bjam -a link=static variant=release threading=multi boost.locale.icu=off --with-locale cxxflags=-fPIC cflags=-fPIC
  229. To install on Linux to /usr/local/..., run the line above with the additional install keyword and with sudo.