bazel build tensorflow/lite  issues brought by "tensorflow\lite\kernels\stablehlo_reduce_window.cc"
I adjusted the order of header files as follows: 
#include "tensorflow/lite/array.h"
#include "tensorflow/lite/builtin_ops.h"
#include "tensorflow/lite/c/c_api_types.h"
#include "tensorflow/lite/core/c/builtin_op_data.h"
#include "tensorflow/lite/core/c/common.h"
#include "tensorflow/lite/core/subgraph.h"
#include "tensorflow/lite/kernels/kernel_util.h"
#include "tensorflow/lite/util.h"
Additionally, I repeatedly executed the Bazel command and made multiple adjustments to the positions of these two functions until the compilation passed successfully. > I adjusted the order of header files as follows: #include "tensorflow/lite/array.h" #include "tensorflow/lite/builtin_ops.h" #include "tensorflow/lite/c/c_api_types.h" #include "tensorflow/lite/core/c/builtin_op_data.h" #include "tensorflow/lite/core/c/common.h" #include "tensorflow/lite/core/subgraph.h" #include "tensorflow/lite/kernels/kernel_util.h" #include "tensorflow/lite/util.h" Additionally, I repeatedly executed the Bazel command and made multiple adjustments to the positions of these two functions until the compilation passed successfully.

我也遇到相同的问题，请问你是如何修改这个文件的，能否把这个文件的全部代码发出来？ > I adjusted the order of header files as follows: #include "tensorflow/lite/array.h" #include "tensorflow/lite/builtin_ops.h" #include "tensorflow/lite/c/c_api_types.h" #include "tensorflow/lite/core/c/builtin_op_data.h" #include "tensorflow/lite/core/c/common.h" #include "tensorflow/lite/core/subgraph.h" #include "tensorflow/lite/kernels/kernel_util.h" #include "tensorflow/lite/util.h" Additionally, I repeatedly executed the Bazel command and made multiple adjustments to the positions of these two functions until the compilation passed successfully.

