This project adds a C/C++ interface to MathCAT. Visit the MathCAT project page for more info or if you want to play around with MathCAT's capabilities, try out the demo.
Warning: the interface is subject to change. This is my first attempt to add a C interface to Rust code. There are two issues I'm not happy with the current interface:
- Because strings are passed back and forth, C code needs to free the Rust strings returned. It's a bit ugly, but that's C's memory management...
- Errors can happen and I didn't see a good way to handle this. The current method is to return an empty string to indicate an error. This means the calling code should check this condition after each condition. Call GetError() to find out what the error is.
To use this project:
- build the project (
cargo build --release) - this will create a release build in target/release and also create a directory
c-examplewithmathcat.hand the MathCATRulesdir in it. - try compiling the the sample program
test.cppin that directory or create your own using that as an example. See instructions for compiling at the start of that file.
Alternatively, to avoid having to have a Rust build environment: download the a prebuilt dll from releases. The Release-version-target.zip file includes the dll, c-header file, a test/example program, and the Rules directory needed by MathCAT. It is probably best to use the latest release at that link. If you need a target/dll not listed there, file an issue.
There are premade building scripts in the scripts folder for the following system.
- Install rustc
- Install Microsoft C++ Build Tools
- Open cmd and install WSL
wsl --install
- Open WSL and install Make
sudo apt install make
- Add build targets in cmd with
rustup target add x86_64-pc-windows-msvc
rustup target add i686-pc-windows-msvc
- Install Android Studio and download the latest NDK.
- Install cargo-ndk with cargo in cmd
cargo install cargo-ndk
- Install build targets
rustup target add aarch64-linux-android
rustup target add armv7-linux-androideabi
- Install rustc
- Install Xcode & Development tools
- Install build targets
rustup target add aarch64-apple-ios
rustup target add x86_64-apple-ios-macabi
- Install Android Studio and download the latest NDK.
- Install cargo-ndk with cargo in cmd
cargo install cargo-ndk
- Install build targets
rustup target add aarch64-linux-android
rustup target add armv7-linux-androideabi
Inside the scripts folder
- Use the build_win.cmd or build_win_local.cmd
- Use the build_android.cmd or build_android_local.cmd
- Use the build_ios.cmd or build_ios_local.cmd
- Use the build_android.sh or build_android_local.sh
Catalyst is broken, due to std path issues needs internal rules folder
- Bundle the MathCat library into your c++ project
- Add the Rules folder unziped into the supporting files.
- Change build rules for Rules folder to "Apply Once to Folder"
- Provide MathCat with the [[NSBundle mainBundle] resourcePath] to the Rules folder
- Bundle the MathCat library into your c++ project
- Add the Rules folder zipped into the assets folder.
- Add code for unzipping the Rules.zip to a accessible folder (ie appspace/Rules)
- Provide MathCat with the path to the Rules folder
- Bundle the MathCat library into your c++ project
- Add Rules unzipped to an accessible folder space (ie deployment_folder)
- Provide MathCat with the path to the Rules folder
