I’m working on a project for Unity3D and using rust for a native plugin. Fundamentally what I’m doing is pretty simple - compiling opus and libspeexdsp into static libs, pulling these into rust and exporting some functions that do some tiny extra bits of pointer arithmetic for me. Finally I use rust to compile a library which is dropped into Unity (normally a dylib).
However this process has to change slightly for iOS which does not support dynamic linking - for this Unity takes a static library and links it into your game. This fails at runtime with an EXC_BAD_ACCESS
error (exactly the same error as this stackoverflow question). It looks like Opus and Unity both define a method called compute_allocation
.
I checked the lib rust produces with nm and the compute_allocation
function is not listed - I suspect my rather patchy knowledge of linking is letting me down, as I don’t even know how this issue is possible in that case!
Here’s a cut down version of my rust source:
pub enum OpusEncoder { }
pub enum OpusDecoder { }
pub enum SpeexPreprocessState { }
extern "C" {
pub fn opus_encoder_create(Fs: i32, channels: i32, application: i32, error: *mut i32) -> *mut OpusEncoder;
}
#[no_mangle]
pub extern "C" fn dissonance_opus_encoder_create(samplingRate: i32, channels: i32, application: i32, error: &mut i32) -> *mut ::OpusEncoder {
unsafe {
return ::opus_encoder_create(samplingRate, channels, application, error);
}
}
tl;dr Is it possible to configure rust to build it’s staticlib in a way which will fix this problem?