Skip to content

[Bug] Cannot find -lxml2 when linking libtvm.so on Ubuntu 22.04 (WSL2) #17696

Closed
@930727fre

Description

@930727fre

Expected behavior

TVM should successfully compile and link libtvm.so without missing -lxml2.

Actual behavior

The build fails with a linker error stating that -lxml2 cannot be found:

[100%] Building CXX object CMakeFiles/tvm_objs.dir/src/target/llvm/llvm_instance.cc.o
[100%] Building CXX object CMakeFiles/tvm_objs.dir/src/target/llvm/llvm_module.cc.o
/home/fre930727/tvm/src/target/tag.cc: In function ‘void __static_initialization_and_destruction_0(int, int)’:
/home/fre930727/tvm/src/target/tag.cc:462:1: note: variable tracking size limit exceeded with ‘-fvar-tracking-assignments’, retrying without
  462 | }  // namespace tvm
      | ^
[100%] Built target tvm_objs
[100%] Linking CXX shared library libtvm.so
[100%] Linking CXX shared library libtvm_allvisible.so
/usr/bin/ld: cannot find -lxml2: /usr/bin/ld: cannot find -lxml2: No such file or directory
No such file or directory
collect2: error: ld returned 1 exit status
collect2: error: ld returned 1 exit status
gmake[2]: *** [CMakeFiles/tvm.dir/build.make:1408: libtvm.so] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:208: CMakeFiles/tvm.dir/all] Error 2
gmake[1]: *** Waiting for unfinished jobs....
gmake[2]: *** [CMakeFiles/tvm_allvisible.dir/build.make:1408: libtvm_allvisible.so] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:309: CMakeFiles/tvm_allvisible.dir/all] Error 2
gmake: *** [Makefile:136: all] Error 2

Environment

  • OS: Ubuntu 22.04 (WSL2)
  • CPU: Intel i5-12400
  • TVM Version: 12e72c2

Steps to reproduce

  1. Follow the instructions in the [TVM installation guide](https://tvm.apache.org/docs/install/from_source.html).

  2. Execute the following shell script:

    # make sure to start with a fresh environment
    conda env remove -n tvm-build-venv
    # create the conda environment with build dependency
    conda create -n tvm-build-venv -c conda-forge \
        "llvmdev>=15" \
        "cmake>=3.24" \
        git \
        python=3.11
    # enter the build environment
    conda activate tvm-build-venv
    git clone --recursive https://github.com/apache/tvm tvm
    
    cd tvm
    rm -rf build && mkdir build && cd build
    # Specify the build configuration via CMake options
    cp ../cmake/config.cmake .
    # controls default compilation flags (Candidates: Release, Debug, RelWithDebInfo)
    echo "set(CMAKE_BUILD_TYPE RelWithDebInfo)" >> config.cmake
    
    # LLVM is a must dependency for compiler end
    echo "set(USE_LLVM \"llvm-config --ignore-libllvm --link-static\")" >> config.cmake
    echo "set(HIDE_PRIVATE_SYMBOLS ON)" >> config.cmake
    
    # GPU SDKs, turn on if needed
    echo "set(USE_CUDA   OFF)" >> config.cmake
    echo "set(USE_METAL  OFF)" >> config.cmake
    echo "set(USE_VULKAN OFF)" >> config.cmake
    echo "set(USE_OPENCL OFF)" >> config.cmake
    
    # cuBLAS, cuDNN, cutlass support, turn on if needed
    echo "set(USE_CUBLAS OFF)" >> config.cmake
    echo "set(USE_CUDNN  OFF)" >> config.cmake
    echo "set(USE_CUTLASS OFF)" >> config.cmake
    cmake .. && cmake --build . --parallel $(nproc)
  3. The build fails with the above linker error.

Troubleshooting Attempts

  • Added debugging options:

    echo "set(CMAKE_BUILD_TYPE Debug)" >> config.cmake
    echo "set(USE_ALTERNATIVE_LINKER OFF)" >> config.cmake
    echo "set(USE_LIBBACKTRACE On)" >> config.cmake
    
  • Installed libxml2 via Conda:

    conda install -c conda-forge libxml2
    

Questions

  • Is libxml2 required to be installed via apt rather than Conda for TVM to find it?
  • Are there specific CMake flags I should set to properly link against libxml2?
  • Any recommendations for debugging linker issues in this context?

Triage

  • needs-triage

Any help would be greatly appreciated. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triagePRs or issues that need to be investigated by maintainers to find the right assignees to address ittype: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions