Using Ubuntu 15.10 on x86_64 with libopencv-dev installed (Version: 2.4.9+dfsg-1ubuntu6) the following linker error results when compiling mxnet with OpenCV support. I copy make/config.mk to the main directory, enable OpenCV and compile with make, producing the output:
g++-4.9 -DMSHADOW_FORCE_STREAM -Wall -O3 -I./mshadow/ -I./dmlc-core/include -fPIC -Iinclude -msse3 -funroll-loops -Wno-unused-parameter -Wno-unknown-pragmas -I/usr/local/cuda/include -DMSHADOW_USE_CBLAS=1 -DMSHADOW_USE_MKL=0 -DMSHADOW_RABIT_PS=0 -DMSHADOW_DIST_PS=0 -DMXNET_USE_OPENCV=1 `pkg-config --cflags opencv` -fopenmp -march=native -o bin/im2rec tools/im2rec.cc build/resource.o build/io/io.o build/io/iter_image_recordio.o build/io/iter_mnist.o build/common/tblob_op_registry.o build/common/mxrtc.o build/ndarray/unary_function.o build/ndarray/ndarray_function.o build/ndarray/ndarray.o build/operator/block_grad.o build/operator/leaky_relu.o build/operator/embedding.o build/operator/pooling.o build/operator/deconvolution.o build/operator/swapaxis.o build/operator/batch_norm.o build/operator/softmax_output.o build/operator/elementwise_sum.o build/operator/convolution.o build/operator/native_op.o build/operator/regression_output.o build/operator/slice_channel.o build/operator/concat.o build/operator/activation.o build/operator/elementwise_binary_op.o build/operator/ndarray_op.o build/operator/operator.o build/operator/lrn.o build/operator/dropout.o build/operator/cross_device_copy.o build/operator/elementwise_binary_scalar_op.o build/operator/fully_connected.o build/operator/reshape.o build/symbol/graph_executor.o build/symbol/static_graph.o build/symbol/symbol.o build/engine/naive_engine.o build/engine/threaded_engine_pooled.o build/engine/threaded_engine.o build/engine/engine.o build/engine/threaded_engine_perdevice.o build/storage/storage.o build/c_api/c_predict_api.o build/c_api/c_api.o build/c_api/c_api_error.o build/kvstore/kvstore.o dmlc-core/libdmlc.a build/ndarray/unary_function_gpu.o build/ndarray/ndarray_function_gpu.o build/operator/elementwise_binary_op_gpu.o build/operator/batch_norm_gpu.o build/operator/dropout_gpu.o build/operator/elementwise_binary_scalar_op_gpu.o build/operator/lrn_gpu.o build/operator/slice_channel_gpu.o build/operator/fully_connected_gpu.o build/operator/reshape_gpu.o build/operator/pooling_gpu.o build/operator/block_grad_gpu.o build/operator/leaky_relu_gpu.o build/operator/embedding_gpu.o build/operator/elementwise_sum_gpu.o build/operator/deconvolution_gpu.o build/operator/swapaxis_gpu.o build/operator/activation_gpu.o build/operator/softmax_output_gpu.o build/operator/concat_gpu.o build/operator/native_op_gpu.o build/operator/regression_output_gpu.o build/operator/convolution_gpu.o -pthread -lm -lcudart -lcublas -lcurand -L/usr/local/cuda/lib64 -L/usr/local/cuda/lib -lblas -lrt `pkg-config --libs opencv` -lnvrtc -lcuda
/tmp/ccoTXSwt.o: In function `main':
im2rec.cc:(.text.startup+0x1c60): 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&)'
collect2: error: ld returned 1 exit status
Makefile:137: recipe for target 'bin/im2rec' failed
make: *** [bin/im2rec] Error 1
Could you run pkg-config --libs opencv and post your output?
sn@hutu:~$ pkg-config --libs opencv
/usr/lib/x86_64-linux-gnu/libopencv_calib3d.so -lopencv_calib3d /usr/lib/x86_64-linux-gnu/libopencv_contrib.so -lopencv_contrib /usr/lib/x86_64-linux-gnu/libopencv_core.so -lopencv_core /usr/lib/x86_64-linux-gnu/libopencv_features2d.so -lopencv_features2d /usr/lib/x86_64-linux-gnu/libopencv_flann.so -lopencv_flann /usr/lib/x86_64-linux-gnu/libopencv_gpu.so -lopencv_gpu /usr/lib/x86_64-linux-gnu/libopencv_highgui.so -lopencv_highgui /usr/lib/x86_64-linux-gnu/libopencv_imgproc.so -lopencv_imgproc /usr/lib/x86_64-linux-gnu/libopencv_legacy.so -lopencv_legacy /usr/lib/x86_64-linux-gnu/libopencv_ml.so -lopencv_ml /usr/lib/x86_64-linux-gnu/libopencv_objdetect.so -lopencv_objdetect /usr/lib/x86_64-linux-gnu/libopencv_ocl.so -lopencv_ocl /usr/lib/x86_64-linux-gnu/libopencv_photo.so -lopencv_photo /usr/lib/x86_64-linux-gnu/libopencv_stitching.so -lopencv_stitching /usr/lib/x86_64-linux-gnu/libopencv_superres.so -lopencv_superres /usr/lib/x86_64-linux-gnu/libopencv_ts.so -lopencv_ts /usr/lib/x86_64-linux-gnu/libopencv_video.so -lopencv_video /usr/lib/x86_64-linux-gnu/libopencv_videostab.so -lopencv_videostab
And also
sn@hutu:~$ apt-cache show libopencv-dev
Package: libopencv-dev
Priority: optional
Section: universe/libdevel
Installed-Size: 653
Maintainer: Kubuntu Developers <[email protected]>
Original-Maintainer: Debian Science Team <[email protected]>
Architecture: amd64
Source: opencv
Version: 2.4.9+dfsg-1ubuntu6
Depends: libc6 (>= 2.14), libgcc1 (>= 1:4.1.1), libopencv-calib3d2.4v5, libopencv-core2.4v5, libopencv-highgui2.4v5, libopencv-imgproc2.4v5, libopencv-ml2.4v5, libopencv-objdetect2.4v5, libstdc++6 (>= 5.2), libopencv-core-dev (= 2.4.9+dfsg-1ubuntu6), libopencv-ml-dev (= 2.4.9+dfsg-1ubuntu6), libopencv-imgproc-dev (= 2.4.9+dfsg-1ubuntu6), libopencv-video-dev (= 2.4.9+dfsg-1ubuntu6), libopencv-objdetect-dev (= 2.4.9+dfsg-1ubuntu6), libopencv-highgui-dev (= 2.4.9+dfsg-1ubuntu6), libopencv-calib3d-dev (= 2.4.9+dfsg-1ubuntu6), libopencv-flann-dev (= 2.4.9+dfsg-1ubuntu6), libopencv-features2d-dev (= 2.4.9+dfsg-1ubuntu6), libopencv-legacy-dev (= 2.4.9+dfsg-1ubuntu6), libopencv-contrib-dev (= 2.4.9+dfsg-1ubuntu6), libopencv-ts-dev (= 2.4.9+dfsg-1ubuntu6), libopencv-photo-dev (= 2.4.9+dfsg-1ubuntu6), libopencv-videostab-dev (= 2.4.9+dfsg-1ubuntu6), libopencv-stitching-dev (= 2.4.9+dfsg-1ubuntu6), libopencv-gpu-dev (= 2.4.9+dfsg-1ubuntu6), libopencv-superres-dev (= 2.4.9+dfsg-1ubuntu6), libopencv-ocl-dev (= 2.4.9+dfsg-1ubuntu6), libopencv2.4-java (= 2.4.9+dfsg-1ubuntu6), libopencv2.4-jni (= 2.4.9+dfsg-1ubuntu6), libcv-dev (= 2.4.9+dfsg-1ubuntu6), libhighgui-dev (= 2.4.9+dfsg-1ubuntu6), libcvaux-dev (= 2.4.9+dfsg-1ubuntu6), pkg-config
Recommends: opencv-data
Breaks: libopencv-core-dev (<= 2.3.1-8)
Filename: pool/universe/o/opencv/libopencv-dev_2.4.9+dfsg-1ubuntu6_amd64.deb
Size: 167428
MD5sum: ecaf4191cf03536bff3e19cc1ddc424c
SHA1: d719e328151d771af7eaef054ee7edbbf803681d
SHA256: 0c7ec4a327a5c124ddcb6d5247a3e0a7421679a422aa005353830d59444d818e
Description-en: development files for opencv
This is a metapackage providing development package necessary for
development of OpenCV (Open Computer Vision).
.
The Open Computer Vision Library is a collection of algorithms and sample
code for various computer vision problems. The library is compatible with
IPL (Intel's Image Processing Library) and, if available, can use IPP
(Intel's Integrated Performance Primitives) for better performance.
.
OpenCV provides low level portable data types and operators, and a set
of high level functionalities for video acquisition, image processing and
analysis, structural analysis, motion analysis and object tracking, object
recognition, camera calibration and 3D reconstruction.
Description-md5: f9dc67381f1013c39fe59842c79cbddf
Homepage: http://opencv.org/
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu
I don't really know what happened, but maybe you can try adding the output of pkg-config --libs opencv to LDFLAGS in config.mk
closing due to inactive state, please feel free to reopen
Also have problems when compiling with opencv on 15.10:
/tmp/ccU9s2mB.o: In function
main': im2rec.cc:(.text.startup+0x1c37): undefined reference tocv::imencode(std::string const&, cv::_InputArray const&, std::vector>&, std::vector > const&)'
build/c_api/c_api.o: In functionMXRecordIOReaderReadRecord': c_api.cc:(.text+0x23da): undefined reference todmlc::RecordIOReader::NextRecord(std::string_)'
collect2: error: ld returned 1 exit status
Makefile:137: recipe for target 'bin/im2rec' failed
make: *_* [bin/im2rec] Error 1
without opencv compiles fine
fixed the same problem using clang instead of gcc
FYI, I ran into this issue and fixed it by recompiling OpenCV from source in C++0x.
@Aelphy I also fixed the same problem using clang instead of gcc...
Most helpful comment
fixed the same problem using clang instead of gcc