Tag Archives: Ubuntu 18.04

[Solved] Ubuntu 18.04 Compile opencv-3.4.16 Error: “c++: internal compiler error: Killed (program cc1plus)”

Ubuntu 18.04 compiles opencv-3.4.16 with the command “make – J” and encounters the error “C + +: internal compiler error: killed (program cc1plus)”. In the system, there are 8 CPUs and 32GB memory, and 83 cc1plus processes are found. Check the help information of make, “- j [n], — jobs [= n] allow n jobs at once; infinite jobs with no arg.”, If there are no parameters, an unlimited number of worker processes are used. The previous command “make – J” can be compiled successfully on a 128GB server.

According to the following commands provided by C + +: internal compiler error, increase the switching space to 8GB. The same problem still exists.

#The size of count is the size of the increased swap space, 1M is the block size, so the space size is bs*count=8192MB
sudo dd if=/dev/zero of=/swapfile bs=1M count=8192 
# format the space into swap format just now
sudo mkswap /swapfile 
chmod 0600 /swapfile  
#Use the swap space you just created
sudo swapon /swapfile

After increasing the size of swap space, the space of KIB swap listed by the top command increases.

~/proj/slam$ top
top - 11:25:12 up 23:59,  7 users,  load average: 24.55, 70.32, 66.93
Tasks: 495 total,  19 running, 400 sleeping,   0 stopped,   0 zombie
%Cpu(s): 95.5 us,  4.4 sy,  0.1 ni,  0.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem : 32760356 total, 28245364 free,  3986600 used,   528392 buff/cache
KiB Swap:  9392120 total,  8107088 free,  1285032 used. 28321152 avail Mem

Then use the command “make – J 16” to recompile and complete the task successfully.

Some information in case of error is as follows:

[ 96%] Building CXX object modules/imgproc/CMakeFiles/opencv_test_imgproc.dir/test/test_resize_bitexact.cpp.o
[ 97%] Building CXX object modules/imgproc/CMakeFiles/opencv_test_imgproc.dir/test/test_smooth_bitexact.cpp.o
[ 97%] Building CXX object modules/imgproc/CMakeFiles/opencv_test_imgproc.dir/test/test_templmatch.cpp.o
[ 97%] Building CXX object modules/imgproc/CMakeFiles/opencv_test_imgproc.dir/test/test_thresh.cpp.o
[ 97%] Building CXX object modules/imgproc/CMakeFiles/opencv_test_imgproc.dir/test/test_subdivision2d.cpp.o
[ 97%] Building CXX object modules/imgproc/CMakeFiles/opencv_test_imgproc.dir/test/test_watershed.cpp.o
c++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-7/README.Bugs> for instructions.
c++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-7/README.Bugs> for instructions.
modules/videoio/CMakeFiles/opencv_test_videoio.dir/build.make:110: recipe for target 'modules/videoio/CMakeFiles/opencv_test_videoio.dir/test/test_ffmpeg.cpp.o' failed
make[2]: *** [modules/videoio/CMakeFiles/opencv_test_videoio.dir/test/test_ffmpeg.cpp.o] Error 4
make[2]: *** Waiting for unfinished jobs....
c++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-7/README.Bugs> for instructions.
c++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-7/README.Bugs> for instructions.
modules/core/CMakeFiles/opencv_perf_core.dir/build.make:590: recipe for target 'modules/core/CMakeFiles/opencv_perf_core.dir/perf/perf_math.cpp.o' failed
make[2]: *** [modules/core/CMakeFiles/opencv_perf_core.dir/perf/perf_math.cpp.o] Error 4
make[2]: *** Waiting for unfinished jobs....
modules/videoio/CMakeFiles/opencv_test_videoio.dir/build.make:62: recipe for target 'modules/videoio/CMakeFiles/opencv_test_videoio.dir/test/test_camera.cpp.o' failed
make[2]: *** [modules/videoio/CMakeFiles/opencv_test_videoio.dir/test/test_camera.cpp.o] Error 4
c++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-7/README.Bugs> for instructions.
modules/calib3d/CMakeFiles/opencv_test_calib3d.dir/build.make:494: recipe for target 'modules/calib3d/CMakeFiles/opencv_test_calib3d.dir/test/test_fisheye.cpp.o' failed
make[2]: *** [modules/calib3d/CMakeFiles/opencv_test_calib3d.dir/test/test_fisheye.cpp.o] Error 4
make[2]: *** Waiting for unfinished jobs....
modules/objdetect/CMakeFiles/opencv_objdetect.dir/build.make:212: recipe for target 'modules/objdetect/CMakeFiles/opencv_objdetect.dir/src/qrcode.cpp.o' failed
make[2]: *** [modules/objdetect/CMakeFiles/opencv_objdetect.dir/src/qrcode.cpp.o] Error 4
c++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-7/README.Bugs> for instructions.
CMakeFiles/Makefile2:3434: recipe for target 'modules/objdetect/CMakeFiles/opencv_objdetect.dir/all' failed
make[1]: *** [modules/objdetect/CMakeFiles/opencv_objdetect.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
c++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-7/README.Bugs> for instructions.
c++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-7/README.Bugs> for instructions.
modules/core/CMakeFiles/opencv_perf_core.dir/build.make:110: recipe for target 'modules/core/CMakeFiles/opencv_perf_core.dir/perf/opencl/perf_bufferpool.cpp.o' failed
make[2]: *** [modules/core/CMakeFiles/opencv_perf_core.dir/perf/opencl/perf_bufferpool.cpp.o] Error 4
c++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-7/README.Bugs> for instructions.

[Solved] ubuntu 18.04 Fix Error: “libpng12.so.0: cannot open shared object file: No such file or directory”

Error “libpng12.so.0: cannot open shared object file: No such file or directory”
When running ORB_SLAM3, I encountered the error “libpng12.so.0: cannot open shared object file: No such file or directory”. Execute the command “sudo apt install libpng12-0” to install libpng12.so.0 and solve the problem.
The command log of the error:

/proj/hankf/slam/ORB_SLAM3$ ./Examples/Stereo/stereo_euroc ./Vocabulary/ORBvoc.txt ./Examples/Stereo/EuRoC.yaml /proj/hankf/hankf/slam/euroc-mav-dataset/MH_04_difficult ./Examples/Stereo/EuRoC_TimeStamps/MH04.txt dataset-MH04_stereo
./Examples/Stereo/stereo_euroc: error while loading shared libraries: libpng12.so.0: cannot open shared object file: No such file or directory

Installed command record

hankf@XSZGS4:/proj/hankf/hankf/slam/opencv-4.5$ sudo apt install libpng12-0
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  libpng12-0
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
Need to get 0 B/116 kB of archives.
After this operation, 285 kB of additional disk space will be used.
Selecting previously unselected package libpng12-0:amd64.
(Reading database ... 315713 files and directories currently installed.)
Preparing to unpack .../libpng12-0_1.2.54-1ubuntu1.1_amd64.deb ...
Unpacking libpng12-0:amd64 (1.2.54-1ubuntu1.1) ...
Setting up libpng12-0:amd64 (1.2.54-1ubuntu1.1) ...
Processing triggers for libc-bin (2.27-3ubuntu1.4) ...

Ubuntu 18.04: How to Install & Configure Opencv 4.2.0

This paper mainly introduces how to install and configure opencv from the source code in Ubuntu 18.04, and uses a simple example to verify whether the installation is successful

For specific installation and configuration steps, please refer to the following article: https://cv-tricks.com/installation/opencv-4-1-ubuntu18-04/

Different from the tutorial provided in the above link:

Some dependent package installations may need to be modified

In this paper, opencv version 4.2 is installed and configured to support CUDA to accelerate the calculation of DNN module

This article does not deal with Python interface configuration, only for C + +, so steps 2 ~ 5 will be skipped

Step 1: install opencv dependency package

Step by step, install all the following dependent packages:

sudo apt-get update -y # Update the list of packages
sudo apt-get remove -y x264 libx264-dev # Remove the older version of libx264-dev and x264
sudo apt-get install -y build-essential checkinstall cmake pkg-config yasm
sudo apt-get install -y git gfortran
sudo add-apt-repository -y "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt-get install -y libjpeg8-dev libjasper-dev libpng12-dev
sudo apt-get install -y libtiff5-dev
sudo apt-get install -y libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev
sudo apt-get install -y libxine2-dev libv4l-dev
sudo apt-get install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
sudo apt-get install -y qt5-default libgtk2.0-dev libtbb-dev
sudo apt-get install -y libatlas-base-dev
sudo apt-get install -y libfaac-dev libmp3lame-dev libtheora-dev
sudo apt-get install -y libvorbis-dev libxvidcore-dev
sudo apt-get install -y libopencore-amrnb-dev libopencore-amrwb-dev
sudo apt-get install -y x264 v4l-utils
 
# Some Optional Dependencies
sudo apt-get install -y libprotobuf-dev protobuf-compiler
sudo apt-get install -y libgoogle-glog-dev libgflags-dev
sudo apt-get install -y libgphoto2-dev libeigen3-dev libhdf5-dev doxygen

In the process of installing the above dependent package, there may be some errors in . Here I will list the problems I encountered and give the solutions error 1:

E: Unable to locate package libjasper-dev

Implementation:

sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt-get update

Just install the dependency package again

error 2:

E: Unable to locate package libgstreamer0.10-dev

Implementation:

sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev

Step 2: Install OpenCV 4.2.0 & OpenCV Contrib 4.2.0

OpenCV 4.2.0:
https://github.com/opencv/opencv/releases/tag/4.2.0

OpenCV Contib 4.2.0:
https://github.com/opencv/opencv_contrib/releases/tag/4.2.0

If you save the two compressed packages to /home/user name/opencv4.2/, unzip them

In addition, you need ippicv when compiling_ 2019_ lnx_ intel64_ general_ 20180723. Tgz this file is very slow to download. Here is a link to download and configure by referring to steps 1 and 2

For example, I put the downloaded file in the opencv4.2 folder and changed it to "/ home/username/opencv4.2/

Finally, the directory structure is as follows:

/home/username/opencv4.2/
	opencv-4.2.0/
	opencv_contrib-4.2.0/
	ippicv_2019_lnx_intel64_general_20180723.tgz

Step 3: building libraries with cmake

Implementation:

cd /home/username/opencv4.2/opencv-4.2.0
mkdir build
cd build

Implementation:

cmake -D CMAKE_BUILD_TYPE=RELEASE \
      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D INSTALL_C_EXAMPLES=ON \
      -D CUDA_ARCH_BIN='7.5'
      -D WITH_CUDA=ON
      -D WITH_TBB=ON \
      -D WITH_V4L=ON \
      -D WITH_QT=ON \
      -D WITH_OPENGL=ON \
      -D OPENCV_EXTRA_MODULES_PATH=/home/username/opencv4.2/opencv_contrib-4.2.0/modules \
      -D BUILD_EXAMPLES=ON \
      -D OPENCV_GENERATE_PKGCONFIG=YES ..

There are two aspects that need to be modified in the above steps

CUDA_ARCH_BIN='7.5'

Because opencv 4.2 supports CUDA to accelerate the calculation of DNN module, CUDA is configured here; Before that, you need to configure the driver and CUDA of NVIDIA graphics card

Among them, 7.5 refers to the computing power of the graphics card, my GTX 1660ti, and the corresponding computing power is 7.5

Here is a link for reference: nvida CUDA graphics card computing capacity table

The second place that needs to be modified is:

OPENCV_EXTRA_MODULES_PATH=/home/username/opencv4.2/opencv_contrib-4.2.0/modules

This is modified to your own OpenCV_ Location of contrib-4.2.0/modules

Step 4: building libraries with make

To view the number of CPU cores:

nproc

For example, my CPU core number is 12, and the execution time is 12

cd /home/username/opencv4.2/build
make -j12

Wait for a while, and then configuration done appears

Implementation:

sudo make install

After waiting for a while again, execute:

sudo sh -c 'echo "/usr/local/lib" >> /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig

Step 5: modify opencv4. PC file

If the above configuration is successful, a pkgconfig folder will appear in the /usr/local/lib/ folder, in which there is a OpenCV. PC file. The contents are as follows:

# Package Information for pkg-config

prefix=/usr/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir_old=${prefix}/include/opencv4/opencv2
includedir_new=${prefix}/include/opencv4

Name: OpenCV
Description: Open Source Computer Vision Library
Version: 4.2.0
Libs: -L${exec_prefix}/lib -lopencv_gapi -lopencv_stitching -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_cudabgsegm -lopencv_cudafeatures2d -lopencv_cudaobjdetect -lopencv_cudastereo -lopencv_cvv -lopencv_dnn_objdetect -lopencv_dnn_superres -lopencv_dpm -lopencv_highgui -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hdf -lopencv_hfs -lopencv_img_hash -lopencv_line_descriptor -lopencv_quality -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_sfm -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_superres -lopencv_cudacodec -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_dnn -lopencv_plot -lopencv_videostab -lopencv_cudaoptflow -lopencv_optflow -lopencv_cudalegacy -lopencv_videoio -lopencv_cudawarping -lopencv_xfeatures2d -lopencv_shape -lopencv_ml -lopencv_ximgproc -lopencv_video -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_imgcodecs -lopencv_features2d -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_cudaimgproc -lopencv_cudafilters -lopencv_imgproc -lopencv_cudaarithm -lopencv_core -lopencv_cudev
Libs.private: -lm -lpthread -L/usr/lib/x86_64-linux-gnu -lGL -lGLU -lcudart_static -ldl -lrt -lnppc -lnppial -lnppicc -lnppicom -lnppidei -lnppif -lnppig -lnppim -lnppist -lnppisu -lnppitc -lnpps -lcublas -lcudnn -lcufft -L-L/usr/local/cuda -llib64 -L-L/usr/lib -lx86_64-linux-gnu
Cflags: -I${includedir_old} -I${includedir_new}

note: the sixth line needs to be modified to:

includedir_old=${prefix}/include/opencv4/opencv2

If it is not generated automatically, you can try to create a new file, copy the above content into it, and continue to the next step

Step 6: add PKG to . Bashrc file_ CONFIG_ PATH

Implementation:

sudo gedit ~/.bashrc

Add at the end of the file:

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH

After exiting, execute

source ~/.bashrc

# Determine when the path is added successfully and return :/usr/local/lib/pkgconfig
echo $PKG_CONFIG_PATH

Step 7: verification with C + + code

Create a test. CPP file in any directory and add the following content:

#include "opencv.hpp"
 
using namespace cv;
using namespace std;
 
int main( int argc, char** argv )
{
  cout << "OpenCV version : " << CV_VERSION << endl;
  cout << "Major version : " << CV_MAJOR_VERSION << endl;
  cout << "Minor version : " << CV_MINOR_VERSION << endl;
  cout << "Subminor version : " << CV_SUBMINOR_VERSION << endl;
}

Use the command line to execute under its folder:

# Compile the test.cpp program and generate the executable file
g++ -std=c++11 test.cpp `pkg-config --libs --cflags opencv4` -o result

# Execute executable files
./result

The output of the following indicates that the configuration is successful

OpenCV version : 4.2.0
Major version : 4
Minor version : 2
Subminor version : 0