Tensorflow-Lite CMake Build Fails On Windows With VS Build Generator
@embeddetech Could you ensure that you're not building with options related to Python bindings or Unix-specific features if you don't need them. Please make sure the appropriate requirements for the required dependencies like pybind11 are added to your project settings.
Thank you! Hi @sushreebarsa , 
I didn't specify any settings, as shown above, so it would be just building with the default settings. I would expect that building with the default settings should work. 

I have used Tensorflow Lite for many years, and it has never built properly on WIndows. I have had to spend months to get it working. Now I'm getting back to it again, and am much more familiar with CMake, more understanding of what's happening when I follow the build instructions. I followed these instructions:

https://www.tensorflow.org/lite/guide/build_cmake

 @embeddetech Could you double-check your CMake command line. Ensure you're passing the necessary flags for your platform and desired build configurations.
Use the -DCMAKE_VERBOSE_MAKEFILE=ON flag to see more detailed information about the build process and identify potential missing dependencies.
Please let us know the outcome?
Thank you! Hi @sushreebarsa ,
As shown above and reproduced in the video below, I don't have any necessary flags for my platform. Visual Studio is my default platform, and that is the desired build system. I would expect the build to not fail when using the default configuration. I believe the video below should be reproducible, and represents a build problem with Tensorflow that definitely needs to be resolved. Thanks!


https://github.com/tensorflow/tensorflow/assets/13501663/1e185200-ae09-4ecf-a4fb-4a790efc7317

 Hi @pkgoogle,

Please look into the issue

Thank You Hi @embeddetech,

