我有一个有两个文件的项目:
src/lib.rssrc/rle.rsrle.rs包含以下内容(以及更多):
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看起来如下所示:
mod rle;
use rle::rle_new;
// blablabla当我在Python中加载库时,会得到以下错误:
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似乎罗斯特明白这一点(聪明,聪明),因为我的林特说:
17 1 warning function rle_new is marked #[no_mangle], but not exported, #[warn(private_no_mangle_fns)] on by default (rust-cargo)如何解决这个问题,并使函数rle_new可以从目标/debug/LIBRANGes.dylib文件中获得?
我的crate-type Cargo.toml是["dylib"]
发布于 2016-10-19 14:39:50
罗斯特哲学倾向于明示而非隐含。
锈病只会输出从根箱公开访问的符号。这使得在不爬行所有文件的情况下检查机箱的公共接口变得非常容易:只需从根目录中跟踪pub即可。
在您的示例中,任何访问rle模块(例如兄弟模块)的人都可以公开访问符号rle,但是rle模块本身在根机箱中不能公开访问。
最简单的解决方案是有选择地导出这个符号:
pub use rle::rle_new;https://stackoverflow.com/questions/40131838
复制相似问题