Skip to content

Instantly share code, notes, and snippets.

@sverhoeven
Last active October 24, 2022 14:39
Show Gist options
  • Save sverhoeven/53d66d10776cdbce255ed914430be759 to your computer and use it in GitHub Desktop.
Save sverhoeven/53d66d10776cdbce255ed914430be759 to your computer and use it in GitHub Desktop.
Octave with netcdf on linux

Octave on linux with netcdf4+statistics packages

https://octave.sourceforge.io/netcdf/

OS

Octave version too old.

Anaconda

Build octave-netcdf package

conda create -n bb conda-build
conda activate bb
mkdir octave-netcdf
# edit conda/octave-netcdf/recipe/meta.yaml
conda build octave-netcdf

Stuck at

Saving to: ‘netcdf.tar.gz’

netcdf.tar.gz                        100%[===================================================================>] 409.68K  1.88MB/s    in 0.2s    

2022-10-24 16:17:10 (1.88 MB/s) - ‘netcdf.tar.gz’ saved [419517/419517]

QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-verhoes'
mkdir (/tmp/oct-poACam)
untar (netcdf.tar.gz, /tmp/oct-poACam)
checking for gawk... gawk
checking whether the C++ compiler works... no
configure: error: in `/tmp/oct-poACam/netcdf-1.0.16/src':
configure: error: C++ compiler cannot create executables
See `config.log' for more details

error: pkg: error running the configure script for netcdf
error: called from
    configure_make at line 101 column 9
    install at line 202 column 7
    pkg at line 612 column 9
Traceback (most recent call last):

Snap

snap install octave
octave --version

Inject netcdf into existing octave snap

snap run --shell octave
curl https://downloads.unidata.ucar.edu/netcdf-c/4.9.0/netcdf-c-4.9.0.tar.gz > netcdf-c-4.9.0.tar.gz
curl https://downloads.unidata.ucar.edu/netcdf-cxx/4.3.1/netcdf-cxx4-4.3.1.tar.gz > netcdf-cxx4-4.3.1.tar.gz
tar -xf netcdf-c-4.9.0.tar.gz 
cd netcdf-c-4.9.0
./configure
checking for m4... no
configure: error: Cannot find m4 utility. Install m4 and try again.
snap run --shell octave
touch /lib/x86_64-linux-gnu/x
touch: cannot touch '/lib/x86_64-linux-gnu/x': Read-only file system

Create snap with netcdf4+statistics packages

sudo snap install --classic snapcraft
mkdir own
cd own
snapcraft init

Cannot use octave as base

New octave snap

Clone https://github.com/octave-snap/octave-snap

add netcdf-dev to octave-snap/snap/snapcraft.yaml

snapcraft

Failed with

  CXX      libinterp/corefcn/libinterp_corefcn_libcorefcn_la-input.lo
