TensorFlow build for C++ using Bazel failed with error "Link.exe 1120 failed: error executing command " in Windows 10

Steps followed:

  1. Installed Bazel version 5.1.1 and set the environment variables.
  2. Installed msys2 and set the environment variables.
  3. Installed visual studio professional 2019 for C++ build .
  4. Installed python 3.9.13
  5. Installed python dependencies like numpy, wheel, keras
  6. Configured TensorFlow with default configuration using ‘./configure’
  7. Build TensorFlow using the command
    ‘bazel --host_jvm_args=-Xmx4g --output_base=D:\0 build --jvmopt=“-server -Xms2g” --config=opt tensorflow:tensorflow_cc’

While tried to build ‘tensorflow_cc’ with the above command, the compilation is success but the linking failed with error 1120.
→ Attached error screenshot

The following versions of tools are used for building:
Tensorflow - 2.10.0
Python - 3.9.13
Visual studio - Professional 2019
Bazel - 5.1.1
MSYS - 2
Tried the GPU build with ‘Cuda 11.2 and Cudnn 8.1’ also but the result is same.

Note: Earlier tried to build tensorflow.dll (not tensorflow_cc), for which the compilation and linking was success and tensorflow.dll got generated.
But while linking the tensorflow.dll to visual studio cpp project, I got ‘unresolved external symbol errors’. It seems the dll generated by this method has the ‘C’ symbols instead of ‘CPP’ symbols in it.