Building on Microsoft Windows: Difference between revisions

→‎Building natively (MSYS2): Update configure flags (remove workaround for termcap; add workaround for weak symbols)
(→‎Building natively (MSYS2): Use different ccache)
(→‎Building natively (MSYS2): Update configure flags (remove workaround for termcap; add workaround for weak symbols))
 
(20 intermediate revisions by 2 users not shown)
Line 18: Line 18:
If you want to contribute changes to C++ files or are interested in testing the latest development or (unreleased) stable release, you can build Octave from source.
If you want to contribute changes to C++ files or are interested in testing the latest development or (unreleased) stable release, you can build Octave from source.


There is currently no maintained way to build Octave on Windows directly. But it is still possible to build Octave on Windows machines using virtual machines or Microsoft's Windows Subsystem for Linux.
It seems to be possible to build Octave natively on Windows with the MSYS2 shell. (Be aware that this might take some time.) It is also possible to build Octave on Windows machines using virtual machines or Microsoft's Windows Subsystem for Linux. Using VM is the currently recommended way to build Octave on Windows machines.
 
Building Octave natively on Windows is experimental! The only supported way of creating Windows binaries of Octave is cross-building with MXE Octave ([[Windows Installer]]).


==Virtual Machine==
==Virtual Machine==
Line 93: Line 95:
Use the "MSYS2 MinGW 64bit" shell for building Octave.
Use the "MSYS2 MinGW 64bit" shell for building Octave.


The following command can be used to install the necessary and optional build dependencies in MSYS2:
The following command can be used to install the necessary and optional build and run-time dependencies in MSYS2:
<pre>pacman -S base-devel mingw-w64-x86_64-toolchain mingw-w64-x86_64-lapack mingw-w64-x86_64-openblas mingw-w64-x86_64-pcre \
<syntaxhighlight lang="bash">pacman -S base-devel mingw-w64-x86_64-autotools mingw-w64-x86_64-cc mingw-w64-x86_64-fc mingw-w64-x86_64-gperf mingw-w64-x86_64-openblas mingw-w64-x86_64-pcre2 \
   mingw-w64-x86_64-arpack mingw-w64-x86_64-curl mingw-w64-x86_64-cvode mingw-w64-x86_64-fftw mingw-w64-x86_64-fltk mingw-w64-x86_64-gl2ps mingw-w64-x86_64-glpk mingw-w64-x86_64-ghostscript mingw-w64-x86_64-gnuplot mingw-w64-x86_64-graphicsmagick mingw-w64-x86_64-hdf5 mingw-w64-x86_64-libsndfile mingw-w64-x86_64-portaudio mingw-w64-x86_64-qhull mingw-w64-x86_64-qrupdate mingw-w64-x86_64-qscintilla mingw-w64-x86_64-qt5 mingw-w64-x86_64-rapidjson mingw-w64-x86_64-suitesparse \
   mingw-w64-x86_64-arpack mingw-w64-x86_64-curl mingw-w64-x86_64-fftw mingw-w64-x86_64-fltk mingw-w64-x86_64-gl2ps mingw-w64-x86_64-glpk mingw-w64-x86_64-ghostscript mingw-w64-x86_64-gnuplot mingw-w64-x86_64-graphicsmagick mingw-w64-x86_64-hdf5 mingw-w64-x86_64-libsndfile mingw-w64-x86_64-portaudio mingw-w64-x86_64-qhull mingw-w64-x86_64-qrupdate mingw-w64-x86_64-qscintilla mingw-w64-x86_64-qt5-base mingw-w64-x86_64-qt5-imageformats mingw-w64-x86_64-qt5-svg mingw-w64-x86_64-qt5-tools mingw-w64-x86_64-rapidjson mingw-w64-x86_64-suitesparse mingw-w64-x86_64-sundials \
  libutil-linux-devel \
   git mercurial mingw-w64-x86_64-ccache mingw-w64-x86_64-icoutils mingw-w64-x86_64-librsvg texinfo \
   git mercurial mingw-w64-x86_64-ccache mingw-w64-x86_64-icoutils mingw-w64-x86_64-librsvg texinfo</pre>
  unzip zip</syntaxhighlight>


Using ccache is optional. It speeds up compilation time but needs several GiB free disc space for its cache. If disc space is an issue, this step can be skipped. To prepend the path to the ccache helper scripts to the front of the PATH variable, add the following line near the end of the {{Path|.bash_profile}} file in your MSYS2 {{Path|$HOME}} directory:
Using ccache is optional. It speeds up compilation time but needs several GiB free disk space for its cache. If disk space is an issue, this step can be skipped. To prepend the path to the ccache helper scripts to the front of the PATH variable, add the following line near the end of the {{Path|.bash_profile}} file in your MSYS2 {{Path|$HOME}} directory:
<pre>export PATH="/mingw64/lib/ccache/bin:$PATH"</pre>
<syntaxhighlight lang="bash">export PATH="/mingw64/lib/ccache/bin:$PATH"</syntaxhighlight>
 
