bazel build -c opt --config=macos //tensorflow/lite/c:tensorflowlite_c --verbose_failure   ld: unknown option: --no-undefined
Hi @Yongle-Fu Thanks for reporting this issue.

I was able to reproduce this issue. Please find the screenshot below.

<img width="567" alt="image" src="https://github.com/tensorflow/tensorflow/assets/118897289/0348572b-e363-4303-ac37-d01ea8e9fa3f">

@pkgoogle Can you please look into this?

Thanks. I was able to reproduce:

```
ERROR: /Users/pisethk/git/tensorflow/tensorflow/lite/c/BUILD:27:24: Linking tensorflow/lite/c/libtensorflowlite_c.dylib failed: (Exit 1): cc_wrapper.sh failed: error executing command (from target //tensorflow/lite/c:libtensorflowlite_c.dylib) 
  (cd /private/var/tmp/_bazel_pisethk/0b4260bf24636eb9896878b03d13e41b/execroot/org_tensorflow && \
  exec env - \
    APPLE_SDK_PLATFORM=MacOSX \
    APPLE_SDK_VERSION_OVERRIDE=13.3 \
    PATH=/Users/pisethk/Library/Caches/bazelisk/downloads/bazelbuild/bazel-6.1.0-darwin-arm64/bin:/opt/homebrew/opt/make/libexec/gnubin:/Users/pisethk/miniforge3/bin:/Users/pisethk/miniforge3/condabin:/usr/local/git/git-google/bin:/usr/local/git/current/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/homebrew/bin \
    PYTHON_BIN_PATH=/Users/pisethk/miniforge3/bin/python3 \
    PYTHON_LIB_PATH=/Users/pisethk/miniforge3/lib/python3.10/site-packages \
    TF2_BEHAVIOR=1 \
    XCODE_VERSION_OVERRIDE=14.3.1.14E300b \
    ZERO_AR_DATE=1 \
  external/local_config_cc/cc_wrapper.sh @bazel-out/darwin_arm64-opt/bin/tensorflow/lite/c/libtensorflowlite_c.dylib-2.params)
# Configuration: 909810f2fd11f4b96aeaacdf0d5bc1e200c23f5a11823d712c54452c08c5a573
# Execution platform: @local_execution_config_platform//:platform
ld: unknown option: --no-undefined
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error in child process '/usr/bin/xcrun'. 1
Target //tensorflow/lite/c:tensorflowlite_c failed to build
INFO: Elapsed time: 143.211s, Critical Path: 16.06s
INFO: 1228 processes: 370 internal, 858 local.
FAILED: Build did NOT complete successfully
```

In https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/c/BUILD#L29:
```
...
tflite_cc_shared_object(
    name = "tensorflowlite_c",
    linkopts = tflite_linkopts_no_undefined() + select({
        "//tensorflow:ios": [
            "-Wl,-exported_symbols_list,$(location //tensorflow/lite/c:exported_symbols.lds)",
        ],
        "//tensorflow:macos": [
            "-Wl,-exported_symbols_list,$(location //tensorflow/lite/c:exported_symbols.lds)",
        ],
        "//tensorflow:windows": [],
        "//conditions:default": [
            "-Wl,--version-script,$(location //tensorflow/lite/c:version_script.lds)",
        ],
    }),
...
```
the linker options are defined per platform.

This case should be handled here:
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/build_def.bzl#L144
```

def tflite_linkopts_no_undefined():
    """Defines linker flags to enable errors for undefined symbols.

    This enables link-time errors for undefined symbols even when linking
    shared libraries, where the default behaviour on many systems is to only
    report errors for undefined symbols at runtime.
    """
    return if_oss(
        select({
            "//tensorflow:ios": [
                # iOS linker uses "--undefined error" instead of "--no-undefined".
                "-Wl,-undefined,error",
            ],
            "//conditions:default": ["-Wl,--no-undefined"],
        }),
        select({
            # Can't enable errors for undefined symbols for asan/msan/tsan mode,
            # since undefined symbols in shared libraries (references to symbols
            # that will be defined in the main executable) are normal and
            # expected in those cases.
            "//tools/cpp:asan_build": [],
            "//tools/cpp:msan_build": [],
            "//tools/cpp:tsan_build": [],
            "//tensorflow:ios": [
                # iOS linker uses "--undefined error" instead of "--no-undefined".
                "-Wl,-undefined,error",
            ],
            "//conditions:default": ["-Wl,--no-undefined"],
        }),
    )
```

I believe somehow the new bazel update is causing
```
"//conditions:default": ["-Wl,--no-undefined"],
```
to be hit with macOS.

