pyo3 入门示例未在 MacOS 上构建

问题描述 投票:0回答:2

我正在尝试开始使用 py03,使用由 maturin 创建的入门项目,如下所述:

https://pyo3.rs/v0.17.3/

但是,当我尝试构建它时,我在链接阶段得到了这个:

  = note: Undefined symbols for architecture x86_64:
            "_PyBytes_AsString", referenced from:
                pyo3::types::bytes::PyBytes::as_bytes::hb0ce42a9e99b7119 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.13.rcgu.o)
            "_PyBytes_Size", referenced from:
                pyo3::types::bytes::PyBytes::as_bytes::hb0ce42a9e99b7119 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.13.rcgu.o)
            "_PyCFunction_NewEx", referenced from:
                pyo3::types::function::PyCFunction::internal_new_from_pointers::h92a1006a066f3794 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.5.rcgu.o)
            "_PyErr_Fetch", referenced from:
                pyo3::err::PyErr::take::h34abf03aae524a39 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.2.rcgu.o)
            "_PyErr_GivenExceptionMatches", referenced from:
                pyo3::err::PyErr::is_instance::h5bd7a1c534dc95ff in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.2.rcgu.o)
            "_PyErr_NewExceptionWithDoc", referenced from:
                pyo3::err::PyErr::new_type::h207f67133d2fe7dc in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.2.rcgu.o)
            "_PyErr_NormalizeException", referenced from:
                pyo3::err::PyErr::make_normalized::h92e97061454d87df in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.2.rcgu.o)
            "_PyErr_Print", referenced from:
                pyo3::err::panic_after_error::h1855c4e68479b292 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.2.rcgu.o)
            "_PyErr_PrintEx", referenced from:
                pyo3::err::PyErr::take::h34abf03aae524a39 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.2.rcgu.o)
            "_PyErr_Restore", referenced from:
                pyo3::err::PyErr::take::h34abf03aae524a39 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.2.rcgu.o)
                pyo3::err::PyErr::restore::h79045018546bf3d0 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.2.rcgu.o)
            "_PyEval_SaveThread", referenced from:
                pyo3::gil::prepare_freethreaded_python::_$u7b$$u7b$closure$u7d$$u7d$::h7ec7eff51d016eb2 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.8.rcgu.o)
            "_PyExc_AttributeError", referenced from:
                _$LT$pyo3..exceptions..PyAttributeError$u20$as$u20$pyo3..type_object..PyTypeInfo$GT$::type_object_raw::h9d284f308c6428d1 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.1.rcgu.o)
            "_PyExc_BaseException", referenced from:
                _$LT$pyo3..exceptions..PyBaseException$u20$as$u20$pyo3..type_object..PyTypeInfo$GT$::type_object_raw::hbc1c2918865ca2cb in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.1.rcgu.o)
            "_PyExc_ImportError", referenced from:
                _$LT$pyo3..exceptions..PyImportError$u20$as$u20$pyo3..type_object..PyTypeInfo$GT$::type_object_raw::h61f161f64a44efc1 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.1.rcgu.o)
            "_PyExc_OverflowError", referenced from:
                _$LT$pyo3..exceptions..PyOverflowError$u20$as$u20$pyo3..type_object..PyTypeInfo$GT$::type_object_raw::h745fe716930d7217 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.1.rcgu.o)
            "_PyExc_TypeError", referenced from:
                _$LT$pyo3..exceptions..PyTypeError$u20$as$u20$pyo3..type_object..PyTypeInfo$GT$::type_object_raw::h53ec02261503227a in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.1.rcgu.o)
            "_PyExc_ValueError", referenced from:
                _$LT$pyo3..exceptions..PyValueError$u20$as$u20$pyo3..type_object..PyTypeInfo$GT$::type_object_raw::h6af62b63d19decb7 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.1.rcgu.o)
            "_PyException_GetCause", referenced from:
                pyo3::err::PyErr::cause::h53aeaff8e297ea33 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.2.rcgu.o)
            "_PyException_SetCause", referenced from:
                pyo3::err::PyErr::set_cause::hf1c8ca56b45e01b9 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.2.rcgu.o)
            "_PyGILState_Ensure", referenced from:
                pyo3::gil::GILGuard::acquire_unchecked::h9d0224a43e6401ff in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.8.rcgu.o)
            "_PyGILState_Release", referenced from:
                _$LT$pyo3..gil..GILGuard$u20$as$u20$core..ops..drop..Drop$GT$::drop::h37927fc149066dfd in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.8.rcgu.o)
            "_PyList_Append", referenced from:
                pyo3::types::list::PyList::append::h9a6d00903059b938 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.15.rcgu.o)
            "_PyList_New", referenced from:
                pyo3::types::list::PyList::empty::h5be9ffe49a8635cc in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.15.rcgu.o)
            "_PyLong_AsUnsignedLongLong", referenced from:
                pyo3::types::num::_$LT$impl$u20$pyo3..conversion..FromPyObject$u20$for$u20$u64$GT$::extract::hc3c373b6f4fdef2b in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.5.rcgu.o)
            "_PyModule_Create2", referenced from:
                pyo3_ffi::modsupport::PyModule_Create::ha69b3fe4e6294f16 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.7.rcgu.o)
            "_PyModule_GetName", referenced from:
                pyo3::types::module::PyModule::name::h9e36dc62b552af10 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.4.rcgu.o)
            "_PyNumber_Index", referenced from:
                pyo3::types::num::_$LT$impl$u20$pyo3..conversion..FromPyObject$u20$for$u20$u64$GT$::extract::hc3c373b6f4fdef2b in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.5.rcgu.o)
            "_PyObject_GetAttr", referenced from:
                pyo3::types::any::PyAny::getattr::h2e27ff38c6c3fa19 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.6.rcgu.o)
            "_PyObject_Repr", referenced from:
                pyo3::types::any::PyAny::repr::h269b96ae0d11be7c in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.6.rcgu.o)
            "_PyObject_SetAttr", referenced from:
                pyo3::types::any::PyAny::setattr::he6a247c2d4d07938 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.6.rcgu.o)
                pyo3::types::any::PyAny::setattr::hfd8996f03911a84a in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.6.rcgu.o)
            "_PyObject_Str", referenced from:
                pyo3::types::any::PyAny::str::he0298d3bd0b3ac1e in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.6.rcgu.o)
            "_PyTuple_New", referenced from:
                pyo3::types::tuple::_$LT$impl$u20$pyo3..conversion..IntoPy$LT$pyo3..instance..Py$LT$pyo3..types..any..PyAny$GT$$GT$$u20$for$u20$$LP$T0$C$$RP$$GT$::into_py::h9b62fef051255294 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.15.rcgu.o)
                pyo3::types::tuple::_$LT$impl$u20$pyo3..conversion..IntoPy$LT$pyo3..instance..Py$LT$pyo3..types..any..PyAny$GT$$GT$$u20$for$u20$$LP$T0$C$$RP$$GT$::into_py::hf65fb0560a71d6f9 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.8.rcgu.o)
            "_PyTuple_SetItem", referenced from:
                pyo3::types::tuple::_$LT$impl$u20$pyo3..conversion..IntoPy$LT$pyo3..instance..Py$LT$pyo3..types..any..PyAny$GT$$GT$$u20$for$u20$$LP$T0$C$$RP$$GT$::into_py::h9b62fef051255294 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.15.rcgu.o)
                pyo3::types::tuple::_$LT$impl$u20$pyo3..conversion..IntoPy$LT$pyo3..instance..Py$LT$pyo3..types..any..PyAny$GT$$GT$$u20$for$u20$$LP$T0$C$$RP$$GT$::into_py::hf65fb0560a71d6f9 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.8.rcgu.o)
            "_PyUnicode_AsEncodedString", referenced from:
                pyo3::types::string::PyString::to_string_lossy::h5fff290c6902d849 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.2.rcgu.o)
            "_PyUnicode_AsUTF8AndSize", referenced from:
                pyo3::types::string::PyString::to_str::he285678de3416a4a in pyo3_example.31e4txws67eg8xfh.rcgu.o
                pyo3::types::string::PyString::to_str::h0c0d3cfa46a3349a in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.2.rcgu.o)
            "_PyUnicode_FromStringAndSize", referenced from:
                pyo3::types::string::PyString::new::h756c302dc780d638 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.2.rcgu.o)
                pyo3::types::string::PyString::intern::h99c7d7fb8d5ff249 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.2.rcgu.o)
            "_PyUnicode_InternInPlace", referenced from:
                pyo3::types::string::PyString::intern::h99c7d7fb8d5ff249 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.2.rcgu.o)
            "_Py_InitializeEx", referenced from:
                pyo3::gil::prepare_freethreaded_python::_$u7b$$u7b$closure$u7d$$u7d$::h7ec7eff51d016eb2 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.8.rcgu.o)
            "_Py_IsInitialized", referenced from:
                pyo3::gil::prepare_freethreaded_python::_$u7b$$u7b$closure$u7d$$u7d$::h7ec7eff51d016eb2 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.8.rcgu.o)
                pyo3::gil::GILGuard::acquire::_$u7b$$u7b$closure$u7d$$u7d$::hcf818b25afc19e8c in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.8.rcgu.o)
            "__Py_Dealloc", referenced from:
                pyo3_ffi::object::Py_DECREF::h80a00bbd387b4f47 in libpyo3-fe99c63bd9fc0ad2.rlib(pyo3-fe99c63bd9fc0ad2.pyo3.754cfbf6-cgu.4.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)

