cyrusbehr opened a new issue #15393: Unable to build mxnet with OpenCV4 on 
Raspberry Pi 3B
URL: https://github.com/apache/incubator-mxnet/issues/15393
 
 
   I am trying to build mxnet with OpenCV 4. Additionally, I am trying to use 
the OpenCV 4 static library files.  
   
   On my Raspberry Pi, I have the appropriate OpenCV files in `/usr/local/lib` :
   
   ```
   /usr/local/lib/cmake/opencv4
   /usr/local/lib/cmake/opencv4/OpenCVConfig.cmake
   /usr/local/lib/cmake/opencv4/OpenCVModules-release.cmake
   /usr/local/lib/cmake/opencv4/OpenCVConfig-version.cmake
   /usr/local/lib/cmake/opencv4/OpenCVModules.cmake
   /usr/local/lib/libopencv_gapi.a
   /usr/local/lib/libopencv_features2d.a
   /usr/local/lib/libopencv_objdetect.a
   /usr/local/lib/libopencv_photo.a
   /usr/local/lib/libopencv_video.a
   /usr/local/lib/libopencv_flann.a
   /usr/local/lib/libopencv_calib3d.a
   /usr/local/lib/libopencv_imgproc.a
   /usr/local/lib/opencv4
   /usr/local/lib/opencv4/3rdparty
   /usr/local/lib/opencv4/3rdparty/libquirc.a
   /usr/local/lib/opencv4/3rdparty/libade.a
   /usr/local/lib/opencv4/3rdparty/liblibwebp.a
   /usr/local/lib/opencv4/3rdparty/libtegra_hal.a
   /usr/local/lib/opencv4/3rdparty/liblibprotobuf.a
   /usr/local/lib/opencv4/3rdparty/libIlmImf.a
   /usr/local/lib/libopencv_stitching.a
   /usr/local/lib/libopencv_videoio.a
   /usr/local/lib/libopencv_dnn.a
   /usr/local/lib/libopencv_core.a
   /usr/local/lib/libopencv_ml.a
   /usr/local/lib/libopencv_highgui.a
   /usr/local/lib/libopencv_imgcodecs.a
   ```
   as well as the required include files in `/usr/local/include/opencv4`.
   
   To built mxnet, I am using the following version of gcc: `gcc (Raspbian 
4.8.5-4) 4.8.5`
   I first run the following commands: 
   ```
   sudo apt-get -y install ninja-build \
   liblapack* \
   libblas* \
   libopenblas* \
   && cd ~ \
   && git clone https://github.com/apache/incubator-mxnet.git --recursive \
   && cd incubator-mxnet
   ```
   Note that I do not install `libopencv*` which is shown in the guide 
[here](https://mxnet.incubator.apache.org/versions/master/install/index.html) 
as explicitly want to use opencv 4 (and the command `libopencv*` installs 
opencv 2). 
   
   Finally, I run the following command:
   
   ```
   cd ~/incubator-mxnet \
   && mkdir -p build \
   && cd build \
   && cmake \
                -DUSE_CPP_PACKAGE=1 \
           -DUSE_SSE=OFF \
           -DUSE_CUDA=OFF \
           -DUSE_OPENCV=ON \
           -DUSE_OPENMP=ON \
           -DUSE_MKL_IF_AVAILABLE=OFF \
           -DUSE_SIGNAL_HANDLER=ON \
           -DCMAKE_BUILD_TYPE=Release \
           -GNinja .. \
   && ninja -j1
   ```
   The cmake command outputs the following, indicating that opencv 4 was indeed 
found:
   
   ```
   -- Found OpenCV: /usr/local (found version "4.0.0") found components:  core 
highgui imgproc imgcodecs 
   -- OpenCV 4.0.0 found (/usr/local/lib/cmake/opencv4)
   --  OpenCV_LIBS=opencv_core;opencv_highgui;opencv_imgproc;opencv_imgcodecs
   
   ```
   
   When building, I get the following error:
   ```
   [252/296] Linking CXX executable im2rec
   FAILED: im2rec 
   : && /usr/bin/c++   -Wall -Wno-unknown-pragmas -Wno-sign-compare -O3 
-std=c++11 -fopenmp -std=c++0x -O3 -DNDEBUG   
CMakeFiles/im2rec.dir/tools/im2rec.cc.o  -o im2rec  -rdynamic 
-Wl,--whole-archive libmxnet.a -Wl,--no-whole-archive -lopenblas -lrt 
/usr/local/lib/libopencv_core.a /usr/local/lib/libopencv_highgui.a 
/usr/local/lib/libopencv_imgproc.a /usr/local/lib/libopencv_imgcodecs.a 
-llapack /usr/local/lib/libopencv_core.a /usr/local/lib/libopencv_highgui.a 
/usr/local/lib/libopencv_imgproc.a /usr/local/lib/libopencv_imgcodecs.a 
3rdparty/dmlc-core/libdmlc.a /usr/local/lib/libopencv_videoio.a 
/usr/local/lib/libopencv_imgcodecs.a /usr/local/lib/libopencv_imgproc.a 
/usr/local/lib/libopencv_core.a /usr/local/lib/opencv4/3rdparty/liblibwebp.a 
-ljpeg -lpng -ltiff -ljasper -ljpeg -lpng -ltiff -ljasper 
/usr/local/lib/opencv4/3rdparty/libIlmImf.a -lz -ldl -lm -lpthread 
/usr/local/lib/opencv4/3rdparty/libtegra_hal.a -lavcodec -lavformat -lavutil 
-lswscale -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 
-lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 
-lgthread-2.0 -lrt && :
   CMakeFiles/im2rec.dir/tools/im2rec.cc.o: In function `main':
   im2rec.cc:(.text.startup+0x1c0c): undefined reference to 
`cv::imencode(std::string const&, cv::_InputArray const&, std::vector<unsigned 
char, std::allocator<unsigned char> >&, std::vector<int, std::allocator<int> > 
const&)'
   libmxnet.a(image_io.cc.o): In function `cv::Mat::Mat(int, int, int, void*, 
unsigned int) [clone .constprop.758]':
   image_io.cc:(.text+0x104): undefined reference to `cv::error(int, 
std::string const&, char const*, char const*, int)'
   libmxnet.a(iter_image_det_recordio.cc.o): In function 
`mxnet::io::ImageDetRecordIOParser<float>::ParseNext(std::vector<mxnet::io::InstVector<float>,
 std::allocator<mxnet::io::InstVector<float> > >*)::{lambda()#1}::operator()() 
const':
   
iter_image_det_recordio.cc:(.text._ZZN5mxnet2io22ImageDetRecordIOParserIfE9ParseNextEPSt6vectorINS0_10InstVectorIfEESaIS5_EEENKUlvE_clEv[_ZZN5mxnet2io22ImageDetRecordIOParserIfE9ParseNextEPSt6vectorINS0_10InstVectorIfEESaIS5_EEENKUlvE_clEv]+0x1254):
 undefined reference to `cv::error(int, std::string const&, char const*, char 
const*, int)'
   libmxnet.a(iter_image_recordio.cc.o): In function 
`mxnet::io::ImageRecordIOParser<float>::ParseNext(std::vector<mxnet::io::InstVector<float>,
 std::allocator<mxnet::io::InstVector<float> > >*) [clone ._omp_fn.23]':
   iter_image_recordio.cc:(.text+0x4b24): undefined reference to 
`cv::error(int, std::string const&, char const*, char const*, int)'
   libmxnet.a(iter_image_recordio.cc.o): In function 
`mxnet::io::ImageRecordIOParser<unsigned 
char>::ParseNext(std::vector<mxnet::io::InstVector<unsigned char>, 
std::allocator<mxnet::io::InstVector<unsigned char> > >*) [clone ._omp_fn.20]':
   iter_image_recordio.cc:(.text+0x5928): undefined reference to 
`cv::error(int, std::string const&, char const*, char const*, int)'
   libmxnet.a(iter_image_recordio_2.cc.o): In function 
`mxnet::io::ImageRecordIOParser2<float>::ParseChunk(float*, float*, unsigned 
int, dmlc::InputSplit::Blob*)::{lambda()#1}::operator()() const':
   
iter_image_recordio_2.cc:(.text._ZZN5mxnet2io20ImageRecordIOParser2IfE10ParseChunkEPfS3_jPN4dmlc10InputSplit4BlobEENKUlvE_clEv[_ZZN5mxnet2io20ImageRecordIOParser2IfE10ParseChunkEPfS3_jPN4dmlc10InputSplit4BlobEENKUlvE_clEv]+0xc58):
 undefined reference to `cv::error(int, std::string const&, char const*, char 
const*, int)'
   
libmxnet.a(iter_image_recordio_2.cc.o):iter_image_recordio_2.cc:(.text._ZZN5mxnet2io20ImageRecordIOParser2IaE10ParseChunkEPaPfjPN4dmlc10InputSplit4BlobEENKUlvE_clEv[_ZZN5mxnet2io20ImageRecordIOParser2IaE10ParseChunkEPaPfjPN4dmlc10InputSplit4BlobEENKUlvE_clEv]+0xc58):
 more undefined references to `cv::error(int, std::string const&, char const*, 
char const*, int)' follow
   collect2: error: ld returned 1 exit status
   ninja: build stopped: subcommand failed.
   ```
   
   My main reason for wanting to use opencv 4 when building mxnet is that in my 
project where I use mxnet I am using opencv 4. When using the mxnet lib which 
is built with opencv 2, I get a ` Using GTK+ 2.x and GTK+ 3 in the same process 
is not supported` error as it looks like the opencv2 used by mxnet is using 
`gtk2` while opencv4 is using `gtk3`
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to