Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
930727fre opened this issue Mar 2, 2025 · 1 comment
Open
Labels
needs-triage PRs or issues that need to be investigated by maintainers to find the right assignees to address it type: bug

Comments

@930727fre
Copy link

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!

@930727fre 930727fre added needs-triage PRs or issues that need to be investigated by maintainers to find the right assignees to address it type: bug labels Mar 2, 2025
@ShihengCao
Copy link

hello, i encoutered the same problem and i resolved it. My solution is use the path of xml2 to replace the -lxml2 in link.txt.
use bash:~$ find $CONDA_PREFIX/lib -name "libxml2*" to get the path of lxml2.
I get a path like /$HOME/miniconda3/envs/tvm-build-venv/lib/libxml2.so, then use "/$HOME/miniconda3/envs/tvm-build-venv/lib/libxml2.so" to replace "-lxml2" in tvm/build/CMakeFiles/tvm_allvisible.dir/link.txt and tvm/build/CMakeFiles/tvm.dir/link.txt.
Hope this can work for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage PRs or issues that need to be investigated by maintainers to find the right assignees to address it type: bug
Projects
None yet
Development

No branches or pull requests

2 participants