Rust cross compilation errors (While native compilation is successful)


#1

I’ve got hello world program working for cross compilation (armv7) and tried to do the same for a slightly complex crate which involves bindings and wrappers to a C library.

What is successful for native compilation is failing while doing cross compilation with below errors

src/lib.rs:66:56: 66:76 error: mismatched types:
 expected `*const u8`,
    found `*const i8`
(expected u8,
    found i8) [E0308]
src/lib.rs:66             client.mosquitto = bindings::mosquitto_new(id.unwrap().as_ptr(),
                                                                     ^~~~~~~~~~~~~~~~~~~~
src/lib.rs:66:56: 66:76 help: run `rustc --explain E0308` to see a detailed explanation

Here are my bindings and wrappers

Bindings

pub fn mosquitto_new(id: *const ::libc::c_char, clean_session: u8,
                         obj: *mut ::libc::c_void) -> *mut Struct_mosquitto;

Wrapper over binding

unsafe {
            client.mosquitto = bindings::mosquitto_new(id.unwrap().as_ptr(),
                                                       true as u8,
                                                       ptr::null_mut());

What is the reason for this behavior? How do I fix this?


#2

This is probably because c_char is aliased differently on different plattforms. For example on OSX and Linux it’s i8 while on ARM its defines as u8 (http://rust-lang-nursery.github.io/libc/arm-linux-androideabi/libc/type.c_char.html).

So I guess your native code with i8 is fine, but on arm it needs to be u8.

I’m not sure if this is the right answer, but probably your code needs to have a utility method somewhere that if you compile for arm turns i8 into an u8?


#3

Hi. Thanks. You are right.


#4

You’ve simply caught up with the serious breakage on ARM Linux in Rust 1.6.

Using 1.5 is probably the best option at the moment (or you’ll be doing up to dozens of casts per broken crate like a good code monkey) but it’s still affected by the updated libc 0.2 crate.