codypiersall / pynng

Python bindings for Nanomsg Next Generation.
https://pynng.readthedocs.io
MIT License
260 stars 58 forks source link

Building on Mac M1 needs a tweak. #110

Open SpaceMonkeyForever opened 1 year ago

SpaceMonkeyForever commented 1 year ago

I get the following error when compiling on Mac M1:

[ 98%] Building C object src/CMakeFiles/nng.dir/supplemental/http/http_server.c.o
[100%] Linking C static library ../libnng.a
[100%] Built target nng
creating build
creating build/lib.macosx-12-arm64-cpython-310
creating build/lib.macosx-12-arm64-cpython-310/pynng
copying pynng/options.py -> build/lib.macosx-12-arm64-cpython-310/pynng
copying pynng/_version.py -> build/lib.macosx-12-arm64-cpython-310/pynng
copying pynng/__init__.py -> build/lib.macosx-12-arm64-cpython-310/pynng
copying pynng/_aio.py -> build/lib.macosx-12-arm64-cpython-310/pynng
copying pynng/tls.py -> build/lib.macosx-12-arm64-cpython-310/pynng
copying pynng/sockaddr.py -> build/lib.macosx-12-arm64-cpython-310/pynng
copying pynng/exceptions.py -> build/lib.macosx-12-arm64-cpython-310/pynng
copying pynng/nng.py -> build/lib.macosx-12-arm64-cpython-310/pynng
running build_ext
generating cffi module 'build/temp.macosx-12-arm64-cpython-310/pynng._nng.c'
creating build/temp.macosx-12-arm64-cpython-310
build_nng_lib()
building 'pynng._nng' extension
creating build/temp.macosx-12-arm64-cpython-310/build
creating build/temp.macosx-12-arm64-cpython-310/build/temp.macosx-12-arm64-cpython-310
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Inng/include -I/Users/spacemonkey/Projects/mangotrader/mangotrader/env/include -I/opt/homebrew/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/include/python3.10 -c build/temp.macosx-12-arm64-cpython-310/pynng._nng.c -o build/temp.macosx-12-arm64-cpython-310/build/temp.macosx-12-arm64-cpython-310/pynng._nng.o
clang -bundle -undefined dynamic_lookup build/temp.macosx-12-arm64-cpython-310/build/temp.macosx-12-arm64-cpython-310/pynng._nng.o ./nng/build/libnng.a ./mbedtls/prefix/lib/libmbedtls.a ./mbedtls/prefix/lib/libmbedx509.a ./mbedtls/prefix/lib/libmbedcrypto.a -lpthread -latomic -o build/lib.macosx-12-arm64-cpython-310/pynng/_nng.abi3.so
ld: library not found for -latomic
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command '/usr/bin/clang' failed with exit code 1

The main error ld: library not found for -latomic seems to be resolved by removing -latmoice from the linking step. So, instead, I can do:

clang -bundle -undefined dynamic_lookup build/temp.macosx-12-arm64-cpython-310/build/temp.macosx-12-arm64-cpython-310/pynng._nng.o ./nng/build/libnng.a ./mbedtls/prefix/lib/libmbedtls.a ./mbedtls/prefix/lib/libmbedx509.a ./mbedtls/prefix/lib/libmbedcrypto.a -lpthread ~-latomic~ -o build/lib.macosx-12-arm64-cpython-310/pynng/_nng.abi3.so

Then I can python setup.py install and I can import it fine. It seems to work fine when I tested REQ/REP against a Rust REP server.

codypiersall commented 1 year ago

I think there was a PR that fixed this, if it's possible for you to retry from master I'd appreciate it. I don't have a Mac so can't actually test anything on my end.