@terryheo can you please take a look at this? Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60745">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60745">No</a>

<details><summary>Click to expand!</summary> 
 
 ### Issue Type

Build/Install

### Have you reproduced the bug with TF nightly?

Yes

### Source

source

### Tensorflow Version

2.12

### Custom Code

Yes

### OS Platform and Distribution

_No response_

### Mobile device

_No response_

### Python version

3.11.3

### Bazel version

6.1

### GCC/Compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current Behaviour?

(base) ➜  tensorflow git:(master) ✗ bazel build -c opt --config=macos //tensorflow/lite/c:tensorflowlite_c --verbose_failures
INFO: Options provided by the client:
  Inherited 'common' options: --isatty=1 --terminal_columns=198
INFO: Reading rc options for 'build' from /Users/yongle/project/C/tensorflow/.bazelrc:
  Inherited 'common' options: --experimental_repo_remote_exec
INFO: Reading rc options for 'build' from /Users/yongle/project/C/tensorflow/.bazelrc:
  'build' options: --define framework_shared_object=true --define tsl_protobuf_header_only=true --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true --spawn_strategy=standalone -c opt --announce_rc --define=grpc_no_ares=true --noincompatible_remove_legacy_whole_archive --enable_platform_specific_config --define=with_xla_support=true --config=short_logs --config=v2 --define=no_aws_support=true --define=no_hdfs_support=true --experimental_cc_shared_library --experimental_link_static_libraries_once=false --incompatible_enforce_config_setting_visibility
INFO: Reading rc options for 'build' from /Users/yongle/project/C/tensorflow/.tf_configure.bazelrc:
  'build' options: --action_env PYTHON_BIN_PATH=/Users/yongle/.pyenv/versions/3.11.3/bin/python3 --action_env PYTHON_LIB_PATH=/Users/yongle/.pyenv/versions/3.11.3/lib/python3.11/site-packages --python_path=/Users/yongle/.pyenv/versions/3.11.3/bin/python3 --action_env ANDROID_NDK_HOME=/Users/yongle/Library/Android/sdk/ndk/21.4.7075529 --action_env ANDROID_NDK_API_LEVEL=21 --action_env ANDROID_BUILD_TOOLS_VERSION=33.0.1 --action_env ANDROID_SDK_API_LEVEL=33 --action_env ANDROID_SDK_HOME=/Users/yongle/Library/Android/sdk
INFO: Reading rc options for 'build' from /Users/yongle/project/C/tensorflow/.bazelrc:
  'build' options: --deleted_packages=tensorflow/compiler/mlir/tfrt,tensorflow/compiler/mlir/tfrt/benchmarks,tensorflow/compiler/mlir/tfrt/jit/python_binding,tensorflow/compiler/mlir/tfrt/jit/transforms,tensorflow/compiler/mlir/tfrt/python_tests,tensorflow/compiler/mlir/tfrt/tests,tensorflow/compiler/mlir/tfrt/tests/ir,tensorflow/compiler/mlir/tfrt/tests/analysis,tensorflow/compiler/mlir/tfrt/tests/jit,tensorflow/compiler/mlir/tfrt/tests/lhlo_to_tfrt,tensorflow/compiler/mlir/tfrt/tests/lhlo_to_jitrt,tensorflow/compiler/mlir/tfrt/tests/tf_to_corert,tensorflow/compiler/mlir/tfrt/tests/tf_to_tfrt_data,tensorflow/compiler/mlir/tfrt/tests/saved_model,tensorflow/compiler/mlir/tfrt/transforms/lhlo_gpu_to_tfrt_gpu,tensorflow/core/runtime_fallback,tensorflow/core/runtime_fallback/conversion,tensorflow/core/runtime_fallback/kernel,tensorflow/core/runtime_fallback/opdefs,tensorflow/core/runtime_fallback/runtime,tensorflow/core/runtime_fallback/util,tensorflow/core/tfrt/gpu,tensorflow/core/tfrt/run_handler_thread_pool,tensorflow/core/tfrt/runtime,tensorflow/core/tfrt/saved_model,tensorflow/core/tfrt/graph_executor,tensorflow/core/tfrt/saved_model/tests,tensorflow/core/tfrt/tpu,tensorflow/core/tfrt/utils,tensorflow/core/tfrt/utils/debug
INFO: Found applicable config definition build:short_logs in file /Users/yongle/project/C/tensorflow/.bazelrc: --output_filter=DONT_MATCH_ANYTHING
INFO: Found applicable config definition build:v2 in file /Users/yongle/project/C/tensorflow/.bazelrc: --define=tf_api_version=2 --action_env=TF2_BEHAVIOR=1
INFO: Found applicable config definition build:macos in file /Users/yongle/project/C/tensorflow/.bazelrc: --apple_platform_type=macos --copt=-DGRPC_BAZEL_BUILD --features=archive_param_file --copt=-w --define=PREFIX=/usr --define=LIBDIR=$(PREFIX)/lib --define=INCLUDEDIR=$(PREFIX)/include --define=PROTOBUF_INCLUDE_PATH=$(PREFIX)/include --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
INFO: Found applicable config definition build:macos in file /Users/yongle/project/C/tensorflow/.bazelrc: --apple_platform_type=macos --copt=-DGRPC_BAZEL_BUILD --features=archive_param_file --copt=-w --define=PREFIX=/usr --define=LIBDIR=$(PREFIX)/lib --define=INCLUDEDIR=$(PREFIX)/include --define=PROTOBUF_INCLUDE_PATH=$(PREFIX)/include --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
INFO: Build options --action_env and --python_path have changed, discarding analysis cache.
INFO: Analyzed target //tensorflow/lite/c:tensorflowlite_c (107 packages loaded, 2952 targets configured).
INFO: Found 1 target...
ERROR: /Users/yongle/project/C/tensorflow/tensorflow/lite/c/BUILD:28:24: Linking tensorflow/lite/c/libtensorflowlite_c.dylib failed: (Exit 1): cc_wrapper.sh failed: error executing command (from target //tensorflow/lite/c:libtensorflowlite_c.dylib)
  (cd /private/var/tmp/_bazel_yongle/fb676000c07d36afe13b22c7b593df69/execroot/org_tensorflow && \
  exec env - \
    ANDROID_BUILD_TOOLS_VERSION=33.0.1 \
    ANDROID_NDK_API_LEVEL=21 \
    ANDROID_NDK_HOME=/Users/yongle/Library/Android/sdk/ndk/21.4.7075529 \
    ANDROID_SDK_API_LEVEL=33 \
    ANDROID_SDK_HOME=/Users/yongle/Library/Android/sdk \
    APPLE_SDK_PLATFORM=MacOSX \
    APPLE_SDK_VERSION_OVERRIDE=13.3 \
    PATH=/Users/yongle/Library/Caches/bazelisk/downloads/bazelbuild/bazel-6.1.0-darwin-x86_64/bin:/Users/yongle/miniconda3/bin:/Users/yongle/miniconda3/condabin:/Users/yongle/Library/pnpm:/usr/local/opt/node@19/bin:/Users/yongle/.pyenv/shims:/Users/yongle/.local/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Apple/usr/bin://Library/Developer/Panda3D/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Users/yongle/.cargo/bin:/usr/local/bin:91139ANDROID_NDK_ROOT/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin:/Users/yongle/Library/Android/sdk/emulator:/Users/yongle/Library/Android/sdk/tools:/Users/yongle/Library/Android/sdk/platform-tools:/Users/yongle/Library/Android/sdk/build-tools/33.0.1:/usr/local/bin:/Users/yongle/.pub-cache/bin:/opt/fvm/default/bin:/opt/fvm/default/bin/cache/dart-sdk/bin:/Users/yongle/Documents/apache-maven-3.8.1/bin \
    PYTHON_BIN_PATH=/Users/yongle/.pyenv/versions/3.11.3/bin/python3 \
    PYTHON_LIB_PATH=/Users/yongle/.pyenv/versions/3.11.3/lib/python3.11/site-packages \
    TF2_BEHAVIOR=1 \
    XCODE_VERSION_OVERRIDE=14.3.0.14E222b \
    ZERO_AR_DATE=1 \
  external/local_config_cc/cc_wrapper.sh @bazel-out/darwin-opt/bin/tensorflow/lite/c/libtensorflowlite_c.dylib-2.params)
# Configuration: 0147ddac8ddd69cb32a57bdf7993d2379760736293c350037f6e0ed5fdf8b453
# Execution platform: @local_execution_config_platform//:platform
ld: unknown option: --no-undefined
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error in child process '/usr/bin/xcrun'. 1
Target //tensorflow/lite/c:tensorflowlite_c failed to build
INFO: Elapsed time: 124.453s, Critical Path: 47.17s
INFO: 407 processes: 2 internal, 405 local.
FAILED: Build did NOT complete successfully

### Standalone code to reproduce the issue

```shell
bazel build -c opt --config=macos //tensorflow/lite/c:tensorflowlite_c --verbose_failures
```


### Relevant log output

_No response_</details>