Function marked # [no_mangle] but not exported

I have a project with two files:

  • src/lib.rs
  • src/rle.rs

rle.rs contains the following (and much more):

extern crate libc;

#[derive(Debug, PartialEq)]
pub struct Rle {
    pub lengths: Vec<i32>,
    pub values: Vec<i32>,
}

#[no_mangle]
pub extern "C" fn rle_new(blablabla...)

lib.rs as follows:

mod rle;
use rle::rle_new; 
// blablabla

When I load the library in Python, I get the error:

Traceback (most recent call last):
  File "compact_ranges.py", line 19, in <module>
    lib.rle_new.restype = POINTER(RleS)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 378, in __getattr__
    func = self.__getitem__(name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 383, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(0x7f94ca700370, rle_new): symbol not found

It seems that Rust understands this (smart, smart) because my linter says:

17   1 warning         function rle_new is marked #[no_mangle], but not exported, #[warn(private_no_mangle_fns)] on by default (rust-cargo)

How to fix this and make my function rle_newaccessible from target / debug / libranges.dylib?

crate-type > ["dylib"]

+4
source share
1 answer

Rust's philosophy is to prefer explicitly implicit.

Rust will export only characters that are publicly available from the root box. This makes it easy to check the open box interface without crawling all the files: just follow pubfrom the root.

rle_new , rle (, sibling modules), rle .

:

pub use rle::rle_new;
+12

Source: https://habr.com/ru/post/1658205/


All Articles