简体   繁体   中英

Cargo run using PyO3

I'm working on a rust/python package using PyO3 and its working great from python after I run maturin develop . I can import my rust code into Python and run my functions as I expect.

I would also like to still run my code from Rust though, and so when I run cargo run , I get the following errors:

error: linking with `cc` failed: exit status: 1

...

ld: symbol(s) not found for architecture arm64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

Here is are some simple instructions to replicate this:

1. Setup

# (replace string_sum with the desired package name)
$ mkdir string_sum
$ cd string_sum
$ python -m venv .env
$ source .env/bin/activate
$ pip install maturin

2. Initialize Package using maturin

maturin init

3. Add main.rs file

fn main() {
    println!("Hello, world!");
}

4. Run

cargo run

I found that the solution is similar to the reported error with cargo test , here :

[lib]
name = "lib"
crate-type = ["cdylib", "rlib"]

...

[dependencies.pyo3]
version = "0.16.5"

[features]
extension-module = ["pyo3/extension-module"]
default = ["extension-module"]

and then if you run:

cargo run --no-default-features

It works as expected

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM