rust-python-example icon indicating copy to clipboard operation
rust-python-example copied to clipboard

ld: symbol(s) not found for architecture x86_64

Open phdoerfler opened this issue 7 years ago • 7 comments

I'm on macOS and ran into this issue:

rustup update
git clone https://github.com/rochacbruno/rust-python-example
cd rust-python-example
make compile-rust

then I was greeted by this:

image

which after a lot of scrolling ended in this:

image
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-m64" "-L" …

…

 "-lSystem" "-lresolv" "-lpthread" "-lc" "-lm" "-dynamiclib" "-Wl,-dylib"
  = note: Undefined symbols for architecture x86_64:
            "_PyModule_GetFilename", referenced from:

…

                cpython::err::result_cast_from_owned_ptr::h1ac7cdf8da86aadd in libcpython-27991f0cb68c1b96.rlib(cpython-27991f0cb68c1b96.cpython0-1ffe5a9ffc73bff7490d17c35d3f3537.rs.rcgu.o)
                ...
          ld: symbol(s) not found for architecture x86_64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

What am I missing?

phdoerfler avatar Oct 01 '18 09:10 phdoerfler

@phdoerfler did you ever figure this one out? Having same issue.

tcullum-gpsw avatar Nov 30 '18 07:11 tcullum-gpsw

@tcullum-gpsw Nope unfortunately I did not but went back to the frustration that is Cython instead

phdoerfler avatar Nov 30 '18 09:11 phdoerfler

I think cpython crate should be replaced with PyO3 in this repo, PyO3 is more updated and maybe solved this issue.

rochacbruno avatar Nov 30 '18 13:11 rochacbruno

https://github.com/PyO3/pyo3

rochacbruno avatar Nov 30 '18 13:11 rochacbruno

Getting the same error on MacOSX 10.14.2 using rustc 1.27.2 (58cc626de 2018-07-18), following the tutorial exactly, but it seems breaking changes were made since this initial tutorial was done

ra0x3 avatar Jan 03 '19 21:01 ra0x3

I made the needed changes to get the tutorial working on recent versions of Rust.

This works on rustc 1.42.0-nightly (0de96d37f 2019-12-19) and MacOSX 10.14.5.

As @rochacbruno mentioned, it involves using PyO3 instead of CPython.

Switch to Rust nightly (see this link):

cd <path/to/project>
rustup nightly
rustup override set nightly

Change the following files (combining the README example and the PyO3 example):

Cargo.toml:

[package]
name = "pyext-myrustlib"
version = "0.1.0"
authors = ["Bruno Rocha <[email protected]>"]
edition = "2018"

[lib]
name = "myrustlib"
crate-type = ["dylib"]

[dependencies.pyo3]
version = "0.8.4"
features = ["extension-module"]

src/lib.rs:

use pyo3::prelude::*;
use pyo3::wrap_pyfunction;

#[pyfunction]
fn count_doubles(val: &str) -> PyResult<u64> {
    let mut total = 0u64;

    for (c1, c2) in val.chars().zip(val.chars().skip(1)) {
        if c1 == c2 {
            total += 1;
        }
    }

    Ok(total)
}

#[pymodule]
fn myrustlib(_py: Python, m: &PyModule) -> PyResult<()> {
    m.add_wrapped(wrap_pyfunction!(count_doubles))?;

    Ok(())
}

Use the following build command on MacOSX:

cargo rustc --release -- -C link-arg=-undefined -C link-arg=dynamic_lookup

The rest of the tutorial should be the same.

To fix the make command, PyO3 will have to be implemented for all of the functions (which shouldn't be too hard, following the convention shown above).

gabrielibagon avatar Dec 23 '19 22:12 gabrielibagon

@gabrielibagon thanks for the final command! it just worked for me. Just out of curiosity: where did get it? is there a way to have it configure globally?

pathcl avatar Feb 12 '23 17:02 pathcl