'Golang and tensorflow in mac M1 / arm64: ld: library not found for ltensorflow

I'm trying to build a go application that uses tensorflow and I'm getting that error when I try to build it.

make build 
# github.com/tensorflow/tensorflow/tensorflow/go
ld: library not found for -ltensorflow
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [build/binaries] Error 2

I have currently installed conda (as explained https://developer.apple.com/metal/tensorflow-plugin/) and all these packages, including tensorflow.

tensorboard               2.8.0                    pypi_0    pypi
tensorboard-data-server   0.6.1                    pypi_0    pypi
tensorboard-plugin-wit    1.8.1              pyhd8ed1ab_0    conda-forge
tensorflow                2.4.0rc0                 pypi_0    pypi
tensorflow-addons         0.11.2                   pypi_0    pypi
tensorflow-base           2.7.0           cpu_py38h93cb87e_0    conda-forge
tensorflow-datasets       4.5.2                    pypi_0    pypi
tensorflow-deps           2.8.0                         0    apple
tensorflow-estimator      2.7.0           cpu_py38h4dea37b_0    conda-forge
tensorflow-metadata       1.6.0                    pypi_0    pypi
tensorflow-metal          0.4.0                    pypi_0    pypi

Of course, the env is activated, I've also pointed the DYDL path to:

export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/Users/myuser/mambaforge/envs/mlp/libs/

But no luck. I tried to build it from source using bazel but I wasn't able to do so (tried bazel versions 4 and 5). Also from homebrew:

brew install --build-from-source libtensorflow 
Running `brew update --preinstall`...
==> Auto-updated Homebrew!
==> ./configure
==> bazel build --jobs=10 --compilation_mode=opt --copt=-march=native tensorflow:libtensorflow.so tensorflow:install_headers tensorflow/tools/benchmark:benchmark_model tensorfl
Last 15 lines from /Users/myuser/Library/Logs/Homebrew/libtensorflow/02.bazel:
Repository rule _tf_http_archive defined at:
  /private/tmp/libtensorflow-20220224-18156-wpuf5/tensorflow-2.7.0/third_party/repo.bzl:66:35: in <toplevel>
INFO: Repository farmhash_archive instantiated at:
  /private/tmp/libtensorflow-20220224-18156-wpuf5/tensorflow-2.7.0/WORKSPACE:15:14: in <toplevel>
  /private/tmp/libtensorflow-20220224-18156-wpuf5/tensorflow-2.7.0/tensorflow/workspace2.bzl:1082:28: in workspace
  /private/tmp/libtensorflow-20220224-18156-wpuf5/tensorflow-2.7.0/tensorflow/workspace2.bzl:64:13: in _initialize_third_party
  /private/tmp/libtensorflow-20220224-18156-wpuf5/tensorflow-2.7.0/third_party/farmhash/workspace.bzl:14:20: in repo
  /private/tmp/libtensorflow-20220224-18156-wpuf5/tensorflow-2.7.0/third_party/repo.bzl:113:21: in tf_http_archive
Repository rule _tf_http_archive defined at:
  /private/tmp/libtensorflow-20220224-18156-wpuf5/tensorflow-2.7.0/third_party/repo.bzl:66:35: in <toplevel>
ERROR: Analysis of target '//tensorflow:install_headers' failed; build aborted: 
INFO: Elapsed time: 140.750s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (165 packages loaded, 3586 targets configured)
FAILED: Build did NOT complete successfully (165 packages loaded, 3586 targets configured)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source