Last active
September 26, 2015 16:35
-
-
Save tomaka/0949b94ee9b6b8b6799d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate gcc; | |
fn main() { | |
gcc::compile_library("libhello.a", &["src/test.c"]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "test" | |
version = "0.0.1" | |
authors = ["Pierre Krieger <pierre.krieger1708@gmail.com>"] | |
build = "build.rs" | |
[dependencies] | |
libc = "*" | |
[build-dependencies] | |
gcc = "*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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