使用Bazel编译TensorFlow适配Spleeterpp时遇tensorflow_cc库未找到错误
Let's break down why this error is happening and fix it step by step:
1. Library Path Mismatch
Your current Dockerfile copies TensorFlow shared libraries to $INSTALL_DIR/bin/, but most CMake modules (including add_tensorflow.cmake) expect libraries to live in a lib subdirectory under the install root, not bin. This is the primary reason the library isn't being detected.
2. Adjust the TensorFlow Library Installation Path
Update the TensorFlow installation step in your Dockerfile to place libraries in $INSTALL_DIR/lib instead of bin, and ensure we preserve symbolic links (critical for proper shared library resolution):
# tensorflow install ENV INSTALL_DIR=install ENV INCLUDE_DIR=$INSTALL_DIR/include RUN cd tensorflow && \ mkdir -p $INSTALL_DIR/lib && \ cp -a bazel-bin/tensorflow/libtensorflow_cc.so* $INSTALL_DIR/lib/ && \ mkdir -p $INSTALL_DIR/include && \ rsync -a --prune-empty-dirs --include '*/' --include '*.h' --exclude '*' tensorflow/ $INCLUDE_DIR/tensorflow && \ mkdir -p $INSTALL_DIR/include/third_party/eigen3/unsupported/ && \ cp -r ./bazel-tensorflow/external/eigen_archive/unsupported/Eigen $INSTALL_DIR/include/third_party/eigen3/unsupported/Eigen && \ cp -r ./bazel-tensorflow/external/eigen_archive/Eigen $INSTALL_DIR/include/third_party/eigen3/Eigen
Key changes here:
- Swapped
binforlibas the library storage directory - Added the
-aflag tocpto preserve symbolic links (sincelibtensorflow_cc.sois typically a symlink to a versioned library file)
3. Fix the Spleeterpp CMake Configuration
When running CMake for Spleeterpp, point TENSORFLOW_CC_INSTALL_DIR to the root $INSTALL_DIR (not the bin subdirectory). The CMake module will automatically look for libraries in $INSTALL_DIR/lib and headers in $INSTALL_DIR/include:
# spleeterpp build RUN mkdir build && cd build && \ cmake -DTENSORFLOW_CC_INSTALL_DIR=$INSTALL_DIR .. && \ cmake --build .
4. Verify the Final Library Structure
After these changes, your $INSTALL_DIR should follow this structure, which aligns with what Spleeterpp's CMake module expects:
install/ ├── lib/ │ ├── libtensorflow_cc.so │ ├── libtensorflow_cc.so.1 │ └── libtensorflow_cc.so.1.14.0 └── include/ ├── tensorflow/ └── third_party/ └── eigen3/
This should resolve the "tensorflow_cc library not found" error, as CMake can now locate the library in the standard lib directory under the specified install root.
内容的提问来源于stack exchange,提问作者loretoparisi

