Skip to main content
This guide covers building Giac on macOS for both Intel (x86_64) and Apple Silicon (ARM64) architectures.

Prerequisites

Install Xcode Command Line Tools

xcode-select --install

Install Homebrew (Optional)

If you want to use system libraries instead of prebuilt static libraries:
brew install cmake gmp mpfr
The Giac source tree includes prebuilt static versions of GMP and MPFR for macOS. Using these is recommended for better portability and easier linking.

Building with CMake

1

Install CMake

brew install cmake make
Or download from cmake.org.
2

Create build directory

mkdir build
cd build
3

Configure the build

cmake ..
CMake will automatically:
  • Detect macOS as the target platform
  • Use prebuilt libraries from src/jni/prebuilt/maccatalyst/x86_64/ or arm64/
  • Configure for your architecture (Intel or Apple Silicon)
4

Compile

make
This builds:
  • minigiac: Command-line executable
  • javagiac: Dynamic library (.jnilib) for Java integration
5

Run the executable

./minigiac

Architecture-Specific Builds

Intel (x86_64) Build

cmake -DCMAKE_OSX_ARCHITECTURES=x86_64 ..
make
The build uses prebuilt libraries from src/jni/prebuilt/maccatalyst/x86_64/.

Apple Silicon (ARM64) Build

cmake -DCMAKE_OSX_ARCHITECTURES=arm64 ..
make
The build uses prebuilt libraries from src/jni/prebuilt/maccatalyst/arm64/.

Universal Binary (Both Architectures)

To create a universal binary that runs on both Intel and Apple Silicon:
cmake -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" ..
make
Universal binary builds require both x86_64 and arm64 versions of all dependencies.

Building with Gradle

Giac supports Gradle builds on macOS with additional platform targets.

macOS Native Build

../gradlew minigiacExecutable

Build for Specific Platform

../gradlew javagiacOsx_amd64SharedLibrary

macOS-Specific Configuration

Compiler Settings

The macOS build uses the following configuration:
Compiler Flags
-stdlib=libc++              # Use libc++ standard library
-std=c++11                  # C++11 standard
-mmacosx-version-min=10.7   # Minimum macOS version
-target x86_64-apple-macos11 # Target specification (or arm64)
-isysroot [MacOSX.sdk path] # SDK path

Preprocessor Definitions

Key macOS-specific definitions:
DefinitionPurpose
HAVE_UNISTD_HPOSIX unistd.h available
APPLE_SMARTEnable Apple-specific optimizations
NO_SCANDIRscandir() not available
HAVE_SYS_TIMES_Hsys/times.h available
HAVE_SYS_TIME_Hsys/time.h available
NO_GETTEXTDisable gettext internationalization
DONT_USE_LIBLAPLACKDon’t use LAPACK library

Linker Configuration

The macOS linker uses these frameworks and flags:
-framework Accelerate        # Apple's optimized math library
-framework CoreFoundation    # Core Foundation framework
-stdlib=libc++ -lc++        # C++ standard library
-lgmp -lmpfr -lpthread      # Required libraries
-dynamiclib                  # Create dynamic library
-Wl,-search_paths_first     # Linker search order

SDK Configuration

The build automatically detects SDK paths using xcrun:
# Verify SDK paths
xcrun --sdk macosx --show-sdk-path
xcrun --sdk macosx --find clang
xcrun --sdk macosx --find gcc
Typical SDK location:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk

Building iOS Frameworks

Giac can also be compiled for iOS, iPhone Simulator, and Mac Catalyst.

iOS Device (ARM64)

../gradlew giacIos_arm64StaticLibrary

iPhone Simulator

../gradlew giacIphonesimulator_x86_64StaticLibrary

Mac Catalyst

../gradlew giacMaccatalyst_x86_64StaticLibrary
../gradlew giacMaccatalyst_arm64StaticLibrary

Create XCFramework

To build a complete XCFramework with all platforms:
../gradlew createIosXcframework
This creates build/libs/framework/Giac.xcframework containing:
  • iOS device (arm64)
  • iOS Simulator (arm64, x86_64)
  • Mac Catalyst (arm64, x86_64)

CocoaPods Package

Create a CocoaPods-compatible zip:
../gradlew cocoapodsZip
Output: build/cocoapods/Giac-[version].zip

Debugging in Xcode

While CMakeLists.txt is primarily for CLion, you can debug with Xcode:
1

Generate Xcode project

mkdir build-xcode
cd build-xcode
cmake -G Xcode ..
2

Open in Xcode

open minigiac.xcodeproj
3

Set breakpoints and debug

Select the minigiac scheme and press Cmd+R to run or Cmd+Y to debug.

Troubleshooting

Linking Errors on macOS 10.14+

If you encounter linking issues on macOS Mojave or later:
ld: library not found for -lgmp
Solution: The build system automatically handles this by using prebuilt static libraries. If you’re using Homebrew libraries, ensure the link directories are correct:
cmake -DCMAKE_LIBRARY_PATH=/usr/local/lib ..

libc++ Compatibility Issues

ld: warning: direct access in function '...' to global weak symbol
This warning is usually harmless. If problematic, ensure all dependencies are built with the same C++ standard library:
-stdlib=libc++

Missing JDK Headers

For JNI builds, if headers are not found:
fatal error: 'jni.h' file not found
The build looks for headers in src/jni/jdkHeaders/darwin/. Verify this directory exists and contains JNI headers.

Apple Silicon Specific Issues

If building on Apple Silicon but getting x86_64 errors:
# Verify architecture
file ./minigiac

# Should show:
minigiac: Mach-O 64-bit executable arm64
Force ARM64 build:
cmake -DCMAKE_OSX_ARCHITECTURES=arm64 ..

Accelerate Framework Not Found

ld: framework not found Accelerate
Ensure Xcode Command Line Tools are properly installed:
sudo xcode-select --reset
xcode-select --install

Using System Libraries (Homebrew)

To use dynamically linked libraries from Homebrew instead of static prebuilt ones:
1

Install dependencies

brew install gmp mpfr
2

Modify CMakeLists.txt

Comment out or change lines 81-88 and 262:
# Comment out:
# find_static_library(gmp GMP_STATIC ...)

# Use instead:
target_link_libraries(minigiac mpfr gmp)
3

Configure with library paths

cmake -DCMAKE_PREFIX_PATH=/usr/local ..
make

Performance Notes

Apple Silicon builds benefit from native ARM64 optimizations. Benchmark comparison:
ArchitectureRelative Performance
ARM64 (native)100% (baseline)
x86_64 (Rosetta 2)~70-80%
Universal binarySame as respective arch
For best performance on Apple Silicon, always build native ARM64 binaries.

Build docs developers (and LLMs) love