0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Note Book : OpenCV v4.5.0-dev On Ubuntu 20.04 But Didn't work cmake build for Java

Last updated at Posted at 2020-11-02

####Conclusion

  1. It's not OpenCV's fault, It's Ubuntu fault.
  2. If OpenCV with cuda, It's needed gcc and g++ version 8 under.

I found it. But I can't found for Apache Ant.
https://bugs.launchpad.net/ubuntu/+source/python3-defaults/+bug/1876957
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1633839

I put it.
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1902570

####Reason

  1. Because the Apache Ant symbolic is broken, link installed by apt-get.
  2. It' working. I use export CC and CXX.
    ・export CC=gcc-8
    ・export CXX=g++-8

####Contents
I wanna set up something like this against OpenCV 4.5.0-dev, but I can't build it on ubuntu 20.04 LTS. Because the symbolic link in Ant is broken.
I'm using the apt-get command to get Apache Ant. But the /bin/ant command does not work. It's a throw ClassNotFoundException.

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.1 LTS"

It's not work, '/bin/ant'.
image.png

The symbolic link is a ...?? What's this?
/usr/bin/ant -> ../share/ant/bin/ant
/bin/ant -> ../share/ant/bin/ant

image.png
This '/bin/ant -> ../share/ant/bin/ant' is a '/bin/share/ant/bin/ant'. It's nothing the Path.

I delete /bin/ant, And create new symbolic link. But I think upside down, /bin/share/ant/bin/ant is true. Because /bin/share has a higher priority more than /usr/bin/share.

sudo rm -fr /bin/ant
sudo ln -s /usr/share/ant/bin/ant /bin/ant

####What I want to do.

I wanna doing samething liks like this configuration.

build
-- General configuration for OpenCV 4.5.0-dev =====================================
--   Version control:               4.5.0-76-g691c3d1e3c
--
--   Extra modules:
--     Location (extra):            /usr/local/src/opencv_contrib/modules
--     Version control (extra):     4.5.0-13-gb65b3cc3
--
--   Platform:
--     Timestamp:                   2020-11-01T15:56:15Z
--     Host:                        Linux 5.4.0-52-generic x86_64
--     CMake:                       3.16.3
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               RELEASE
--
--   CPU/HW features:
--     Baseline:                    SSE SSE2 SSE3
--       requested:                 SSE3
--     Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
--       requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
--       SSE4_1 (17 files):         + SSSE3 SSE4_1
--       SSE4_2 (2 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
--       FP16 (1 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
--       AVX (5 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
--       AVX2 (31 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
--       AVX512_SKX (7 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX
--
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ standard:                11
--     C++ Compiler:                /usr/bin/g++-8  (ver 8.4.0)
--     C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /usr/bin/gcc-8
--     C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):      -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a   -Wl,--gc-sections -Wl,--as-needed
--     Linker flags (Debug):        -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a   -Wl,--gc-sections -Wl,--as-needed
--     ccache:                      NO
--     Precompiled headers:         NO
--     Extra dependencies:          m pthread cudart_static -lpthread dl rt nppc nppial nppicc nppicom nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cudnn cufft -L/usr/lib/x86_64-linux-gnu
--     3rdparty dependencies:
--
--   OpenCV modules:
--     To be built:                 alphamat aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hdf hfs highgui img_hash imgcodecs imgproc intensity_transform java line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab viz xfeatures2d ximgproc xobjdetect xphoto
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 cnn_3dobj cvv js julia matlab ovis python2 sfm
--     Applications:                tests perf_tests apps
--     Documentation:               NO
--     Non-free algorithms:         NO
--
--   GUI:
--     GTK+:                        YES (ver 3.24.20)
--       GThread :                  YES (ver 2.64.3)
--       GtkGlExt:                  NO
--     VTK support:                 YES (ver 7.1.1)
--
--   Media I/O:
--     ZLib:                        /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.11)
--     JPEG:                        /usr/lib/x86_64-linux-gnu/libjpeg.so (ver 80)
--     WEBP:                        /usr/lib/x86_64-linux-gnu/libwebp.so (ver encoder: 0x020e)
--     PNG:                         /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.37)
--     TIFF:                        /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 / 4.1.0)
--     JPEG 2000:                   OpenJPEG (ver 2.3.1)
--     OpenEXR:                     /usr/lib/x86_64-linux-gnu/libImath.so /usr/lib/x86_64-linux-gnu/libIlmImf.so /usr/lib/x86_64-linux-gnu/libIex.so /usr/lib/x86_64-linux-gnu/libHalf.so /usr/lib/x86_64-linux-gnu/libIlmThread.so (ver 2_3)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
--
--   Video I/O:
--     DC1394:                      NO
--     FFMPEG:                      YES
--       avcodec:                   YES (58.54.100)
--       avformat:                  YES (58.29.100)
--       avutil:                    YES (56.31.100)
--       swscale:                   YES (5.5.100)
--       avresample:                YES (4.0.0)
--     GStreamer:                   NO
--     v4l/v4l2:                    YES (linux/videodev2.h)
--
--   Parallel framework:            pthreads
--
--   Trace:                         YES (with Intel ITT)
--
--   Other third-party libraries:
--     Intel IPP:                   2020.0.0 Gold [2020.0.0]
--            at:                   /usr/local/src/opencv/build/3rdparty/ippicv/ippicv_lnx/icv
--     Intel IPP IW:                sources (2020.0.0)
--               at:                /usr/local/src/opencv/build/3rdparty/ippicv/ippicv_lnx/iw
--     Lapack:                      YES (/usr/lib/x86_64-linux-gnu/liblapack.so /usr/lib/x86_64-linux-gnu/libcblas.so /usr/lib/x86_64-linux-gnu/libatlas.so)
--     Eigen:                       YES (ver 3.3.7)
--     Custom HAL:                  NO
--     Protobuf:                    build (3.5.1)
--
--   NVIDIA CUDA:                   YES (ver 10.1, CUFFT CUBLAS FAST_MATH)
--     NVIDIA GPU arch:             30 35 37 50 52 60 61 70 75
--     NVIDIA PTX archs:
--
--   cuDNN:                         YES (ver 7.6.5)
--
--   OpenCL:                        YES (no extra features)
--     Include path:                /usr/local/src/opencv/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
--
--   Python 3:
--     Interpreter:                 /usr/bin/python3 (ver 3.8.5)
--     Libraries:                   /usr/lib/x86_64-linux-gnu/libpython3.8.so (ver 3.8.5)
--     numpy:                       /usr/lib/python3/dist-packages/numpy/core/include (ver 1.17.4)
--     install path:                lib/python3.8/dist-packages/cv2/python-3.8
--
--   Python (for build):            python3
--
--   Java:
--     ant:                         /bin/ant (ver 1.10.7)
--     JNI:                         /usr/lib/jvm/java-14-openjdk-amd64/include /usr/lib/jvm/java-14-openjdk-amd64/include/linux /usr/lib/jvm/java-14-openjdk-amd64/include
--     Java wrappers:               YES
--     Java tests:                  YES
--
--   Install to:                    /usr/local/lib/opencv
-- -----------------------------------------------------------------
--
-- Configuring done
-- Generating done
-- Build files have been written to: /usr/local/src/opencv/build

####It's finaly it.

I install this library.

install
#/usr/bin/sh

sudo apt update
sudo apt -yV upgrade

sudo apt-get -yV install build-essential
Sudo apt-get -yV install gcc-8.0 g++-8.0
sudo apt-get -yV install cmake

sudo apt-get -yV install libeigen3-dev

sudo apt-get -yV install libgtk-3-dev
sudo apt-get -yV install qt5-default
sudo apt-get -yV install libvtk7-qt-dev
sudo apt-get -yV install freeglut3-dev

sudo apt-get -yV install libtbb-dev

sudo apt-get -yV install libjpeg-dev
sudo apt-get -yV install libopenjp2-7-dev
sudo apt-get -yV install libpng++-dev
sudo apt-get -yV install libtiff-dev
sudo apt-get -yV install libopenexr-dev
sudo apt-get -yV install libwebp-dev

sudo apt-get -yV install libavresample-dev

sudo apt-get -yV install libhdf5-dev

sudo apt-get -yV install libpython3-dev
sudo apt-get -yV install python3-numpy python3-scipy python3-matplotlib

sudo apt-get -yV install libatlas-base-dev
sudo apt-get -yV install liblapacke-dev

sudo apt-get -yV install ubuntu-drivers-common
sudo ubuntu-drivers autoinstall

# dpkg -l | grep cuda
# sudo apt-get --purge remove cuda*
# sudo apt-get autoremove

sudo apt-get -yV install linux-headers-$(uname -r)

sudo apt-get -yV install wget
sudo apt-get -yV install nvidia-cuda-dev nvidia-cuda-toolkit nvidia-cuda-toolkit-gcc

sudo apt-get -yV install openjdk-14-jdk

cat /usr/lib/cuda/version.txt

cd /tmp

echo "deb https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64 /" | sudo tee /etc/apt/sources.list.d/nvidia-ml.list

sudo apt update

sudo apt-get -yV install libcudnn7-dev
sudo apt-get -yV install cuda
sudo apt-get -yV install cuda-drivers

sudo apt-get -yV install openjdk-14-jdk
sudo apt-get -yV install ant
sudo rm -rf /bin/ant
sudo ln -s /usr/share/ant/bin/ant /bin/ant

It's build by cmake.


#/usr/bin/sh

export LIB_NAME=opencv
export VERSION=4.5.0-dev
export SRC_DIR=/usr/local/src
export USR_LIB=/usr/local/lib
export INSTALL_PREFIX=${USR_LIB}
export GNU_INCLUDE_DIR=/usr/include/x86_64-linux-gnu
export GNU_LIB_DIR=/usr/lib/x86_64-linux-gnu
export CC=gcc-8
export CXX=g++-8
#export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
#export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
#export JAVA_HOME=/usr/lib/jvm/java-14-openjdk-amd64
#export ANT_HOME=/usr/share/ant
#export ANT_HOME=/usr/local/lib/ant
#export PATH=.:${JAVA_HOME}/bin:${ANT_HOME}/bin:${PATH}
#export PATH=.:${JAVA_HOME}/bin:${PATH}
#export OPENCV_JAVA_SOURCE_VERSION=14
#export OPENCV_JAVA_TARGET_VERSION=14

echo `java -version`
echo `ant -version`

cd ${SRC_DIR}
sudo git clone https://github.com/opencv/opencv.git
sudo chown -R ${USER} ${SRC_DIR}/${LIB_NAME}

sudo git clone https://github.com/opencv/opencv_contrib.git
sudo chown -R ${USER} ${SRC_DIR}/opencv_contrib

cd ${SRC_DIR}/opencv

# sudo rm -rf ${SRC_DIR}/${LIB_NAME}/build
sudo rm -rf ${SRC_DIR}/${LIB_NAME}/build/CMakeCache.txt
sudo mkdir ${SRC_DIR}/${LIB_NAME}/build
sudo chown -R ${USER} ${SRC_DIR}/${LIB_NAME}/build
cd ${SRC_DIR}/${LIB_NAME}/build

cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=${INSTALL_PREFIX}/${LIB_NAME}-${VERSION} \
-D WITH_CUDA=ON \
-D CUDA_FAST_MATH=ON \
-D WITH_CUBLAS=ON \
-D WITH_CUDNN=ON \
-D WITH_NVCUVID=ON \
-D OPENCV_DNN_CUDA=ON \
-D BUILD_opencv_cudaimgproc=ON \
-D INSTALL_C_EXAMPLES=ON \
-D WITH_PYTHON=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_opencv_python2=OFF \
-D BUILD_opencv_python3=ON \
-D PYTHON_DEFAULT_EXECUTABLE=python3 \
-D EIGEN_INCLUDE_PATH=/usr/include/eigen3/Eigen/ \
-D OPENCV_EXTRA_MODULES_PATH=${SRC_DIR}/opencv_contrib/modules \
-D OPENCV_DNN_CUDA=ON \
-D BUILD_CUDA_STUBS=OFF \
-D WITH_MKL=ON \
-D BUILD_opencv_python2=OFF \
-D BUILD_opencv_python3=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D WITH_LAPACK=ON \
..

sudo cmake --build ${SRC_DIR}/${LIB_NAME}/build --config release -j 12
sudo cmake --build ${SRC_DIR}/${LIB_NAME}/build --target install
sudo rm -rf /usr/local/lib/opencv
sudo ln -s /usr/local/lib/opencv-4.5.0-dev /usr/local/lib/opencv
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?