Skip to main content
This guide explains how to create a command-line driven Linux version of Giac. The steps have been tested under Linux Mint 17.2, Ubuntu Linux 14.04, 16.04, and 18.04.

Prerequisites

Before compiling Giac, you need to install the required development packages:
sudo apt-get install build-essential libgmp-dev libmpfr-dev
The prebuilt source tree includes static versions of GMP and MPFR for various platforms. If you use the default CMake configuration, you don’t need to install these libraries separately.

Building with Gradle

The simplest way to build and run Giac on Linux is using the included Gradle wrapper.
1

Navigate to the source directory

cd /path/to/giac
2

Run the Gradle build

../gradlew run
This command will:
  • Compile all necessary source files
  • Link the executable
  • Launch the interactive Giac terminal
3

Use the interactive terminal

After a successful compilation, you should see:
Press CTRL-D to stop
> Building 85% > :run
You can now type Giac expressions and commands. Exit with CTRL-D.

Building with CMake

For more control over the build process, you can use CMake directly.
1

Create a build directory

mkdir build
cd build
2

Configure the project

cmake ..
CMake will automatically detect your platform and configure the build to use prebuilt static libraries for GMP and MPFR from src/jni/prebuilt/linux/x86-64/.
3

Compile the project

make
This builds two targets:
  • minigiac: Command-line executable
  • javagiac: Shared library for JNI integration
4

Run the executable

./minigiac

Using System Libraries

If you prefer to use dynamically linked system libraries instead of the prebuilt static versions:
CMakeLists.txt
# Change line 262 in CMakeLists.txt from:
target_link_libraries(minigiac ${MPFR_STATIC} ${GMP_STATIC})

# To:
target_link_libraries(minigiac mpfr gmp)

Build Configuration

The CMake build uses the following compiler flags:
Compiler Flags
-std=c++0x          # C++11 support
-fpermissive        # Allow some non-conforming code
-fno-strict-aliasing # Prevent strict aliasing optimizations
-DPIC -fpic         # Position independent code

Preprocessor Definitions

Key definitions used during compilation:
DefinitionPurpose
HAVE_NO_HOME_DIRECTORYDisable home directory detection
GIAC_GGBEnable GeoGebra integration features
IN_GIACMark compilation as internal to Giac
HAVE_LIB_PTHREADEnable pthread support
GIAC_GENERIC_CONSTANTSUse generic constant definitions
TIMEOUTEnable timeout functionality
HAVE_LIBMPFRMPFR library is available
HAVE_UNISTD_HPOSIX unistd.h is available
HAVE_SYS_TIMES_Hsys/times.h is available
SIZEOF_VOID_P=8Pointer size (64-bit)

Troubleshooting

Android SDK Dependency

If you encounter errors related to the Android SDK during Gradle builds:
By default, the build configuration includes Android components. If you don’t have the Android SDK installed, you’ll need to disable these components.
1

Remove Android from settings.gradle

Open settings.gradle and remove the line:
include 'giac-android'
Alternatively, delete the file completely:
rm settings.gradle
rm ../settings.gradle  # For Gradle 5.x
2

Remove Android tasks from build.gradle

Edit build.gradle and remove these tasks:
  • androidCopyCrystaxSo
  • androidAar
If you cloned the source using git, you may need to create a symlink:
ln -s /path/to/gradle-scripts ../gradle-scripts

Library Not Found Errors

If CMake cannot find the prebuilt libraries:
CMake Error: Unable to find library gmp in src/jni/prebuilt/linux/x86-64/
Solution:
  1. Verify the prebuilt directory exists and contains libgmp.a and libmpfr.a
  2. Try using system libraries instead (see “Using System Libraries” above)
  3. Install libraries manually: sudo apt-get install libgmp-dev libmpfr-dev

Debugging in an IDE

CLion Setup

Giac supports debugging with CLion (or other CMake-compatible IDEs):
1

Open the project

In CLion, select File → Open and choose the CMakeLists.txt file.
2

Configure build settings

CLion will automatically detect the CMake configuration. Ensure the build directory is set to build/.
3

Set breakpoints

Open src/minigiac/cpp/minigiac.cc or any other source file and set breakpoints by clicking in the left margin.
4

Start debugging

Click the debug icon or press Shift+F9 to start a debugging session.

Building Specific Targets

Command-line Executable Only

make minigiac

JNI Shared Library Only

make javagiac
The shared library will be output to build/libs/javagiac/shared/linux64/libjavagiac.so.

Static Linking

The build system automatically links GMP and MPFR statically with the following flags:
Linker Flags
-static-libgcc       # Link libgcc statically
-static-libstdc++    # Link libstdc++ statically
-s                   # Strip symbols (reduce binary size)

Testing the Build

Run the regression test suite:
../gradlew testMinigiacExecutable
This will execute tests from src/test/ and verify the build is working correctly.

Performance Optimization

The default build uses -O2 optimization. For maximum performance:
cmake -DCMAKE_CXX_FLAGS="-O3" ..
make
Higher optimization levels may increase compilation time significantly.

Build docs developers (and LLMs) love