apache / mxnet

Lightweight, Portable, Flexible Distributed/Mobile Deep Learning with Dynamic, Mutation-aware Dataflow Dep Scheduler; for Python, R, Julia, Scala, Go, Javascript and more
https://mxnet.apache.org
Apache License 2.0
20.79k stars 6.79k forks source link

Static Build with OPENCV Linking Error #18898

Open Zha0q1 opened 4 years ago

Zha0q1 commented 4 years ago

I used this cmake config

set(CMAKE_BUILD_TYPE "Distribution" CACHE STRING "Build type")
set(CFLAGS "-mno-avx" CACHE STRING "CFLAGS")
set(CXXFLAGS "-mno-avx" CACHE STRING "CXXFLAGS")

set(USE_CUDA OFF CACHE BOOL "Build with CUDA support")
set(USE_OPENCV ON CACHE BOOL "Build with OpenCV support")
set(USE_OPENMP ON CACHE BOOL "Build with Openmp support")
set(USE_MKL_IF_AVAILABLE OFF CACHE BOOL "Use Intel MKL if found")
set(USE_MKLDNN ON CACHE BOOL "Build with MKL-DNN support")
set(USE_LAPACK OFF CACHE BOOL "Build with lapack support")
set(USE_TVM_OP OFF CACHE BOOL "Enable use of TVM operator build system.")
set(USE_SSE ON CACHE BOOL "Build with x86 SSE instruction support")
set(USE_F16C OFF CACHE BOOL "Build with x86 F16C instruction support")
set(USE_LIBJPEG_TURBO ON CACHE BOOL "Build with libjpeg-turbo")
set(USE_DIST_KVSTORE ON CACHE BOOL "Build with DIST_KVSTORE support")

set(USE_INT64_TENSOR_SIZE ON CACHE BOOL "Use int64_t to represent the total number of elements in a tensor")

The compilation was successful but when importing mxnet this was the error message:

OSError: /home/ubuntu/.local/mxnet/libmxnet.so: undefined symbol: _gfortran_concat_string

Disabling opencv resolved the issue

szha commented 4 years ago

Looks like the same issue as this? https://github.com/xianyi/OpenBLAS/issues/460

leezu commented 4 years ago

Is this on master or on your modified code?

Zha0q1 commented 4 years ago

Is this on master or on your modified code?

This is on master

leezu commented 4 years ago

Why do you turn USE_LAPACK OFF? Do you build via the tools/staticbuild/build.s? Otherwise the Distribution build type is not supported.

Zha0q1 commented 4 years ago

Why do you turn USE_LAPACK OFF?

I am building with ilp64 mkl so lapack signatures are different. This is something I will work on fixing but for this build I turned it off.

Do you build via the tools/staticbuild/build.s?

Yes. The build succeeded but I ran into that error at runtime

leezu commented 4 years ago

I am building with ilp64 mkl

However you set USE_MKL_IF_AVAILABLE OFF and you didn't specify the BLAS option?

If you build with mkl blas, mxnet will not depend on libgfortran. As you build opencv with a dependency on libgfortran and static link opencv, you need to manually specify the dependency on libgfortran. It would be better to use a consistent BLAS library when building OpenCV and MXNet, ie also use MKL for OpenCV

Zha0q1 commented 4 years ago

However you set USE_MKL_IF_AVAILABLE OFF and you didn't specify the BLAS option?

Right, I overlooked this. But our cmake will still choose mkl as our choice of blas.

If you build with mkl blas, mxnet will not depend on libgfortran. As you build opencv with a dependency on libgfortran and static link opencv, you need to manually specify the dependency on libgfortran. It would be better to use a consistent BLAS library when building OpenCV and MXNet, ie also use MKL for OpenCV

Thanks for the insight! As discussed offline we will be providing a fix to this