Prerequisites
Install Xcode Command Line Tools
Install Homebrew (Optional)
If you want to use system libraries instead of prebuilt static libraries: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
Install CMake
Configure the build
- Detect macOS as the target platform
- Use prebuilt libraries from
src/jni/prebuilt/maccatalyst/x86_64/orarm64/ - Configure for your architecture (Intel or Apple Silicon)
Compile
minigiac: Command-line executablejavagiac: Dynamic library (.jnilib) for Java integration
Architecture-Specific Builds
Intel (x86_64) Build
src/jni/prebuilt/maccatalyst/x86_64/.
Apple Silicon (ARM64) Build
src/jni/prebuilt/maccatalyst/arm64/.
Universal Binary (Both Architectures)
To create a universal binary that runs on both Intel and Apple Silicon:Building with Gradle
Giac supports Gradle builds on macOS with additional platform targets.macOS Native Build
Build for Specific Platform
macOS-Specific Configuration
Compiler Settings
The macOS build uses the following configuration:Compiler Flags
Preprocessor Definitions
Key macOS-specific definitions:| Definition | Purpose |
|---|---|
HAVE_UNISTD_H | POSIX unistd.h available |
APPLE_SMART | Enable Apple-specific optimizations |
NO_SCANDIR | scandir() not available |
HAVE_SYS_TIMES_H | sys/times.h available |
HAVE_SYS_TIME_H | sys/time.h available |
NO_GETTEXT | Disable gettext internationalization |
DONT_USE_LIBLAPLACK | Don’t use LAPACK library |
Linker Configuration
The macOS linker uses these frameworks and flags:SDK Configuration
The build automatically detects SDK paths usingxcrun:
Building iOS Frameworks
Giac can also be compiled for iOS, iPhone Simulator, and Mac Catalyst.iOS Device (ARM64)
iPhone Simulator
Mac Catalyst
Create XCFramework
To build a complete XCFramework with all platforms: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:build/cocoapods/Giac-[version].zip
Debugging in Xcode
While CMakeLists.txt is primarily for CLion, you can debug with Xcode:Troubleshooting
Linking Errors on macOS 10.14+
If you encounter linking issues on macOS Mojave or later:libc++ Compatibility Issues
Missing JDK Headers
For JNI builds, if headers are not found: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:Accelerate Framework Not Found
Using System Libraries (Homebrew)
To use dynamically linked libraries from Homebrew instead of static prebuilt ones:Performance Notes
Apple Silicon builds benefit from native ARM64 optimizations. Benchmark comparison:| Architecture | Relative Performance |
|---|---|
| ARM64 (native) | 100% (baseline) |
| x86_64 (Rosetta 2) | ~70-80% |
| Universal binary | Same as respective arch |
For best performance on Apple Silicon, always build native ARM64 binaries.