virtual memory exhausted: Cannot allocate memory
Makefile:17926: recipe for target 'libinterp/corefcn/libinterp_corefcn_libcorefcn_la-input.lo' failed
make[2]: *** [libinterp/corefcn/libinterp_corefcn_libcorefcn_la-input.lo] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: Leaving directory '/root/parts/octave/build'
Makefile:26490: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/root/parts/octave/build'
Makefile:9865: recipe for target 'all' failed
make: *** [all] Error 2
Failed to run 'make -j2' for 'octave': Exited with code 2.
Verify that the part is using the correct parameters and try again.
Run the same command again with --debug to shell into the environment if you wish to introspect this failure.
{% set version = "1.0.16" %}
package:
name: octave-netcdf
version: 1.0.16
build:
number: 1
script: |
wget -O netcdf.tar.gz https://octave.sourceforge.io/download.php?package=netcdf-{{ version }}.tar.gz &&
octave --eval 'pkg install -verbose netcdf.tar.gz'
requirements:
build:
- octave
- libnetcdf
- gxx
host:
- octave
- libnetcdf
name: octave
base: core18
summary: Interactive programming environment for numerical computations
description: |
GNU Octave is a high-level interpreted language, primarily intended for
numerical computations. It provides capabilities for the numerical
solution of linear and nonlinear problems, and for performing other
numerical experiments. It also provides extensive graphics capabilities
for data visualization and manipulation. Octave is normally used through
its interactive command line interface, but it can also be used to write
non-interactive programs. The Octave language is quite similar to
Matlab so that most programs are easily portable.
confinement: strict
adopt-info: octave
apps:
octave:
command: bin/octave
common-id: org.octave.Octave
desktop: share/applications/org.octave.Octave.desktop
environment:
OCTAVE_HOME: "$SNAP"
GNUPLOT_DRIVER_DIR: "$SNAP/usr/lib/gnuplot"
GNUPLOT_LUA_DIR: "$SNAP/usr/share/gnuplot/gnuplot/5.2/lua"
GNUPLOT_PS_DIR: "$SNAP/usr/share/gnuplot/gnuplot/5.2/PostScript"
GS_LIB: "$SNAP/usr/share/ghostscript/9.26/Resource/Init:$SNAP/usr/share/ghostscript/9.26/lib:$SNAP/usr/share/ghostscript/9.26/Resource/Font:$SNAP/usr/share/ghostscript/fonts:$SNAP/usr/share/fonts"
LD_LIBRARY_PATH: "$SNAP/lib/octave/$SNAPCRAFT_PROJECT_VERSION"
LOCPATH: "$SNAP/usr/lib/locale"
PKG_CONFIG_PATH: "$SNAP/lib/pkgconfig:$SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pkgconfig:$SNAP/usr/share/pkgconfig"
PKG_CONFIG_SYSROOT_DIR: "$SNAP"
UNITSFILE: "$SNAP/usr/share/units/definitions.units"
plugs:
- desktop
- desktop-legacy
- home
- network
- opengl
- pulseaudio
- removable-media
- unity7
- wayland
- x11
octave-cli:
command: bin/octave-cli
environment:
OCTAVE_HOME: "$SNAP"
GNUPLOT_DRIVER_DIR: "$SNAP/usr/lib/gnuplot"
GNUPLOT_LUA_DIR: "$SNAP/usr/share/gnuplot/gnuplot/5.2/lua"
GNUPLOT_PS_DIR: "$SNAP/usr/share/gnuplot/gnuplot/5.2/PostScript"
GS_LIB: "$SNAP/usr/share/ghostscript/9.26/Resource/Init:$SNAP/usr/share/ghostscript/9.26/lib:$SNAP/usr/share/ghostscript/9.26/Resource/Font:$SNAP/usr/share/ghostscript/fonts:$SNAP/usr/share/fonts"
LD_LIBRARY_PATH: "$SNAP/lib/octave/$SNAPCRAFT_PROJECT_VERSION"
LOCPATH: "$SNAP/usr/lib/locale"
PKG_CONFIG_PATH: "$SNAP/lib/pkgconfig:$SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pkgconfig:$SNAP/usr/share/pkgconfig"
PKG_CONFIG_SYSROOT_DIR: "$SNAP"
UNITSFILE: "$SNAP/usr/share/units/definitions.units"
plugs:
- desktop
- desktop-legacy
- home
- network
- opengl
- pulseaudio
- removable-media
- unity7
- wayland
- x11
parts:
alsa:
plugin: nil
source: https://github.com/diddledan/snapcraft-alsa.git
override-pull: |
cat > asound.conf <<EOF
pcm.!default {
type pulse
fallback "sysdefault"
hint {
show on
description "Default ALSA Output (currently PulseAudio Sound Server)"
}
}
ctl.!default {
type pulse
fallback "sysdefault"
}
EOF
override-build: |
install -m644 -D -t $SNAPCRAFT_PART_INSTALL/etc asound.conf
prime:
- -usr/share/doc
- -usr/share/man
build-packages:
- libasound2-dev
stage-packages:
- libasound2
- libasound2-plugins
octave:
plugin: autotools
source: https://hg.savannah.gnu.org/hgweb/octave
source-type: hg
source-commit: "@"
build-environment:
# Use a sensible default set of build flags, append flags from environment
- CFLAGS: "-g -O2 -fexceptions -fstack-protector-strong${CFLAGS:+ $CFLAGS}"
- CPPFLAGS: "-D_FORTIFY_SOURCE=2${CPPFLAGS:+ $CPPFLAGS}"
- CXXFLAGS: "-g -O2 -fexceptions -fstack-protector-strong${CXXFLAGS:+ $CXXFLAGS}"
- FFLAGS: "-g -O2${FFLAGS:+ $FFLAGS}"
- FLIBS: "-lgfortran -lquadmath -lm"
- LDFLAGS: "-Wl,-z,relro,-z,now -Wl,--as-needed${LDFLAGS:+ $LDFLAGS}"
# Strip debug symbols from programs and libraries when installing
- INSTALL_PROGRAM: "/usr/bin/install -s"
- INSTALL_STRIP_FLAG: "-s"
# Force Octave header files to be found before system header files
# This override can be dropped after upgrading to snapcraft version 3.11
- INCLUDES: "-Ilibinterp/corefcn"
override-build: |
# Parse octave version information and set snap grade and version
sed -n '/^AC_INIT/{s/^[^,]*, *\[//;s/\],.*//;p}' configure.ac > ac-version.txt
if test -d .hg; then
# Construct a snapshot version string if we are building from mercurial
hg log -r . -T "{node|short}" | cut -c1-8 > commit.txt
date -u +%Y-%m-%d > date.txt
echo "$(cat ac-version.txt)+hg$(cat commit.txt)" > version.txt
echo "<release version=\"$(cat version.txt)\" type=\"development\" date=\"$(cat date.txt)\" />" > release.xml
sed -i "/<releases>/a\ $(cat release.xml)" etc/icons/org.octave.Octave.appdata.xml
sed -i "s/hg_safe.*||/hg_safe log -r . -T \"{node|short}\" ||/" build-aux/mk-hg-id.sh
grade=devel
version="$(cat version.txt)"
else
grade=stable
version="$(cat ac-version.txt)"
fi
snapcraftctl set-grade "$grade"
snapcraftctl set-version "$version"
# Patch RapidJSON header files with upstream fixes that haven't been
# incorporated into the Ubuntu distributed version of the library
if test -d /usr/include/rapidjson/.orig; then
cp -a /usr/include/rapidjson/.orig/*.h /usr/include/rapidjson
fi
patch -p3 -N -d /usr/include/rapidjson -b -B .orig/ < $SNAPCRAFT_PROJECT_DIR/patches/rapidjson-issue-905.patch
patch -p3 -N -d /usr/include/rapidjson -b -B .orig/ < $SNAPCRAFT_PROJECT_DIR/patches/rapidjson-issue-1718.patch
# Patch build_env and mkoctfile to record the original build flags from
# above, so that additional flags from snapcraft build setup aren't leaked
sed -i "s|%OCTAVE_CONF_CFLAGS%|\"-g -O2 -fexceptions -fstack-protector-strong\"|" libinterp/build-env.in.cc src/mkoctfile.in.cc
sed -i "s|%OCTAVE_CONF_CPPFLAGS%|\"-D_FORTIFY_SOURCE=2\"|" libinterp/build-env.in.cc src/mkoctfile.in.cc
sed -i "s|%OCTAVE_CONF_CXXFLAGS%|\"-g -O2 -fexceptions -fstack-protector-strong\"|" libinterp/build-env.in.cc src/mkoctfile.in.cc
sed -i "s|%OCTAVE_CONF_LDFLAGS%|\"-Wl,-z,relro,-z,now -Wl,--as-needed\"|" libinterp/build-env.in.cc src/mkoctfile.in.cc
sed -i "s|%OCTAVE_CONF_OCT_LINK_OPTS%|\"-Wl,-z,relro,-z,now -Wl,--as-needed\"|" libinterp/build-env.in.cc src/mkoctfile.in.cc
snapcraftctl build
override-prime: |
snapcraftctl prime
sed -i 's|^Icon=octave|Icon=/share/icons/hicolor/scalable/apps/octave.svg|' share/applications/org.octave.Octave.desktop
sed -i 's|^prefix=.*|prefix=/usr|' usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pkgconfig/*.pc
rm -f usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pkgconfig/hdf5.pc
ln -s hdf5-serial.pc usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pkgconfig/hdf5.pc
rm -f usr/bin/gnuplot
ln -s gnuplot-qt usr/bin/gnuplot
prime:
- -share/man
- -usr/share/doc
- -usr/share/doc-base
- -usr/share/man
- -usr/share/texmf/ls-R
organize:
usr/lib/$SNAPCRAFT_ARCH_TRIPLET/openblas: usr/lib/$SNAPCRAFT_ARCH_TRIPLET
after: [alsa]
build-packages:
- bison
- epstool
- flex
- gfortran
- ghostscript
- gnuplot-nox
- gperf
- icoutils
- less
- libarpack2-dev
- libcurl4-gnutls-dev
- libfftw3-dev
- libfltk1.3-dev
- libfontconfig1-dev
- libgl2ps-dev
- libglpk-dev
- libglu1-mesa-dev
- libgraphicsmagick++1-dev
- libhdf5-dev
- libnetcdf-dev
- libncurses5-dev
- libopenblas-dev
- libpcre3-dev
- libqhull-dev
- libqrupdate-dev
- libqscintilla2-qt5-dev
- libqt5opengl5-dev
- libreadline-dev
- librsvg2-bin
- libsndfile1-dev
- libsuitesparse-dev
- pkg-config
- portaudio19-dev
- qtbase5-dev
- qttools5-dev
- qttools5-dev-tools
- rapidjson-dev
- texinfo
- texlive-fonts-recommended
- texlive-latex-base
- texlive-plain-generic
stage-packages:
- build-essential
- curl
- epstool
- gfortran
- ghostscript
- gnuplot-qt
- info
- libamd2
- libarpack2
- libcamd2
- libccolamd2
- libcholmod3
- libcolamd2
- libcurl3-gnutls
- libcxsparse3
- libfftw3-double3
- libfftw3-single3
- libfltk-gl1.3
- libfltk1.3
- libfontconfig1
- libgl2ps1.4
- libglpk40
- libglu1-mesa
- libgraphicsmagick++-q16-12
- libhdf5-dev
- libnetcdf-dev
- libncurses5-dev
- libopenblas-dev
- libpcre3-dev
- libportaudio2
- libpython3-dev
- libqhull-r7
- libqrupdate1
- libqscintilla2-qt5-13
- libqt5core5a
- libqt5gui5
- libqt5help5
- libqt5network5
- libqt5opengl5
- libqt5printsupport5
- libqt5sql5
- libqt5sql5-sqlite
- libqt5widgets5
- libqt5xml5
- libsndfile1
- libspqr2
- libumfpack5
- locales-all
- pkg-config
- python3-venv
- texinfo
- units
- unzip
- zip
python-packages:
plugin: python
python-packages:
- mpmath==1.1.0
- sympy==1.5.1
prime:
- -bin/isympy
- -share/man
- -usr/share/doc
- -usr/share/man
layout:
/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/alsa-lib:
bind: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/alsa-lib
/etc/asound.conf:
bind-file: $SNAP/etc/asound.conf
/usr/share/alsa/alsa.conf:
bind-file: $SNAP/etc/asound.conf
# Make staged dri and pulseaudio modules available in expected locations
/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/dri:
symlink: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/dri
/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pulseaudio:
symlink: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pulseaudio
# Make staged perl modules available in expected perl path directories
/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/perl/5.26:
symlink: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/perl/5.26
/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/perl5:
symlink: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/perl5
/usr/share/perl:
symlink: $SNAP/usr/share/perl
/usr/share/perl5/Text:
symlink: $SNAP/usr/share/perl5/Text
/usr/share/perl5/XML:
symlink: $SNAP/usr/share/perl5/XML
# Make staged qt plugins available in expected locations
/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/qt5:
symlink: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/qt5
# Make xkb configuration files available in expected locations, required
# by qt in 18.04, may not be needed in 20.04
/usr/share/X11:
symlink: $SNAP/usr/share/X11
# Make all system and staged development library header files available in
# standard /usr/include location, to allow compiling oct files and packages
/usr/include:
bind: $SNAP/usr/include
# Make certain libc static library fragments available in expected locations,
# to allow linking oct files and packages
/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/libc_nonshared.a:
symlink: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/libc_nonshared.a
/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/libmvec_nonshared.a:
symlink: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/libmvec_nonshared.a
/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/libpthread_nonshared.a:
symlink: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/libpthread_nonshared.a
# Make staged Python wheels available in expected system directory
/usr/share/python-wheels:
symlink: $SNAP/usr/share/python-wheels
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment