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

Won't build on Mac OS with Python 3.6.0 installed through pyenv #87

Closed
ghost opened this issue Feb 17, 2017 · 5 comments
Closed

Won't build on Mac OS with Python 3.6.0 installed through pyenv #87

ghost opened this issue Feb 17, 2017 · 5 comments

Comments

@ghost
Copy link

ghost commented Feb 17, 2017

I am running Python 3.6.0:

⋊> ~/D/r/e/hello on master ⨯ python --version
Python 3.6.0

And after running cargo build in the extensions/hello folder, I get:

...
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-m64" "-L" "/Users/mhsjlw/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/mhsjlw/Documents/rust-cpython/target/debug/deps/hello-8c4fb1941e38f02d.0.o" "-o" "/Users/mhsjlw/Documents/rust-cpython/target/debug/deps/libhello-8c4fb1941e38f02d.dylib" "-Wl,-exported_symbols_list,/var/folders/ks/zb8hmv_928dc9f8cg4rdwrzm0000gn/T/rustc.VmLlIoFBLVY4/list" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/Users/mhsjlw/Documents/rust-cpython/target/debug/deps" "-L" "/Users/mhsjlw/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/mhsjlw/Documents/rust-cpython/target/debug/deps/libcpython-af8234415d2422e1.rlib" "/Users/mhsjlw/Documents/rust-cpython/target/debug/deps/libnum_traits-ba977ae2944b0245.rlib" "/Users/mhsjlw/Documents/rust-cpython/target/debug/deps/libpython3_sys-71fbce9ef6e0fe2f.rlib" "/Users/mhsjlw/Documents/rust-cpython/target/debug/deps/liblibc-83c2bd88b43ecde3.rlib" "/Users/mhsjlw/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd-f1544d51c14ee547.rlib" "/Users/mhsjlw/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-0973ad751bdffbae.rlib" "/Users/mhsjlw/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libunwind-30637a1739b412eb.rlib" "/Users/mhsjlw/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librand-6ce8560490ee791c.rlib" "/Users/mhsjlw/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcollections-77c40ab2fac1172e.rlib" "/Users/mhsjlw/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc-40208fb59386bff5.rlib" "/Users/mhsjlw/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc_system-15f9862e7487bd75.rlib" "/Users/mhsjlw/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liblibc-cba64299ce12485f.rlib" "/Users/mhsjlw/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd_unicode-a98ebaa82aaee358.rlib" "/Users/mhsjlw/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcore-cfc94a4f91ad8df0.rlib" "/Users/mhsjlw/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-51cf9867f46a760f.rlib" "-l" "System" "-l" "pthread" "-l" "c" "-l" "m" "-dynamiclib" "-Wl,-dylib"
  = note: Undefined symbols for architecture x86_64:
  "_PyExc_UnicodeDecodeError", referenced from:
      _$LT$cpython..objects..exc..UnicodeDecodeError$u20$as$u20$cpython..python..PythonObjectWithCheckedDowncast$GT$::downcast_from::h7646be070dd5fbae in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "_PyExc_TypeError", referenced from:
      _$LT$cpython..objects..exc..TypeError$u20$as$u20$cpython..python..PythonObjectWithTypeObject$GT$::type_object::h672ee656309ba398 in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "_PyExc_OverflowError", referenced from:
      _$LT$cpython..objects..exc..OverflowError$u20$as$u20$cpython..python..PythonObjectWithTypeObject$GT$::type_object::h9fd1395398434977 in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "_PyLong_AsLong", referenced from:
      cpython::objects::num::_$LT$impl$u20$cpython..conversion..FromPyObject$LT$$u27$source$GT$$u20$for$u20$i32$GT$::extract::h465ba6c10c053a4c in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "_PyModule_Type", referenced from:
      _$LT$cpython..objects..module..PyModule$u20$as$u20$cpython..python..PythonObjectWithCheckedDowncast$GT$::downcast_from::h0114603e06464dd2 in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "_PyType_IsSubtype", referenced from:
      _$LT$cpython..objects..module..PyModule$u20$as$u20$cpython..python..PythonObjectWithCheckedDowncast$GT$::downcast_from::h0114603e06464dd2 in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
      _$LT$cpython..objects..exc..UnicodeDecodeError$u20$as$u20$cpython..python..PythonObjectWithCheckedDowncast$GT$::downcast_from::h7646be070dd5fbae in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "_PyExc_SystemError", referenced from:
      cpython::function::handle_panic::hb3c5bb3452cd9c98 in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
      _$LT$cpython..objects..exc..SystemError$u20$as$u20$cpython..python..PythonObjectWithTypeObject$GT$::type_object::hcd3ab4a42fd7256d in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "_PyErr_SetString", referenced from:
      cpython::function::handle_panic::hb3c5bb3452cd9c98 in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "_Py_InitializeEx", referenced from:
      cpython::pythonrun::prepare_freethreaded_python::_$u7b$$u7b$closure$u7d$$u7d$::h3e5bf0f52c5577fb in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "_PyGILState_Ensure", referenced from:
      cpython::pythonrun::GILGuard::acquire::hb8d911a0e2e1a4c3 in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "_PyObject_Str", referenced from:
      cpython::objectprotocol::ObjectProtocol::str::h5723365d3085f6bf in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "_PyEval_ThreadsInitialized", referenced from:
      cpython::pythonrun::prepare_freethreaded_python::_$u7b$$u7b$closure$u7d$$u7d$::h3e5bf0f52c5577fb in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "_PyDict_Next", referenced from:
      cpython::objects::dict::PyDict::items::h9b652d4b52c01c7b in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "_PyErr_Print", referenced from:
      cpython::err::panic_after_error::h5585969fad56f873 in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "_PyDict_GetItem", referenced from:
      cpython::objects::dict::PyDict::get_item::_$u7b$$u7b$closure$u7d$$u7d$::hde7be6bd4be042aa in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "_Py_IsInitialized", referenced from:
      cpython::pythonrun::prepare_freethreaded_python::_$u7b$$u7b$closure$u7d$$u7d$::h3e5bf0f52c5577fb in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "_PyEval_InitThreads", referenced from:
      cpython::pythonrun::prepare_freethreaded_python::_$u7b$$u7b$closure$u7d$$u7d$::h3e5bf0f52c5577fb in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
      cpython::py_module_initializer_impl::habcf172643911ba1 in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "_PyGILState_Release", referenced from:
      _$LT$cpython..pythonrun..GILGuard$u20$as$u20$core..ops..Drop$GT$::drop::h9541f74e2c15ac67 in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "_PyEval_SaveThread", referenced from:
      cpython::pythonrun::prepare_freethreaded_python::_$u7b$$u7b$closure$u7d$$u7d$::h3e5bf0f52c5577fb in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "_PyDict_Size", referenced from:
      cpython::objects::dict::PyDict::len::h3722ff94b5b02841 in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "_PyObject_SetAttr", referenced from:
      cpython::objectprotocol::ObjectProtocol::setattr::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::h3c7ebc16f3c5d937 in hello-8c4fb1941e38f02d.0.o
      cpython::objectprotocol::ObjectProtocol::setattr::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::hff7931ac82966c4d in hello-8c4fb1941e38f02d.0.o
  "_PyErr_Occurred", referenced from:
      cpython::err::PyErr::occurred::hdc230d6ef9c8c1cc in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "_PyUnicode_AsUTF8AndSize", referenced from:
      cpython::objects::string::PyString::data_impl::h1e40eab4a04bf62b in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "_PyModule_Create2", referenced from:
      python3_sys::modsupport::PyModule_Create::h9236f3481c0ebd20 in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "_PyUnicodeDecodeError_Create", referenced from:
      cpython::objects::exc::UnicodeDecodeError::new::h7d9e93e4a13bd345 in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "_PyErr_Restore", referenced from:
      cpython::err::PyErr::restore::hf510b2f1020e0a82 in hello-8c4fb1941e38f02d.0.o
      cpython::err::PyErr::restore::hf510b2f1020e0a82 in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "_PyErr_Fetch", referenced from:
      cpython::err::PyErr::fetch::h7215baacee0b22cc in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "_PyCFunction_NewEx", referenced from:
      cpython::function::py_fn_impl::h4aec2c3b06820361 in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "__Py_NoneStruct", referenced from:
      cpython::python::Python::None::ha1d600fb8a09e703 in hello-8c4fb1941e38f02d.0.o
  "_PyUnicode_FromStringAndSize", referenced from:
      cpython::objects::string::PyString::new::new_impl::h9e63a10a492e43b9 in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "_PyErr_PrintEx", referenced from:
      cpython::err::PyErr::print::h7efc48c392c6973c in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
  "__Py_Dealloc", referenced from:
      _$LT$T$u20$as$u20$cpython..python..PyDrop$GT$::release_ref::h72530f3a400946d8 in hello-8c4fb1941e38f02d.0.o
      _$LT$T$u20$as$u20$cpython..python..PyDrop$GT$::release_ref::h9cc402971666efed in hello-8c4fb1941e38f02d.0.o
      _$LT$cpython..objects..object..PyObject$u20$as$u20$core..ops..Drop$GT$::drop::h8b50daa097304487 in libcpython-af8234415d2422e1.rlib(cpython-af8234415d2422e1.0.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)


