macOS requires you to use the BEAM bundle when compiling your code. You can do it by adding -bundle -bundle_loader /opt/local/lib/erlang/erts-16.0/bin/beam.smp
to your Makefile replacing the BEAM location with yours. Also, Erlang looks for .so files and not .dylib files when loading your NIF on macOS.