python调用rust_Python调用Rust编译的共享库出现错误

Rust Code:

#[no_mangle]

use std::thread;

pub extern fn process() {

let handles: Vec<_> = (0..10).map(|_| {

thread::spawn(|| {

let mut _x = 0;

for _ in (0..5_000_001) {

_x += 1

}

})

}).collect();

for h in handles {

h.join().ok().expect("Could not join a thread!");

}

}

Cargo.toml:

[package]

name = "embed"

version = "0.1.0"

authors = ["hustlibraco <hustlibraco@gmail.com>"]

[lib]

name = "embed"

crate-type = ["dylib"]

编译得到

target/release/libembed.so

共享库,然后我在此目录下面新建了一个python文件:

from ctypes import cdll

lib = cdll.LoadLibrary("target/release/libembed.so")

lib.process()

print("done!")

执行报错:

-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

这是Rust官方教程给的例子,为什么我这里会执行出错呢?

#[no_mangle]应该写在函数前面,而不是use前…

#[no_mangle]

pub extern fn process() {···}

楼主你是怎么编译的,我编译出来的结果没有libembed.so,好捉急_(:з」∠)_

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值