Cannot locate symbol "expf" error on android(Host system: Ubuntu)

Hi Experts,

I got following error message when load the model library for android: /workspace/tvm/src/runtime/dso_library.cc:84: Check failed: lib_handle_ != nullptr: Failed to load dynamic shared library libface-mnet12_1_640_480_llvm_lib.so dlopen failed: cannot locate symbol "expf" referenced by "/data/app/com.example.myapplication-2/lib/arm64/libface-mnet12_1_640_480_llvm_lib.so"....

it means the math function “expf” cann’t be found. but actually i can found the math library libm.so has been loaded in my dynamic library:

# readelf -d lib/linux/libtvmfacer.so

Dynamic section at offset 0x33528 contains 31 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libopencv_java4.so]
 0x0000000000000001 (NEEDED)             Shared library: [libtvm_runtime.so]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so]
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so]
 0x000000000000000e (SONAME)             Library soname: [libtvmfacer.so]
 0x000000000000001d (RUNPATH)            Library runpath: [.]
 0x0000000000000019 (INIT_ARRAY)         0x426a8
 0x000000000000001b (INIT_ARRAYSZ)       72 (bytes)
 0x000000000000001a (FINI_ARRAY)         0x426f0
 0x000000000000001c (FINI_ARRAYSZ)       16 (bytes)
 0x0000000000000004 (HASH)               0x228
 0x000000006ffffef5 (GNU_HASH)           0x1360
 0x0000000000000005 (STRTAB)             0x56a8
 0x0000000000000006 (SYMTAB)             0x2078
 0x000000000000000a (STRSZ)              36012 (bytes)
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000003 (PLTGOT)             0x43758
 0x0000000000000002 (PLTRELSZ)           4944 (bytes)
 0x0000000000000014 (PLTREL)             RELA
 0x0000000000000017 (JMPREL)             0x11700
 0x0000000000000007 (RELA)               0xe838
 0x0000000000000008 (RELASZ)             11976 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x000000000000001e (FLAGS)              BIND_NOW
 0x000000006ffffffb (FLAGS_1)            Flags: NOW
 0x000000006ffffffe (VERNEED)            0xe7d8
 0x000000006fffffff (VERNEEDNUM)         3
 0x000000006ffffff0 (VERSYM)             0xe354
 0x000000006ffffff9 (RELACOUNT)          41
 0x0000000000000000 (NULL)               0x0

and libtvmfacer.so will load model library:libface-mnet12_1_640_480_llvm_lib.so

so i am confused, hope you experts can give me a sign.

thanks.

If for android, should link with math library. Could do like this : lib.export_library(path_lib, ndk.create_shared, options=["-lm"])

really appreciate your advise.

but it seems do not work, the python compile it as an executable programe:

File "tvm_from_mxnet_android.py", line 73, in GenerateModels
    lib.export_library(path_lib, ndk.create_shared, options=['-lm'])

  File "/usr/local/lib/python3.5/dist-packages/tvm-0.6.0-py3.5-linux-x86_64.egg/tvm/module.py", line 161, in export_library
    fcompile(file_name, files, **kwargs)

  File "/usr/local/lib/python3.5/dist-packages/tvm-0.6.0-py3.5-linux-x86_64.egg/tvm/contrib/ndk.py", line 65, in create_shared
    raise RuntimeError(msg)

RuntimeError: Compilation error:
/opt/android-sdk-linux/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/21/crtbegin_dynamic.o: In function `_start_main':
crtbegin.c:(.text+0x38): undefined reference to `main'
crtbegin.c:(.text+0x3c): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Make sure it produces shared library.

lib.export_library(path_lib, ndk.create_shared, options=["-lm", '-shared', '-fPIC'])

1 Like

So many thanks to you.

It works!!!

I think it should be add by default in our ndk.py. I want to encourage you contribute it back to our code. Would you like to do this? :slight_smile:

thanks for your trust.

and as i know it seems is not needed sometimes. another team in my company compiled another model(for feature comparison), and they found there is no need for libm.so.

Yeah, but add it could make sure we work well on both conditions, right?

Yes you are right,I will contribute it back later. thanks again.

1 Like