Additionally, add the following line to the {{Path|.bash_profile}} file in your MSYS2 {{Path|$HOME}} directory to allow successfully calling programs from perl scripts:
<syntaxhighlight lang="bash">export PERL5SHELL="bash -l -c"</syntaxhighlight>


Like installing the build dependencies, this has to be done only once.
Like installing the build dependencies, this has to be done only once.


To build from the development sources, check out the Mercurial repository and run the {{Path|bootstrap}} script:
To build from the development sources, check out the Mercurial repository and run the {{Path|bootstrap}} script:
<pre> hg clone https://www.octave.org/hg/octave
<syntaxhighlight lang="bash">hg clone https://www.octave.org/hg/octave
cd octave
cd octave
./bootstrap</pre>
./bootstrap</syntaxhighlight>


Create a sub-directory to avoid building in the source tree:
Create a sub-directory to avoid building in the source tree:
<pre>mkdir .build
<syntaxhighlight lang="bash">mkdir -p .build
cd .build</pre>
cd .build</syntaxhighlight>


Configure with the following flags:
Configure with the following flags:
<pre>../configure CC="x86_64-w64-mingw32-gcc" CXX="x86_64-w64-mingw32-g++" F77="x86_64-w64-mingw32-gfortran" PORTAUDIO_LDFLAGS="-LC:/msys64/mingw64/lib -LC:/msys64/usr/lib" --disable-docs ac_cv_search_tputs=-ltermcap</pre>
<syntaxhighlight lang="bash">../configure \
  --disable-docs \
  gl_cv_have_weak=no</syntaxhighlight>
 
And build with the following command:
<syntaxhighlight lang="bash">make all -j8</syntaxhighlight>
 
Windows doesn't have a shebang mechanism to execute scripts with an arbitrary interpreter. But the <code>makeinfo</code> program in MSYS2 is implemented as a perl script. As a work-around, tell Octave to interpret that file with the <code>perl</code> interpreter. You could do that, e.g., by running the following command to append to the global startup file:
<syntaxhighlight lang="bash">echo 'makeinfo_program (sprintf ("%s && cd %s/../usr/bin && perl makeinfo", OCTAVE_HOME ()(1:2), OCTAVE_HOME ()));' >> "${MINGW_PREFIX}/share/octave/site/m/startup/octaverc"</syntaxhighlight>
This has to be done only once.
 
A relocation issue with the graphicsmagick library in MSYS2 might cause Octave to crash on certain commands unless it is installed to the default location. To avoid these possible crashes, install Octave (from the MSYS2 shell in {{Path|.build}}) before using it:
<syntaxhighlight lang="bash">make install</syntaxhighlight>


And build with the following flags:
Windows' library lookup mechanism requires that the following executables are installed in the same folder like the libraries they depend on. That can be achieved by creating symlinks to these executables in the "correct" location:
<pre>make all -j8 FLTK_LIBS="-lfltk_gl -lopengl32 -lglu32 -lfltk -lpthread" PERL5SHELL="bash -l -c"</pre>
<syntaxhighlight lang="bash">ln -sf /mingw64/libexec/octave/7.0.0/exec/x86_64-w64-mingw32/octave-gui.exe /mingw64/bin/octave-gui.exe
ln -sf /mingw64/libexec/octave/7.0.0/exec/x86_64-w64-mingw32/octave-svgconvert.exe /mingw64/bin/octave-svgconvert.exe</syntaxhighlight>
These symlinks are only needed when building the GUI (i.e., Qt is not disabled). This step is no longer necessary with Octave 7 or newer.


Octave doesn't run correctly from the MSYS2 shell due to issues with readline. To be able to work with it anyway, install it with the following commands:
At this point, Octave's GUI can be started with the command <code>octave --gui</code> at the MSYS2/MINGW64 shell.
<pre>make install
ln -sf /mingw64/libexec/octave/7.0.0/exec/x86_64-w64-mingw32/octave-gui.exe /mingw64/bin/octave-gui.exe
ln -sf /mingw64/libexec/octave/7.0.0/exec/x86_64-w64-mingw32/octave-svgconvert.exe /mingw64/bin/octave-svgconvert.exe</pre>


Start Octave from a CMD shell (or with a batch script) with the following content (assuming MSYS2 was installed in its default location):
If you'd like to start Octave from a CMD shell (or with a batch script), the following commands could be used (assuming MSYS2 was installed in its default location):
<pre>set PATH=C:\msys64\mingw64\bin;C:\msys64\usr\bin;%PATH%
<syntaxhighlight lang="batch">set PATH=C:\msys64\mingw64\bin;C:\msys64\usr\bin;%PATH%
set MSYSTEM=MINGW64
set MSYSTEM=MINGW64
set TERM=cygwin
set TERM=cygwin
Line 131: Line 147:
set GS=gs.exe
set GS=gs.exe
set PERL5SHELL=bash -l -c
set PERL5SHELL=bash -l -c
octave-gui --gui</pre>
octave-gui --gui</syntaxhighlight>
If Octave was built without GUI, there won't be an {{Path|octave-gui}} executable. In that case, replace the last line with <code>octave-cli</code>.


=Footnotes=
=Footnotes=
219

edits