Prerequisites
Since Giac is a C++ library, you need to have a compiler toolchain installed:
- Node.js and npm
- A C++ compiler (gcc, clang, or Visual Studio)
- GMP library (GNU Multiple Precision Arithmetic)
- MPFR library (Multiple Precision Floating-Point Reliable)
- node-gyp for native compilation
Linux
Install the required packages:sudo apt install build-essential libgmp-dev libmpfr-dev
Ubuntu 16.04 and above are supported. Tested on amd64, i386, and armhf processors.
macOS
Install dependencies using MacPorts:sudo port install gmp mpfr
The build assumes GMP and MPFR are installed in /opt/local/lib. If using a different location, set the LIBDIR environment variable.Windows
Currently only the 32-bit version works correctly. The 64-bit version may fail for some computations.
- Follow Microsoft’s NodeJS Guidelines to set up node-gyp
- Install Visual Studio 2013 (newer versions may cause compilation errors)
- Download MPIR (instead of GMP) and MPFR static libraries (.LIB files)
- Place .LIB files in the current folder or set the
LIBDIR environment variable
- Place .DLL files (MPIR.DLL and MPFR.DLL) in the same folder for runtime
Installation
Install the latest stable version:Or install the latest development version:Faster compilation
The compilation may take several minutes. Speed it up by using multiple cores:JOBS=4 npm install giac@latest
Set JOBS to the number of CPU cores on your system for optimal compilation speed.
Testing
After installation, test that Giac is working:cd node_modules/giac
npm test
On Windows, ensure the .DLL files are in the giac folder or build subfolder before testing.Prerequisites
Linux and macOS
Install the required packages:Linux (Debian/Ubuntu):sudo apt install cmake make build-essential libgmp-dev libmpfr-dev
macOS (using Homebrew):brew install cmake make gmp mpfr
The build includes prebuilt static versions of GMP and MPFR for most platforms, so you don’t strictly need these libraries installed. However, installing them is recommended for development.
Windows
Use MSYS2 with the CLANG64 flavor. Install these packages:pacman -S base-devel \
mingw-w64-clang-x86_64-cc \
mingw-w64-clang-x86_64-gmp \
mingw-w64-clang-x86_64-mpfr \
mingw-w64-clang-x86_64-cmake \
mingw-w64-clang-x86_64-make
For 32-bit builds, use the CLANG32 flavor and replace “x86_64” with “i686” in package names.
Building
Linux and macOS
mkdir build
cd build
cmake ..
make
This creates two targets:
minigiac - Command-line executable
javagiac - Shared library for JNI bindings
Windows
mkdir build
cd build
CC=clang CXX=clang++ cmake -G "MinGW Makefiles" ..
mingw32-make
Building with Gradle
Alternatively, use Gradle for a more integrated build:Linux command-line version
After successful compilation, you’ll see:Press CTRL-D to stop
> Building 85% > :run
If you encounter Android SDK errors, remove the line include giac-android from settings.gradle and remove the tasks androidCopyCrystaxSo and androidAar from build.gradle.
Development in CLion
For debugging and development:
- Open CLion and import the
CMakeLists.txt file
- Set breakpoints in source files (start with
minigiac.cc)
- Run in debug mode
The build system uses static linking for GMP and MPFR by default, which improves portability. If you prefer dynamic linking, modify the CMakeLists.txt file to use gmp and mpfr instead of ${GMP_STATIC} and ${MPFR_STATIC}.Prerequisites
This process requires approximately 10 GB of disk space.
- Download Crystax NDK 10.2.1
- Unpack to
~/android-sdks/ (requires ~8 GB additional space)
- Set up Android SDK (required for building)
Setting up cross-compilers
Environment variables
export NDK_DIR=~/android-sdks/crystax-ndk-10.2.1
export CC_DIR=~/cross-compilers
ARM (armeabi-v7a)
export ARCH=arm
export HOST=arm-linux-androideabi
$NDK_DIR/build/tools/make-standalone-toolchain.sh \
--ndk-dir=$NDK_DIR \
--arch=$ARCH \
--platform=android-21 \
--install-dir=$CC_DIR/$ARCH
export PATH=$CC_DIR/$ARCH/bin/:$PATH
x86
export ARCH=x86
export HOST=i686-linux-android
$NDK_DIR/build/tools/make-standalone-toolchain.sh \
--ndk-dir=$NDK_DIR \
--arch=$ARCH \
--platform=android-21 \
--install-dir=$CC_DIR/$ARCH
x86_64
export ARCH=x86_64
export HOST=x86_64-linux-android
$NDK_DIR/build/tools/make-standalone-toolchain.sh \
--ndk-dir=$NDK_DIR \
--arch=$ARCH \
--platform=android-21 \
--install-dir=$CC_DIR/$ARCH
ARM64
export ARCH=arm64
export HOST=aarch64-linux-android
$NDK_DIR/build/tools/make-standalone-toolchain.sh \
--ndk-dir=$NDK_DIR \
--arch=$ARCH \
--platform=android-21 \
--install-dir=$CC_DIR/$ARCH
Optional: Compile GMP and MPFR
To compile GMP and MPFR from source for Android (requires 300-500 MB additional space):CFLAGS="-fPIC" ./configure \
--host=$HOST \
--prefix=$CC_DIR/$ARCH/sysroot/usr \
--disable-assembly && make && make install
Repeat for each architecture. Libraries will be in $CC_DIR/$ARCH/sysroot/usr/lib.Building the Android library
Ensure the PATH variable includes your cross-compiler:export PATH=$CC_DIR/$ARCH/bin/:$PATH
../gradlew androidAar
This creates an Android AAR package with native libraries for all architectures.Troubleshooting
Create local.properties if needed:sdk.dir=/path/to/android/sdk
Or set the ANDROID_SDK environment variable.Prerequisites
- Git
- Python
- CMake (for compiling GMP and MPFR if needed)
- Approximately 2-3 GB of disk space
Quick Start
Build the WebAssembly version using Emscripten:./gradlew downloadEmsdk installEmsdk activateEmsdk createGiacWasmJs
This command will:
- Download the Emscripten SDK
- Install Emscripten (may take a while as clang is compiled from source)
- Activate the toolchain
- Compile Giac to WebAssembly
The default Emscripten version is 4.0.7. Other versions may not work correctly or may have issues with some Giac commands.
Step-by-Step Installation
1. Download Emscripten SDK
2. Install Emscripten
For the default version (4.0.7):For a specific version:EMSCRIPTEN_VERSION=tag-X.Y.Z ./gradlew installEmsdk
Always use the correct Emscripten version and clang compiler. Mismatches can cause strange compilation or runtime problems. Newer versions perform sanity checks and will inform you of any issues.
3. Activate Emscripten
4. Compile to WebAssembly
./gradlew createGiacWasmJs
Or with a specific Emscripten version:EMSCRIPTEN_VERSION=tag-X.Y.Z ./gradlew clean activateEmsdk createGiacWasmJs
Advanced: Compiling GMP and MPFR
The repository includes prebuilt GMP and MPFR libraries in src/giac.js/prebuilt/ that are compatible with the default Emscripten version.If you need to recompile them for a different Emscripten version:./gradlew emConfigureGmp emMakeGmp
./gradlew emConfigureMpfr emMakeMpfr
You may need to set source directory paths in build.gradle before running these commands:
gmpSourceDir (default: /data/jenkins/ws/gmp-6.3.0)
mpfrSourceDir (default: /data/jenkins/ws/mpfr-4.2.1)
Output Files
After successful compilation, find the WebAssembly files in:build/binaries/giacggb.wasm/
├── giacggb.js # JavaScript wrapper
├── giacggb.wasm # WebAssembly binary
└── giac.wasm.js # Combined JS with embedded base64 WASM
The giac.wasm.js file contains the entire library with the WASM binary encoded in base64, making it easy to embed in web applications.