Skip to content

Instantly share code, notes, and snippets.

@tomaka
Last active September 26, 2015 16:35
Show Gist options
  • Save tomaka/0949b94ee9b6b8b6799d to your computer and use it in GitHub Desktop.
Save tomaka/0949b94ee9b6b8b6799d to your computer and use it in GitHub Desktop.
extern crate gcc;
fn main() {
gcc::compile_library("libhello.a", &["src/test.c"]);
}
[package]
name = "test"
version = "0.0.1"
authors = ["Pierre Krieger <pierre.krieger1708@gmail.com>"]
build = "build.rs"
[dependencies]
libc = "*"
[build-dependencies]
gcc = "*"
extern crate libc;
use std::ptr;
#[repr(C)]
pub struct Foo {
pub a: libc::size_t,
pub b: libc::size_t,
pub c: libc::size_t,
pub d: libc::size_t,
}
extern {
// this version works with MinGW and crashes with MSVC:
fn foo(_: *const libc::c_void, _: *const libc::c_void, _: *const libc::c_void,
_: *const libc::c_void, _: Foo) -> libc::size_t;
// this version works with MSVC and crashes with MinGW
//fn foo(_: *const libc::c_void, _: *const libc::c_void, _: *const libc::c_void,
// _: *const libc::c_void, _: *const Foo) -> libc::size_t;
}
fn main() {
let f = Foo { a: 1, b: 2, c: 3, d: 4 };
// works with MinGW only:
let ret = unsafe { foo(ptr::null(), ptr::null(), ptr::null(), ptr::null(), f) };
// works with MSVC only:
//let ret = unsafe { foo(ptr::null(), ptr::null(), ptr::null(), ptr::null(), &f) };
println!("obtained {:?}", ret);
}
#include <stdio.h>
typedef struct {
size_t a;
size_t b;
size_t c;
size_t d;
} Foo;
size_t foo(void* a, void* b, void* c, void* d, Foo f) {
return f.c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment