CentOS build error

Hi, I am trying to build the latest tvm 0.11 version in CentOS 7 with gcc/g++ version of 9.3.1 using rhel devtoolset. I installed llvmdev 11.1 and changed cmake.config file as follows:

set(USE_CUDA ON)
set(USE_LLVM /path/to/llvm-config)

and ran the following command

cmake -D CMAKE_C_COMPILER=/opt/rh/devtoolset-9/root/usr/bin/gcc -D CMAKE_CXX_COMPILER=/opt/rh/devtoolset-9/root/usr/bin/g++ ..  
make -j16

leading to a linker error:

[100%] Building CXX object CMakeFiles/tvm_objs.dir/src/relay/backend/contrib/example_target_hooks/tir_to_runtime.cc.o
[100%] Building CXX object CMakeFiles/tvm_objs.dir/src/contrib/hybrid/codegen_hybrid.cc.o
[100%] Built target tvm_objs
[100%] Linking CXX shared library libtvm.so
ld.lld: error: undefined symbol: llvm::Intrinsic::getName(unsigned int, llvm::ArrayRef<llvm::Type*>)
>>> referenced by codegen_llvm.cc
>>>               CMakeFiles/tvm_objs.dir/src/target/llvm/codegen_llvm.cc.o:(tvm::codegen::CodeGenLLVM::CreateIntrinsic(tvm::tir::CallNode const*))
>>> referenced by llvm_module.cc
>>>               CMakeFiles/tvm_objs.dir/src/target/llvm/llvm_module.cc.o:(tvm::runtime::PackedFuncObj::Extractor<tvm::runtime::PackedFuncSubObj<void tvm::runtime::TypedPackedFunc<tvm::runtime::String (long)>::AssignTypedLambda<tvm::codegen::'lambda7'(long)>(tvm::codegen::'lambda7'(long), std::string)::'lambda'(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*)> >::Call(tvm::runtime::PackedFuncObj const*, tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*))

ld.lld: error: undefined symbol: llvm::parseIR(llvm::MemoryBufferRef, llvm::SMDiagnostic&, llvm::LLVMContext&, llvm::function_ref<llvm::Optional<std::string> (llvm::StringRef)>)
>>> referenced by llvm_instance.cc
>>>               CMakeFiles/tvm_objs.dir/src/target/llvm/llvm_instance.cc.o:(tvm::codegen::LLVMInstance::ParseBuffer(llvm::MemoryBuffer const&) const)

ld.lld: error: undefined symbol: llvm::sys::getDefaultTargetTriple()
>>> referenced by llvm_instance.cc
>>>               CMakeFiles/tvm_objs.dir/src/target/llvm/llvm_instance.cc.o:(tvm::codegen::LLVMTargetInfo::LLVMTargetInfo(tvm::codegen::LLVMInstance&, tvm::Target const&))

ld.lld: error: undefined symbol: llvm::TargetRegistry::lookupTarget(std::string const&, std::string&)
>>> referenced by llvm_instance.cc
>>>               CMakeFiles/tvm_objs.dir/src/target/llvm/llvm_instance.cc.o:(tvm::codegen::LLVMTargetInfo::GetOrCreateTargetMachine(bool))
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/tvm.dir/build.make:1348: libtvm.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:932: CMakeFiles/tvm.dir/all] Error 2
make: *** [Makefile:146: all] Error 2

I tried passing the llvm header path to cmake (CXXFLAGS=-isystem\ llvm/header/path cmake …) but no use. Building libtvm.so for the same repository had no problem in other servers (I tried in ubuntu 20.04, 18.04).

Edit: I checked cmake LLVM_LIBRARY_PATH, LLVM_INCLUDE_DIR path and header inside it, but seem there is nothing wrong.

Sounds like we have some issues linking LLVM. Would you like to try static linking first to identify if there is any misconfiguration?

Hi @junrushao, I tried setting cmake.config to set(USE_LLVM "/path/to/llvm-config --link-static") and checked that CMakeFiles/tvm.dir/link.txt has included all static libraries that are related to errors. However, the linker error still won’t go away. I also tried upgrading/downgrading llvmdev to several version but didn’t work. I installed llvmdev via conda package provided by anaconda if this helps.

This is kinda weird and I cannot explain it. Is there any other versions of LLVM that exists on your system?

@junrushao I am in a server environment using conda virtual environement to install llvm packages. Locally the server has built-in llvm-config and lld version of 12.0.0. I tried using this instead of conda packages and finally linker error disappeared. I’m still trying to figure out the reason why linker can’t find symbol in the first place, but thanks for looking through my question :slight_smile:

Hi @Jungi-lee, this might not apply for your problem 100%, but just wanted to mention we build TVM routinely using CentOS, for packaging purposes.

All the scripts and configurations are in the tlcpack repo: https://github.com/tlc-pack/tlcpack

1 Like