Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

mex-sys 0.1 usage #2

Open
ctaggart opened this issue Nov 3, 2016 · 0 comments
Open

mex-sys 0.1 usage #2

ctaggart opened this issue Nov 3, 2016 · 0 comments

Comments

@ctaggart
Copy link
Owner

ctaggart commented Nov 3, 2016

I am able to use rust to create a dll, which I renamed test2.mexw64. I am then able to drop it into a folder and call the function from MATLAB. The warning is intentional and programmed in Rust.

image

src\lib.rs

#![allow(non_snake_case)]
#![allow(unused_variables)]

extern crate mex_sys;

use mex_sys::mxArray;
use mex_sys::mexWarnMsgIdAndTxt;
use std::ffi::CString;

#[no_mangle]
pub extern "C" fn mexFunction(
    nlhs: ::std::os::raw::c_int,
    plhs: *mut *mut mxArray,
    nrhs: ::std::os::raw::c_int,
    prhs: *mut *mut mxArray){
        let id = CString::new("MATLAB:yprime:divideByZero").unwrap();
        let msg = CString::new("Division by zero!\n").unwrap();
        unsafe {
            mexWarnMsgIdAndTxt(id.as_ptr(), msg.as_ptr());
        }
    }

Cargo.toml

[package]
name = "mex"
version = "0.1.0"
authors = ["Cameron Taggart <[email protected]>"]
build = "build.rs"

[lib]
crate-type = ["dylib"]

[dependencies]
mex-sys = "0.1.0"

build.rs

fn main () {
    println!("cargo:rustc-link-search={}", "C:\\Program Files\\MATLAB\\R2016a\\extern\\lib\\win64\\microsoft");
    println!("cargo:rustc-link-lib={}", "libmex");
}

.cargo\config

[build]
rustflags = ["-C", "prefer-dynamic"]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant