Create shared C object linked to Rust dylib for use in R

主宰稳场 提交于 2019-12-06 01:51:02

In the C++ code, you need to declare the Rust function (which is available via the C ABI) as extern "C".

treble.h

#include <stdint.h>

extern "C" {
  int32_t treble(int32_t value);
}

The error you are getting is because the C++ compiler is name mangling the method treble before attempting to link against it. extern "C" disables the mangling.

Additionally, your Rust FFI code should always use the types from the libc crate; in your case you want libc::int32_t.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!