error: aborting due to previous error

error: Could not compile `hello`.

To learn more, run the command again with --verbose.

I'm assuming it's trying to use the wrong version on Python as it's referencing Python 2 symbols? How can I fix this?

@AraHaan
Copy link

AraHaan commented Feb 17, 2017

Uninstall Python 2 and install 3.6 as super-user using homebrew. That is what I would do.

@dgrunwald
Copy link
Owner

This error has nothing to do with Python 2. Python 3.x uses the same symbols.

When compiling extension modules, the symbols are supposed to stay unresolved; so that the binary extension module isn't bound to a specific build of the Python interpreter: http://blog.tim-smith.us/2015/09/python-extension-modules-os-x/

Unfortunately the OSX linker errors out on unresolved symbols by default, and it doesn't seem possible to pass the required -bundle -undefined dynamic_lookup option via cargo: rust-lang/rfcs#1766

You have to either:

  1. manually pass the linker option (e.g. via RUSTFLAGS)
    or
  2. disable features = ["extension-module"] in extensions/hello/Cargo.toml so that the extension module is linked against the python library. An extension module compiled without this feature will only work with the exact python interpreter against which it was built.

@ghost
Copy link
Author

ghost commented Feb 17, 2017

Ok. I've tested both option 1 and 2 and they both seem to clear it up for me. Thanks!

@ghost ghost closed this as completed Feb 17, 2017
@fafhrd91
Copy link

fafhrd91 commented Mar 9, 2017

it is possible to pass extra link arguments with cargo
I added setup tools extension with does that https://github.com/fafhrd91/setuptools-rust

cargo rustc --features "cpython/extension-module-2-7 cpython/python27-sys" --release -- -C link-arg="-undefined" -C link-arg="dynamic_loopup"

@purew
Copy link
Contributor

purew commented Jul 16, 2018

Ok. I've tested both option 1 and 2 and they both seem to clear it up for me. Thanks!

Neither of the two options seem to solve the problem today. How do you go about building a python-module on osx today?

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

No branches or pull requests

4 participants