You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows环境下TensorFlow 2.4.1 C++版本编译失败求助

Fixing "Cannot open include file: 'cudnn_ops_infer.h'" When Building TensorFlow 2.4.1 C++ API on Windows 10

I've run into this exact issue before when building TF 2.4.1 C++ on Windows, so let's break down what's going wrong and how to fix it:

First, Verify Your cuDNN File Structure

The error tells us Bazel can't find cudnn_ops_infer.h, so start by manually checking if this file exists in your cuDNN path. Navigate to D:/code/sdk/cudnn-11.0-windows-x64-v8.0.4.30/cuda/include — you should see cudnn_ops_infer.h, cudnn.h, and all other cuDNN header files here. If they're missing:

  • Double-check that you downloaded the correct cuDNN version (v8.0.4.30 for CUDA 11.0, Windows x64)
  • Re-extract the cuDNN zip file fully (sometimes extraction tools skip files if there's permission issues)

Fix Environment Variables

Even if you set paths in .tf_configure.bazelrc, Windows and Bazel sometimes rely on system environment variables to locate dependencies. Add these to your system environment variables:

  • INCLUDE: Append D:/code/sdk/cudnn-11.0-windows-x64-v8.0.4.30/cuda/include
  • LIB: Append D:/code/sdk/cudnn-11.0-windows-x64-v8.0.4.30/cuda/lib/x64
  • PATH: Append D:/code/sdk/cudnn-11.0-windows-x64-v8.0.4.30/cuda/bin

After adding these, restart your command prompt/Bazel terminal — environment variables won't take effect until you do this.

Tweak Your Bazel Configuration

Your .tf_configure.bazelrc has the right TF_CUDA_PATHS, but sometimes Bazel needs explicit guidance for cuDNN's include directory. Add this line to your .tf_configure.bazelrc:

build --action_env CUDNN_INCLUDE_DIR="D:/code/sdk/cudnn-11.0-windows-x64-v8.0.4.30/cuda/include"

Alternatively, re-run python configure.py and when prompted for the cuDNN path, make sure you input the full path to the cuda folder (with Linux-style slashes) and confirm that the script detects all cuDNN components correctly.

Clean Bazel Cache and Rebuild

Bazel's cache can hold onto old path references that cause conflicts. Run this command to fully clear the cache:

bazel clean --expunge

Then re-run your build command. For the TensorFlow C++ API, the standard command is:

bazel build --config=cuda --config=opt //tensorflow:tensorflow_cc

A Quick Note on Windows Compatibility

Yes, building TensorFlow 2.4.1 C++ API on Windows is absolutely possible — I've done it successfully with the exact same toolchain versions you're using (CUDA 11.0, cuDNN 8.0.4.30, Bazel 3.1.0, Python 3.6.8). The biggest pitfalls are path formatting (always use Linux-style slashes in Bazel configs) and ensuring all dependencies are properly linked via both Bazel config and system environment variables.

内容的提问来源于stack exchange,提问作者Alexander Soklev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 08:57:39