Error when calling Rust from Python -
rust code:
#[no_mangle] use std::thread; pub extern fn process() { let handles: vec<_> = (0..10).map(|_| { thread::spawn(|| { let mut _x = 0; _ in (0..5_000_001) { _x += 1 } }) }).collect(); h in handles { h.join().ok().expect("could not join thread!"); } }
cargo.toml:
[package] name = "embed" version = "0.1.0" authors = ["hustlibraco <hustlibraco@gmail.com>"] [lib] name = "embed" crate-type = ["dylib"]
i build target/release/libembed.so
, , create invoke.py
in path:
from ctypes import cdll lib = cdll.loadlibrary("target/release/libembed.so") lib.process() print("done!")
executing, , error:
-bash-4.2# python invoke.py traceback (most recent call last): file "invoke.py", line 5, in <module> lib.process() file "/usr/lib64/python2.7/ctypes/__init__.py", line 373, in __getattr__ func = self.__getitem__(name) file "/usr/lib64/python2.7/ctypes/__init__.py", line 378, in __getitem__ func = self._funcptr((name_or_ordinal, self)) attributeerror: target/release/libembed.so: undefined symbol: process
how solve problem?
the #[no_mangle]
goes on function, not on use
.
#[no_mangle] pub extern fn process() { ... }
for complete, working example, see the rust ffi omnibus "integers" example.
Comments
Post a Comment