I was able to build the "tensorflow-lite" solution in VS 2022 community:
![Screenshot 2023-12-27 at 11 14 10 AM (3)](https://github.com/tensorflow/tensorflow/assets/132095473/68667315-0010-40ca-81eb-4b45041e2430)

This was on master, can you try again with master or nightly? 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. Hi @pkgoogle,
I tried again and got the same results:

![image](https://github.com/tensorflow/tensorflow/assets/13501663/c6a75d05-80f7-453e-ab49-6c2a3a55ccab)

The exact steps are below. 

Current working directory is C:\tensorflow_test:
git clone https://github.com/tensorflow/tensorflow
mkdir tensorflow_build
cd tensorflow_build
cmake ..\tensorflow\tensorflow\lite
cmake --build .

After running the CMake build command, it ran to completion, and didn't produce any obvious errors, but also doesn't clearly indicate that it built successfully. When I open it in VS2022 and build it, it fails with the same errors as before.



 
https://github.com/tensorflow/tensorflow/assets/13501663/010d6f5e-bad6-44cd-85b2-e826385e76b9

 Hi @embeddetech, I suspect our difference is due to environmental issues, can you check a couple of things for me:

Check your workloads in VS (Tools -> Get Tools and Features...), here's mine:
![Screenshot 2024-01-05 at 1 13 32 PM (3)](https://github.com/tensorflow/tensorflow/assets/132095473/0207739d-d476-40ed-9e72-8efe5fa44724)

From your error message, it seems python related so ensure you have the Python development one, but it might not hurt to just match mine for now.

I am using a Windows Server 2022 Datacenter OS so that's a possibility... also what is your cmake version? mine is 3.28.1, lastly are you using command prompt or powershell? Thanks for your help. Hi @pkgoogle ,
I just tried with Powershell and got the same results. I had not installed the Python workload or Data Science workload, I installed those and got the same results without regenerating the build system (I'm going to try that now). I am using CMake 3.24.2. @pkgoogle Update: I installed the latest version of CMake, 3.28.1, did a clean build generation and build from PowerShell, and got the same results:

![image](https://github.com/tensorflow/tensorflow/assets/13501663/e7113418-b5b2-4117-89b6-c1148b00ddf3)
 @pkgoogle I also installed the Python and Data Science workloads for the above test. Hi @embeddetech, have you tried with the "Linux & embedded development with C++" workload, reason being some of your missing headers are GNU C headers/functions/libraries, perhaps that will install it, which solution/project are you opening exactly? Also give me the exact steps for what you are doing in VS ... like:

1. Open <path/to/(project|solution)/from/tf-root>
2. Set to debug
3. Click Green Run Button

Please adjust to what you are actually doing. Thanks for your help. Hi @pkgoogle ,
Sorry, I forgot to mention that my "Linux & embedded development with C++" workload is also installed. Please see below for my VS2022 installation config.

![image](https://github.com/tensorflow/tensorflow/assets/13501663/c5d7546c-a73b-4380-8652-746cd9d56be4)

My working test folder begins with C:\tensorflow_test, and I clone the tensorflow with git clone https://github.com/tensorflow/tensorflow as outlined above. My build folder is located at C:\tensorflow_test\tensorflow_build. After running the CMake build generation and build, my build system/Visual Studio solution is located at "C:\tensorflow_test\tensorflow_build\tensorflow-lite.sln". 

1) Open Visual Studio 2022 (in admin mode, for kicks).
2) Open the solution at C:\tensorflow_test\tensorflow_build\tensorflow-lite.sln
3) Confirm that the "ALL_BUILD" project is "Set As Startup Project".
4) Confirm that the build configuration is set to "Debug", platform "x64". 
4) Click "Build->Build Solution".

The build fails as shown by the errors above. I'll dump the build outputs in the message to follow.

 Build started at 3:20 PM...
1>------ Skipped Build: Project: uninstall, Configuration: Debug x64 ------
1>Project not selected to build for this solution configuration 
2>------ Skipped Build: Project: flatbuffers-flatc, Configuration: Debug x64 ------
2>Project not selected to build for this solution configuration 
3>------ Skipped Build: Project: NightlyMemoryCheck, Configuration: Debug x64 ------
3>Project not selected to build for this solution configuration 
4>------ Skipped Build: Project: Nightly, Configuration: Debug x64 ------
4>Project not selected to build for this solution configuration 
5>------ Skipped Build: Project: Experimental, Configuration: Debug x64 ------
5>Project not selected to build for this solution configuration 
6>------ Skipped Build: Project: Continuous, Configuration: Debug x64 ------
6>Project not selected to build for this solution configuration 
7>------ Build started: Project: label_image, Configuration: Debug x64 ------
8>------ Build started: Project: benchmark_model, Configuration: Debug x64 ------
9>------ Build started: Project: _pywrap_tensorflow_interpreter_wrapper, Configuration: Debug x64 ------
10>------ Skipped Build: Project: INSTALL, Configuration: Debug x64 ------
10>Project not selected to build for this solution configuration 
9>interpreter_wrapper.cc
7>bitmap_helpers.cc
8>register_custom_op.obj : error LNK2005: "void __cdecl RegisterSelectedOps(class tflite::MutableOpResolver *)" (?RegisterSelectedOps@@YAXPEAVMutableOpResolver@tflite@@@Z) already defined in benchmark_tflite_model.obj
9>C:\tensorflow_test\tensorflow\tensorflow\lite\python\interpreter_wrapper\interpreter_wrapper.h(28,10): error C1083: Cannot open include file: 'Python.h': No such file or directory
9>(compiling source file '../tensorflow/tensorflow/lite/python/interpreter_wrapper/interpreter_wrapper.cc')
9>interpreter_wrapper_pybind11.cc
9>C:\tensorflow_test\tensorflow\tensorflow\lite\python\interpreter_wrapper\interpreter_wrapper_pybind11.cc(19,10): error C1083: Cannot open include file: 'pybind11/functional.h': No such file or directory
9>numpy.cc
9>C:\tensorflow_test\tensorflow\tensorflow\lite\python\interpreter_wrapper\numpy.h(49,10): error C1083: Cannot open include file: 'Python.h': No such file or directory
9>(compiling source file '../tensorflow/tensorflow/lite/python/interpreter_wrapper/numpy.cc')
9>python_error_reporter.cc
9>C:\tensorflow_test\tensorflow\tensorflow\lite\python\interpreter_wrapper\python_error_reporter.h(19,10): error C1083: Cannot open include file: 'Python.h': No such file or directory
9>(compiling source file '../tensorflow/tensorflow/lite/python/interpreter_wrapper/python_error_reporter.cc')
9>python_utils.cc
9>C:\tensorflow_test\tensorflow\tensorflow\lite\python\interpreter_wrapper\python_utils.h(19,10): error C1083: Cannot open include file: 'Python.h': No such file or directory
9>(compiling source file '../tensorflow/tensorflow/lite/python/interpreter_wrapper/python_utils.cc')
9>Generating Code...
9>Done building project "_pywrap_tensorflow_interpreter_wrapper.vcxproj" -- FAILED.
7>label_image.cc
7>C:\tensorflow_test\tensorflow\tensorflow\lite\examples\label_image\bitmap_helpers.cc(18,10): error C1083: Cannot open include file: 'unistd.h': No such file or directory
8>C:\tensorflow_test\tensorflow_build\tools\benchmark\Debug\benchmark_model.exe : fatal error LNK1169: one or more multiply defined symbols found
8>Done building project "benchmark_model.vcxproj" -- FAILED.
7>C:\tensorflow_test\tensorflow\tensorflow\lite\examples\label_image\label_image.cc(19,10): error C1083: Cannot open include file: 'getopt.h': No such file or directory
7>stats_calculator.cc
7>memory_info.cc
7>profile_summarizer.cc
7>profile_summary_formatter.cc
7>time.cc
7>command_line_flags.cc
7>default_execution_provider.cc
7>delegate_provider.cc
7>utils.cc
7>tool_params.cc
7>xnnpack_delegate_provider.cc
7>xnnpack_plugin.cc
7>Generating Code...
7>Done building project "label_image.vcxproj" -- FAILED.
========== Build: 0 succeeded, 3 failed, 152 up-to-date, 7 skipped ==========
========== Build completed at 3:20 PM and took 19.594 seconds ==========
 @pkgoogle If you can provide your path to the python.h file on your system, that might help me see wha I'm missing...? Hi @embeddetech, I was actually able to replicate with your exact instructions ... I think I built a different file or built it a different way, for convenience I will summarize the steps here to replicate:

1. (in powershell)
```
git clone https://github.com/tensorflow/tensorflow
mkdir tensorflow_build
cd tensorflow_build
cmake ..\tensorflow\tensorflow\lite
cmake --build .
```

2. Open tensorflow_build\tensorflow-lite.sln in VS Community 2022 with Admin privileges
3. Confirm that the build configuration is set to "Debug", platform "x64".
4. Click "Build->Build Solution".

Hi @terryheo, can you please take a look? Thanks.
### Issue type

Bug

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

Yes

### Source

source

### TensorFlow version

2.15.0 (latest)

### Custom code

No

### OS platform and distribution

Windows 11

### Mobile device

_No response_

### Python version

_No response_

### Bazel version

_No response_

### GCC/compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

Tensorflow-lite build fails on Windows using CMake with Visual Studio 2022. In my experience, Tensorflow lite has never properly built with Visual Studio projects, and this is a major oversight.



### Standalone code to reproduce the issue

```shell
Exact steps to reproduce:

git clone https://github.com/tensorflow/tensorflow
mkdir tensorflow_build
cd tensorflow_build
cmake ..\tensorflow\tensorflow\lite
cmake --build .
```


### Relevant log output

```shell
Running the above, from the CMake output, it wasn't clear whether it built successfully or not, it seemed to just stop generating output:

  root_profiler.cc
  profiler.cc
  telemetry_setting_internal.cc
  sparsity_format_converter.cc
  schema_utils.cc
  Generating Code...

After then opening the Visual Studio 2022 project and building, it fails. 

C1083: Cannot open include file 'sys/mman.h': No such file or directory.
LNK1104: Cannot open file '..\..\Debug\tensorflow-lite.lib'
C1083: Cannot open include file: 'Python.h': No such file or directory
C1083: Cannot open include file: 'pybind11/functional.h': No such file or directory
C1083: Cannot open include file: 'Python.h': No such file or directory
C1083: Cannot open include file: 'Python.h': No such file or directory
C1083: Cannot open include file: 'Python.h': No such file or directory
C1083: Cannot open include file: 'unistd.h': No such file or directory
C1083: Cannot open include file: 'getopt.h': No such file or directory


PLEASE help resolve these Visual Studio build problems. I have great need of tflite as well as tflite-micro to build in Visual Studio.
```