我也遇到相同的问题，请问你是如何修改这个文件的，能否把这个文件的全部代码发出来？ > > I adjusted the order of header files as follows: #include "tensorflow/lite/array.h" #include "tensorflow/lite/builtin_ops.h" #include "tensorflow/lite/c/c_api_types.h" #include "tensorflow/lite/core/c/builtin_op_data.h" #include "tensorflow/lite/core/c/common.h" #include "tensorflow/lite/core/subgraph.h" #include "tensorflow/lite/kernels/kernel_util.h" #include "tensorflow/lite/util.h" Additionally, I repeatedly executed the Bazel command and made multiple adjustments to the positions of these two functions until the compilation passed successfully.
> 
> 我也遇到相同的问题，请问你是如何修改这个文件的，能否把这个文件的全部代码发出来？
调整了这个文件里 [stablehlo_reduce_window.txt](https://github.com/tensorflow/tensorflow/files/14811404/stablehlo_reduce_window.txt)
StridedReduce 和ReduceWindowImpl 两个函数的先后位置\tensorflow_src\tensorflow\lite\kernels\stablehlo_reduce_window.cc
Reversed the order of the functions StridedReduce and StridedReduce and ReduceWindowImpl in the file tensorflow_src\tensorflow\lite\kernels\stablehlo_reduce_window.cc. Hi @GuoHuanyu, I'm actually running into a different issue when I compile... I suspect our environments are not matching. Did you follow these steps https://www.tensorflow.org/install/source_windows for your environment? Did you run the command in PowerShell under admin privileges or Through some other interface? Are you in the r2.16 branch or in master/nightly? Are you following any instructions/documentation to do this? Thanks for your help. > Hi @GuoHuanyu, I'm actually running into a different issue when I compile... I suspect our environments are not matching. Did you follow these steps https://www.tensorflow.org/install/source_windows for your environment? Did you run the command in PowerShell under admin privileges or Through some other interface? Are you in the r2.16 branch or in master/nightly? Are you following any instructions/documentation to do this? Thanks for your help.

1. In above issues, i use the Developer Command Prompt for Visual Studio to execute  the command  `bazel build --config=monolithic --define=with_select_tf_ops=true -c opt //tensorflow/lite:libtensorflowlite.so`, `bazel build  -c opt //tensorflow/lite:tensorflowlite.dll`. its ok for my environment.
2. My environment includes Visual Studio 2019, Bazelisk, and Python 3.11.
3. i follow these steps https://www.tensorflow.org/install/source_windows for my envirmonment to execute the command  `python ./configure.py` , `bazel build //tensorflow/tools/pip_package:build_pip_package`  using the source code from =https://github.com/tensorflow/tensorflow/releases/tag/v2.16.1. 
4. I am still encountering an error in stablehlo_reduce_window.cc. I fix it by reversing the order of the StridedReduce and ReduceWindowImpl functions, but the build process continues to fail with Developer Command Prompt or Developer PowerShell for Visual Studio in administrator mode,  `cl.exe  D8022 error`
5. Giving up 
 Hi @GuoHuanyu, apologies for the frustration, while I look more into this -- have you tried building/progressing with WSL instead? Generally speaking that will be a smoother experience. > Hi @GuoHuanyu, apologies for the frustration, while I look more into this -- have you tried building/progressing with WSL instead? Generally speaking that will be a smoother experience.

I haven't heard of or used WSL before. I would find some time to configure and compile based on WSL. Thank you for providing another good method! Hi @GuoHuanyu, another alternative if you need the tensorflow lite dll is building with cmake instead: https://www.tensorflow.org/lite/guide/build_cmake, let me know if that works for you or unblocks you. Thanks. > Hi @GuoHuanyu, another alternative if you need the tensorflow lite dll is building with cmake instead: https://www.tensorflow.org/lite/guide/build_cmake, let me know if that works for you or unblocks you. Thanks.
 
1. Thank you for your timely and professional response. 
2. I've experimented with reversing the order of the StridedReduce and ReduceWindowImpl functions and managed to successfully compile TensorFlow Lite using the commands `cmake ../tensorflow_src/tensorflow/lite` and `cmake --build . -j` in the Developer PowerShell for Visual Studio. 
3. However, this only produced a tensorflow-lite.lib file of 247MB, and I did not get the corresponding tensorflow-lite.dll.
4. That's why I resorted to using `bazel build -c opt //tensorflow/lite:tensorflowlite.dll`, which yielded both a lib and a dll file.  I can obtain a dll with `cmake ../tensorflow_src/tensorflow/lite/c` and` cmake --build . -j`, but I am unsure if it corresponds to the previously generated tensorflow-lite.lib. That's why I used `bazel build -c opt //tensorflow/lite:tensorflowlite.dll.`
5. If there is a way to generate both the lib and dll files using cmake, I believe it would be a better solution.
 Hi @GuoHuanyu, if `bazel build -c opt //tensorflow/lite:tensorflowlite.dll` fits your needs, I would say just try it out and see if you run into any other issues. If you required source changes to get that working, and you feel it is something that should be generally fixed (we may need some compile time condition that checks for Windows or something), please create a PR with your fixes so that we may fix it more generally (or at least get started with the review process). Typically, users don't need the static library ... may I understand your use case/context better -- just to ensure you are using best practices, the .lib may not be necessary. > Hi @GuoHuanyu, if `bazel build -c opt //tensorflow/lite:tensorflowlite.dll` fits your needs, I would say just try it out and see if you run into any other issues. If you required source changes to get that working, and you feel it is something that should be generally fixed (we may need some compile time condition that checks for Windows or something), please create a PR with your fixes so that we may fix it more generally (or at least get started with the review process). Typically, users don't need the static library ... may I understand your use case/context better -- just to ensure you are using best practices, the .lib may not be necessary.

Ok，i will create a PR with my fixes, thank your  timely  response. This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. 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/64376">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/64376">No</a>
 I think I get into the same issue when building the example from MediaPipe, and the solution above (reordering of the functions `StridedReduce` and `ReduceWindowImpl`) doesn't work for me.

What I found instead is that the problem seems to be the comment before the function `ReduceWindowImpl`, which ends with an extended ASCII character `┘` and followed by the function definition in the next line.

A simple fix for this is to add a new line between the comment and the function definition.  
(Or add any visible ASCII character at the end of the comment could fix the problem, I guess)
```cpp
// Recursively computes strided reductions using a sliding window over the
// given tensor.
//
// The window is defined using a shape and a dilation. The shape defines the
// elements that the window will let the reduction *see*. The dilation defines
// the step between window elements.
//
// For instance: the following window has a [2, 2] shape and [2, 3] dilations.
//
//    3
// ┌────┐
// ┌─┐   ┌─┐
// │X│X X│X│┐
// └─┘   └─┘│2
//  X X X X ┘
// ┌─┐   ┌─┐
// │X│X X│X│
// └─┘   └─┘
// <- add new line HERE
template <class Op, class Type>
void ReduceWindowImpl(const Type* input, Type* output,
```

I don't know why the comment would cause the compilation issue, but this solution works for me.
Hopefully this will be useful for someone like me if the previous solution doesn't work. (Also found the same [issue](https://stackoverflow.com/questions/78322183/got-trouble-during-on-building-mediapipe-example-hand-tracking-cpu) on stackoverflow)

---

For more details, here is my setup:
- OS: Windows 10
- Bazel: 6.1.1
- GCC/compiler: Visual Studio 2019
- Python: 3.9
- TensorFlow: commit [75bb98b](https://github.com/tensorflow/tensorflow/commit/75bb98bd9d3998431aca05afd4be03e233b14425) (specified in the bazel workspace)
- MediaPipe: commit [72f28f3](https://github.com/google/mediapipe/commit/72f28f37e573c68bccd5e37eea526665ea2303fa)

What I have done:
- Followed the [MediaPipe installation instruction for Windows](https://developers.google.com/mediapipe/framework/getting_started/install#installing_on_windows) and successfully built the `hello_world` example.
- Tried to build the `hand_tracking_cpu` example with the following command but failed.
  ```shell
  bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 --action_env PYTHON_BIN_PATH="C://Python39//python.exe" mediapipe/examples/desktop/hand_tracking:hand_tracking_cpu
  ```

The error message I got:
```shell
ERROR: C:/users/<USER>/_bazel_<USER>/<HASH>/external/org_tensorflow/tensorflow/lite/kernels/BUILD:869:11: Compiling tensorflow/lite/kernels/stablehlo_reduce_window.cc failed: (Exit 2): cl.exe failed: error executing command (from target @org_tensorflow//tensorflow/lite/kernels:builtin_op_kernels) C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE ... (remaining 126 arguments skipped)
cl : Command line warning D9002 : ignoring unknown option '-O3'
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(361): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(361): error C2143: syntax error: missing ',' before '*'
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(368): error C2065: 'depth': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(368): error C2065: 'rank': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(369): error C2065: 'output_shape': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(369): error C2065: 'depth': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(370): error C2065: 'output': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(370): error C2065: 'init': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(371): error C2065: 'Op': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(371): error C2065: 'input': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(371): error C2065: 'window_shape': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(371): error C2065: 'window_reduce_strides': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(372): error C2065: 'output': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(372): error C2065: 'rank': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(373): error C2065: 'input': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(373): error C2065: 'window_offset_strides': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(373): error C2065: 'depth': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(374): error C2065: 'output': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(374): error C2065: 'output_strides': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(374): error C2065: 'depth': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(377): error C2065: 'output_shape': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(377): error C2065: 'depth': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(378): error C2065: 'Op': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(378): error C2065: 'input': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(378): error C2065: 'output': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(378): error C2065: 'output_shape': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(378): error C2065: 'output_strides': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(379): error C2065: 'window_offset_strides': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(379): error C2065: 'window_shape': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(380): error C2065: 'window_reduce_strides': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(380): error C2065: 'init': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(380): error C2065: 'rank': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(380): error C2065: 'depth': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(381): error C2065: 'input': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(381): error C2065: 'window_offset_strides': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(381): error C2065: 'depth': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(382): error C2065: 'output': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(382): error C2065: 'output_strides': undeclared identifier
external/org_tensorflow/tensorflow/lite/kernels/stablehlo_reduce_window.cc(382): error C2065: 'depth': undeclared identifier
Target //mediapipe/examples/desktop/hand_tracking:hand_tracking_cpu failed to build
```
### Issue type

Build/Install

### Have you reproduced the bug with TensorFlow Nightly?

Yes

### Source

source

### TensorFlow version

tf 2.16.1

### Custom code

Yes

### OS platform and distribution

window 10

### Mobile device

_No response_

### Python version

3.11

### Bazel version

bazelisk

### GCC/compiler version

visual studio 2019

### CUDA/cuDNN version

no

### GPU model and memory

_No response_

### Current behavior?

I encountered an issue while performing a build with the latest version using the command bazel build -c opt //tensorflow/lite:tensorflowlite. The problem stems from the file tensorflow\lite\kernels\stablehlo_reduce_window.cc, specifically at line 372, which contains the following function:
 template <class Op, class Type>
void ReduceWindowImpl(const Type* input, Type* output,
                      const int64_t* const output_shape,
                      const int64_t* const output_strides,
                      const int64_t* const window_offset_strides,
                      const int64_t* const window_shape,
                      const int64_t* const window_reduce_strides,
                      const Type init, const int rank, const int depth)
I managed to resolve this issue by moving the above function above the following function:
template <class Op, class Type>
void StridedReduce(const Type* input, const int64_t* const shape,
                   const int64_t* const strides, Type& accu, const int rank,
                   const int depth)
I'm seeking alternative solutions or suggestions to address this issue. 


### Standalone code to reproduce the issue

```shell
bazel build -c opt //tensorflow/lite:tensorflowlite
```


### Relevant log output

```shell
ERROR: D:/deepreinforce/tensorflow_src/tensorflow/lite/kernels/BUILD:869:11: Compiling tensorflow/lite/kernels/stablehlo_reduce_window.cc failed: (Exit 2): cl.exe failed: error executing command (from target //tensorflow/lite/kernels:builtin_op_kernels)
  cd /d C:/users/guoy6/_bazel_guoy6/amvr52k2/execroot/org_tensorflow
  SET INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\ATLMFC\include;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\winrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\cppwinrt
    SET PATH=C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\\Extensions\Microsoft\IntelliCode\CLI;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\VC\VCPackages;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\TestWindow;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\bin\Roslyn;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Team Tools\Performance Tools\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Team Tools\Performance Tools;C:\Program Files (x86)\Microsoft Visual Studio\Shared\Common\VSPerfCollectionTools\vs2019\\x64;C:\Program Files (x86)\Microsoft Visual Studio\Shared\Common\VSPerfCollectionTools\vs2019\;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\Tools\devinit;C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x64;C:\Program Files (x86)\Windows Kits\10\bin\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\\MSBuild\Current\Bin;C:\Windows\Microsoft.NET\Framework64\v4.0.30319;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\Tools\;;C:\WINDOWS\system32;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja
    SET PWD=/proc/self/cwd
    SET PYTHON_BIN_PATH=C:/Users/Guoy6/AppData/Local/Programs/Python/Python311/python.exe
    SET PYTHON_LIB_PATH=C:/Users/Guoy6/AppData/Local/Programs/Python/Python311/Lib/site-packages
    SET TEMP=C:\Users\Guoy6\AppData\Local\Temp
    SET TF2_BEHAVIOR=1
    SET TMP=C:\Users\Guoy6\AppData\Local\Temp
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe @bazel-out/x64_windows-opt/bin/tensorflow/lite/kernels/_objs/builtin_op_kernels/stablehlo_reduce_window.obj.params
# Configuration: 77cd05648d5203f50dead44fd3ee45a61cf90f8b48918874c5fb79829874f482
# Execution platform: @local_execution_config_platform//:platform
cl:  warning D9002 :“-O3”
stablehlo_reduce_window.cc
tensorflow/lite/kernels/stablehlo_reduce_window.cc(361): error C4430: 
tensorflow/lite/kernels/stablehlo_reduce_window.cc(361): error C2143: 
tensorflow/lite/kernels/stablehlo_reduce_window.cc(368): error C2065: “depth”: 
tensorflow/lite/kernels/stablehlo_reduce_window.cc(368): error C2065: “rank”:
```
