Error when run apps/howto_deploy

command: ./run_example.sh
output:

Build the libraries…
python prepare_test_libs.py
Traceback (most recent call last):
File “prepare_test_libs.py”, line 22, in
prepare_test_libs(os.path.join(curr_path, “./lib”))
File “prepare_test_libs.py”, line 13, in prepare_test_libs
fadd_dylib.export_library(dylib_path)
File “/tvm/python/tvm/module.py”, line 121, in export_library
fcompile(file_name, files, **kwargs)
File “/tvm/python/tvm/contrib/cc.py”, line 33, in create_shared
_linux_shared(output, objects, options, cc)
File “/tvm/python/tvm/contrib/cc.py”, line 58, in _linux_shared
raise RuntimeError(msg)
RuntimeError: Compilation error:
/usr/bin/ld: /tmp/tmp2sr91udo/lib.o: relocation R_X86_64_32S against `.rodata.cst4’ can not be used when making a shared object; recompile with -fPIC
/tmp/tmp2sr91udo/lib.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status

Makefile:24: recipe for target ‘lib/test_addone_sys.o’ failed
make: *** [lib/test_addone_sys.o] Error 1
Run the example
Run the deployment with all in one packed library…
run_example.sh: 10: run_example.sh: lib/cpp_deploy_pack: not found
Run the deployment with all in normal library…
run_example.sh: 13: run_example.sh: lib/cpp_deploy_normal: not found

how to solve this problem? thanks

This is weird, the normal behavior of the code should be something like:

Build the libraries..
python prepare_test_libs.py
g++ -c -std=c++11 -O2 -fPIC -I/tvm/include -I/tvm/dmlc-core/include -I/tvm/dlpack/include  -o lib/libtvm_runtime_pack.o  tvm_runtime_pack.cc
g++ -std=c++11 -O2 -fPIC -I/tvm/include -I/tvm/dmlc-core/include -I/tvm/dlpack/include  -o lib/cpp_deploy_pack  cpp_deploy.cc lib/test_addone_sys.o lib/libtvm_runtime_pack.o -L/tvm/build -ldl -lpthread
g++ -std=c++11 -O2 -fPIC -I/tvm/include -I/tvm/dmlc-core/include -I/tvm/dlpack/include  -o lib/cpp_deploy_normal  cpp_deploy.cc lib/test_addone_sys.o -L/tvm/build -ldl -lpthread -ltvm_runtime
Run the example
Run the deployment with all in one packed library...
[18:26:00] cpp_deploy.cc:59: Verify dynamic loading from test_addone_dll.so
[18:26:00] cpp_deploy.cc:52: Finish verification...
[18:26:00] cpp_deploy.cc:63: Verify load function from system lib
[18:26:00] cpp_deploy.cc:52: Finish verification...
Run the deployment with all in normal library...

I think the problem is caused by TVM compilation with llvm, I build TVM from source, but I don’t know why. I rebuild TVM with llvm-5.0, it’s solved now. Thanks for your reply.

For LLVM, any version above 4.0 should be fine.

Hey I realize this is an old post but there are some mistakes in the Makefile.

TVM_ROOT=$(shell cd …/…; pwd)
NNVM_PATH=nnvm
DMLC_CORE=${TVM_ROOT}/3rdparty/dmlc-core

PKG_CFLAGS = -std=c++11 -O2 -fPIC
-I${TVM_ROOT}/include
-I${DMLC_CORE}/include
-I${TVM_ROOT}/3rdparty/dlpack/include\

Just remove “3rdparty” and make any other changes needed for these to match so that it matches your actual paths.