Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ld: symbol(s) not found for architecture x86_64 #15

Open
phdoerfler opened this issue Oct 1, 2018 · 7 comments
Open

ld: symbol(s) not found for architecture x86_64 #15

phdoerfler opened this issue Oct 1, 2018 · 7 comments

Comments

@phdoerfler
Copy link

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?

@tcullum-gpsw
Copy link

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

@phdoerfler
Copy link
Author

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

@rochacbruno
Copy link
Owner

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

@rochacbruno
Copy link
Owner

https://github.com/PyO3/pyo3

@ra0x3
Copy link

ra0x3 commented Jan 3, 2019

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

@gabrielibagon
Copy link

gabrielibagon commented Dec 23, 2019

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 <rochacbruno@gmail.com>"]
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).

@pathcl
Copy link

pathcl commented Feb 12, 2023

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants