Libtvm_runtime.so: undefined symbol

  • I install tvm from source on raspberry pi 4.
  • config make: set(USE_RPC ON), set(USE_LLVM OFF)
  • cmake runtime
  • gcc version gcc (Raspbian 8.3.0-6+rpi1) 8.3.0
  • python version 3.7.3

Error log

Python 3.7.3 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tvm
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/tools/tvm/python/tvm/__init__.py", line 25, in <module>
    from ._ffi.base import TVMError, __version__
  File "/home/pi/tools/tvm/python/tvm/_ffi/__init__.py", line 28, in <module>
    from .base import register_error
  File "/home/pi/tools/tvm/python/tvm/_ffi/base.py", line 58, in <module>
    _LIB, _LIB_NAME = _load_lib()
  File "/home/pi/tools/tvm/python/tvm/_ffi/base.py", line 50, in _load_lib
    lib = ctypes.CDLL(lib_path[0], ctypes.RTLD_GLOBAL)
  File "/usr/lib/python3.7/ctypes/__init__.py", line 356, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: /home/pi/tools/tvm/build/libtvm_runtime.so: undefined symbol: _ZTVN10__cxxabiv120__function_type_infoE

My ~/.bashrc file

export TVM_HOME=/home/pi/tools/tvm
export PYTHONPATH=$TVM_HOME/python:$TVM_HOME/topi/python:${PYTHONPATH}
export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib/gcc/arm-linux-gnueabihf/8:/usr/lib/arm-linux-gnueabihf:$LD_LIBRARY_PATH
export LIBRARY_PATH=/usr/lib/arm-linux-gnueabihf:$LIBRARY_PATH
export AR="/usr/bin/gcc-ar"
export CC="/usr/bin/gcc"
export CXX="/usr/bin/g++"
export CPP="/usr/bin/cpp"

It seems that libtvm_runtime.so miss some libraries (liblstdc++), but I have no idea how to fix it. I installed another gcc version(gcc-9) before, then change back to the default gcc version(gcc-8). Probably the path is not correctly set. Could you give some hints how to solve this? Thanks a lot.

 $ ldd libtvm_runtime.so
        linux-vdso.so.1 (0xbee7e000)
        /usr/lib/arm-linux-gnueabihf/libarmmem-${PLATFORM}.so => /usr/lib/arm-linux-gnueabihf/libarmmem-v7l.so (0xb6e0e000)
        libdl.so.2 => /lib/arm-linux-gnueabihf/libdl.so.2 (0xb6de4000)
        libgcc_s.so.1 => /usr/lib/gcc/arm-linux-gnueabihf/8/libgcc_s.so.1 (0xb6db7000)
        libpthread.so.0 => /lib/arm-linux-gnueabihf/libpthread.so.0 (0xb6d8d000)
        libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6c3f000)
        /lib/ld-linux-armhf.so.3 (0xb6f0a000)
$ nm libtvm_runtime.so | grep _ZTVN10
         U _ZTVN10__cxxabiv117__class_type_infoE
         U _ZTVN10__cxxabiv119__pointer_type_infoE
         U _ZTVN10__cxxabiv120__function_type_infoE
         U _ZTVN10__cxxabiv120__si_class_type_infoE
         U _ZTVN10__cxxabiv121__vmi_class_type_infoE

I found the reason of such undefined symbol error. cmake use CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/gcc as default instead of CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/c++

In CMakeFiles/tvm_runtime.dir/link.txt, it use /usr/bin/gcc rather than /usr/bin/c++. So the libtvm_runtime.so cannot find libstdc++.so to link. I manually modify link.txt, and make again. It worked.