这里可能发生了什么?我想知道是否有一个可以使用的 pyo3 示例作为入门项目

rust interop
2个回答
0
投票

事实证明文档已经过时,有多个不同版本的说明。这些工作截至目前为止:

https://rustrepo.com/repo/PyO3-PyO3-rust-foreign-function-interface


0
投票

只是为了确认并扩展一下Andrew Voelkel的答案。

根据我个人得到的错误输出(macOS Sonoma 14.0):

= 注意:ld:警告:在“/private/var/folders/rm/4t99t9dj0b5dg7h1mndxk0hc0000gp/T/rustce8T2Oc/symbols.o”中找不到平台加载命令,假设:macOS

在 macOS 中需要显式指定平台,因此需要创建

.cargo/config
,这意味着在 .cargo 文件夹中创建一个
config
(无扩展名)文件,并写入以下内容:

[target.x86_64-apple-darwin]
rustflags = [
  "-C", "link-arg=-undefined",
  "-C", "link-arg=dynamic_lookup",
]

[target.aarch64-apple-darwin]
rustflags = [
  "-C", "link-arg=-undefined",
  "-C", "link-arg=dynamic_lookup",
]

通过指定

x86_64-apple-darwin
,那么你可以考虑根据官方的平台支持保证工作,但由于某种原因,你也必须包含
target.aarch64-apple-darwin
,否则会抛出相同的错误。

© www.soinside.com 2019 - 2024. All rights reserved.