Error building OpenCV because of LAPACK

Hey, I am trying to buiild OpenCV from source to use CUDA.

That’s my build script:

#!/bin/bash
# License: MIT. See license file in root directory
# Copyright(c) JetsonHacks (2017-2019)

OPENCV_VERSION=3.4.1
# Jetson Nano
ARCH_BIN=7.2
INSTALL_DIR=/usr/local
# Download the opencv_extras repository
# If you are installing the opencv testdata, ie
#  OPENCV_TEST_DATA_PATH=../opencv_extra/testdata
# Make sure that you set this to YES
# Value should be YES or NO
DOWNLOAD_OPENCV_EXTRAS=NO
# Source code directory
OPENCV_SOURCE_DIR=$HOME
WHEREAMI=$PWD
# NUM_JOBS is the number of jobs to run simultaneously when using make
# This will default to the number of CPU cores (on the Nano, that's 4)
# If you are using a SD card, you may want to change this
# to 1. Also, you may want to increase the size of your swap file
NUM_JOBS=$(nproc)

CLEANUP=true

PACKAGE_OPENCV="-D CPACK_BINARY_DEB=ON"

function usage
{
    echo "usage: ./buildOpenCV.sh [[-s sourcedir ] | [-h]]"
    echo "-s | --sourcedir   Directory in which to place the opencv sources (default $HOME)"
    echo "-i | --installdir  Directory in which to install opencv libraries (default /usr/local)"
    echo "--no_package       Do not package OpenCV as .deb file (default is true)"
    echo "-h | --help  This message"
}

# Iterate through command line inputs
while [ "$1" != "" ]; do
    case $1 in
        -s | --sourcedir )      shift
				OPENCV_SOURCE_DIR=$1
                                ;;
        -i | --installdir )     shift
                                INSTALL_DIR=$1
                                ;;
        --no_package )          PACKAGE_OPENCV=""
                                ;;
        -h | --help )           usage
                                exit
                                ;;
        * )                     usage
                                exit 1
    esac
    shift
done

CMAKE_INSTALL_PREFIX=$INSTALL_DIR

# Print out the current configuration
echo "Build configuration: "
echo " NVIDIA Jetson Nano"
echo " OpenCV binaries will be installed in: $CMAKE_INSTALL_PREFIX"
echo " OpenCV Source will be installed in: $OPENCV_SOURCE_DIR"
if [ "$PACKAGE_OPENCV" = "" ] ; then
   echo " NOT Packaging OpenCV"
else
   echo " Packaging OpenCV"
fi

if [ $DOWNLOAD_OPENCV_EXTRAS == "YES" ] ; then
 echo "Also downloading opencv_extras"
fi

# Repository setup
sudo apt-add-repository universe
sudo apt-get update

# Download dependencies for the desired configuration
cd $WHEREAMI
sudo apt-get install -y \
    build-essential \
    cmake \
    libavcodec-dev \
    libavformat-dev \
    libavutil-dev \
    libeigen3-dev \
    libglew-dev \
    libgtk2.0-dev \
    libgtk-3-dev \
    libjpeg-dev \
    libpng-dev \
    libpostproc-dev \
    libswscale-dev \
    libtbb-dev \
    libtiff5-dev \
    libv4l-dev \
    libxvidcore-dev \
    libx264-dev \
    qt5-default \
    zlib1g-dev \
    pkg-config

# We will be supporting OpenGL, we need a little magic to help
# https://devtalk.nvidia.com/default/topic/1007290/jetson-tx2/building-opencv-with-opengl-support-/post/5141945/#5141945
cd /usr/local/cuda/include
sudo patch -N cuda_gl_interop.h $WHEREAMI'/patches/OpenGLHeader.patch' 

# Python 2.7
sudo apt-get install -y python-dev  python-numpy  python-py  python-pytest
# Python 3.6
sudo apt-get install -y python3-dev python3-numpy python3-py python3-pytest

# GStreamer support
sudo apt-get install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev 

cd $OPENCV_SOURCE_DIR
git clone --branch "$OPENCV_VERSION" https://github.com/opencv/opencv.git
git clone --branch "$OPENCV_VERSION" https://github.com/opencv/opencv_contrib.git

if [ $DOWNLOAD_OPENCV_EXTRAS == "YES" ] ; then
 echo "Installing opencv_extras"
 # This is for the test data
 cd $OPENCV_SOURCE_DIR
 git clone https://github.com/opencv/opencv_extra.git
 cd opencv_extra
 git checkout -b v${OPENCV_VERSION} ${OPENCV_VERSION}
fi

# Patch the Eigen library issue ...
cd $OPENCV_SOURCE_DIR/opencv
sed -i 's/include <Eigen\/Core>/include <eigen3\/Eigen\/Core>/g' modules/core/include/opencv2/core/private.hpp

# Create the build directory and start cmake
cd $OPENCV_SOURCE_DIR/opencv
mkdir build
cd build

# Here are some options to install source examples and tests
#     -D INSTALL_TESTS=ON \
#     -D OPENCV_TEST_DATA_PATH=../opencv_extra/testdata \
#     -D INSTALL_C_EXAMPLES=ON \
#     -D INSTALL_PYTHON_EXAMPLES=ON \

# If you are compiling the opencv_contrib modules:
# curl -L https://github.com/opencv/opencv_contrib/archive/3.4.1.zip -o opencv_contrib-3.4.1.zip

# There are also switches which tell CMAKE to build the samples and tests
# Check OpenCV documentation for details
#       -D WITH_QT=ON \

echo $PWD
time cmake -D CMAKE_BUILD_TYPE=RELEASE \
      -D CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} \
      -D WITH_CUDA=ON \
      -D CUDA_ARCH_BIN=${ARCH_BIN} \
      -D CUDA_ARCH_PTX="" \
      -D WITH_CUDNN=ON \
      -D CUDNN_VERSION='8.0' \
      -D OPENCV_GENERATE_PKGCONFIG=ON \
      -D ENABLE_FAST_MATH=ON \
      -D CUDA_FAST_MATH=ON \
      -D WITH_CUBLAS=ON \
      -D WITH_LIBV4L=ON \
      -D WITH_V4L=ON \
      -D WITH_GSTREAMER=ON \
      -D WITH_GSTREAMER_0_10=OFF \
      -D WITH_OPENGL=ON \
      -D BUILD_opencv_python2=ON \
      -D BUILD_opencv_python3=ON \
      -D WITH_QT=ON \
      -D BUILD_TESTS=OFF \
      -D BUILD_PERF_TESTS=OFF \
      -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
      -D ENABLE_PRECOMPILED_HEADERS=OFF \
      $"PACKAGE_OPENCV" \
      ../


if [ $? -eq 0 ] ; then
  echo "CMake configuration make successful"
else
  # Try to make again
  echo "CMake issues " >&2
  echo "Please check the configuration being used"
  exit 1
fi

# Consider the MAXN performance mode if using a barrel jack on the Nano
time make -j$NUM_JOBS
if [ $? -eq 0 ] ; then
  echo "OpenCV make successful"
else
  # Try to make again; Sometimes there are issues with the build
  # because of lack of resources or concurrency issues
  echo "Make did not build " >&2
  echo "Retrying ... "
  # Single thread this time
  make
  if [ $? -eq 0 ] ; then
    echo "OpenCV make successful"
  else
    # Try to make again
    echo "Make did not successfully build" >&2
    echo "Please fix issues and retry build"
    exit 1
  fi
fi

echo "Installing ... "
sudo make install
sudo ldconfig
if [ $? -eq 0 ] ; then
   echo "OpenCV installed in: $CMAKE_INSTALL_PREFIX"
else
   echo "There was an issue with the final installation"
   exit 1
fi

# If PACKAGE_OPENCV is on, pack 'er up and get ready to go!
# We should still be in the build directory ...
if [ "$PACKAGE_OPENCV" != "" ] ; then
   echo "Starting Packaging"
   sudo ldconfig  
   time sudo make package -j$NUM_JOBS
   if [ $? -eq 0 ] ; then
     echo "OpenCV make package successful"
   else
     # Try to make again; Sometimes there are issues with the build
     # because of lack of resources or concurrency issues
     echo "Make package did not build " >&2
     echo "Retrying ... "
     # Single thread this time
     sudo make package
     if [ $? -eq 0 ] ; then
       echo "OpenCV make package successful"
     else
       # Try to make again
       echo "Make package did not successfully build" >&2
       echo "Please fix issues and retry build"
       exit 1
     fi
   fi
fi


# check installation
IMPORT_CHECK="$(python -c "import cv2 ; print cv2.__version__")"
if [[ $IMPORT_CHECK != *$OPENCV_VERSION* ]]; then
  echo "There was an error loading OpenCV in the Python sanity test."
  echo "The loaded version does not match the version built here."
  echo "Please check the installation."
  echo "The first check should be the PYTHONPATH environment variable."
fi

Some of the CMake output:


 WARNING: Can't build ffmpeg test code
-- CUDA detected: 10.2
-- CUDA NVCC target flags: -gencode;arch=compute_72,code=sm_72;-D_FORCE_INLINES
-- Could not find OpenBLAS include. Turning OpenBLAS_FOUND off
-- Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off
-- Could NOT find Atlas (missing: Atlas_CLAPACK_INCLUDE_DIR) 
-- A library with BLAS API found.
-- A library with LAPACK API found.

The error I get:

                 from /home/nvidia/opencv/modules/core/src/matrix_c.cpp:3:
/usr/local/cuda/include/npp.h:62:0: note: this is the location of the previous definition
 #define NPP_VERSION (NPP_VER_MAJOR * 1000 +     \
 
c++: internal compiler error: Segmentation fault (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_core.dir/build.make:1131: recipe for target 'modules/core/CMakeFiles/opencv_core.dir/src/lapack.cpp.o' failed
make[2]: *** [modules/core/CMakeFiles/opencv_core.dir/src/lapack.cpp.o] Error 4
make[2]: *** Waiting for unfinished jobs....
CMakeFiles/Makefile2:2462: recipe for target 'modules/core/CMakeFiles/opencv_core.dir/all' failed
make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2

I used to be able to compile it wit that bash script but I think I may have deleted some libraries when trying to install another repositories and now it’s not working. I tried to install lapack and openblas using sudo apt get, It didn’t help.

How can I to fix that?

Hi,

Could you share why you need OpenCV 3.4?
The version is quite old so it might have some compatibility issues.

Could you try OpenCV 4 instead?
Thanks.

I tried now again with OpenCV 4.1.1 and even newer.

I am getting the errors:

.size(),
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/eigen3/Eigen/src/Core/GeneralProduct.h:335:7: error: request for member ‘data’ in ‘static_dest’, which is of non-class type ‘int’
       ei_declare_aligned_stack_constructed_variable(ResScalar, actualDestPtr, dest.size(),
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/eigen3/Eigen/src/Core/Transpose.h:77:41: note: suggested alternative: ‘remove_reference’
   EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::remove_reference_t<MatrixTypeNested>& nestedExpression() {
                                         ^~~
                                         remove_reference
/usr/local/include/eigen3/Eigen/src/Core/GeneralProduct.h:335:7: error: request for member ‘data’ in ‘static_dest’, which is of non-class type ‘int’
       ei_declare_aligned_stack_constructed_variable(ResScalar, actualDestPtr, dest.size(),
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/eigen3/Eigen/src/Core/Transpose.h:120:16: error: ‘conditional_t’ in namespace ‘std’ does not name a template type
   typedef std::conditional_t<internal::is_lvalue<MatrixType>::value, Scalar, const Scalar> ScalarWithConstIfNotLvalue;
                ^~~~~~~~~~~~~
In file included from /usr/local/include/eigen3/Eigen/Core:341,
                 from /home/nvidia/opencv/modules/core/include/opencv2/core/private.hpp:66,
                 from /home/nvidia/opencv/modules/core/src/precomp.hpp:55,
                 from /home/nvidia/opencv/modules/core/src/algorithm.cpp:43:
/usr/local/include/eigen3/Eigen/src/Core/GeneralProduct.h: In static member function ‘static void Eigen::internal::gemv_dense_selector<2, 1, true>::run(const Lhs&, const Rhs&, Dest&, const typename Dest::Scalar&)’:
/usr/local/include/eigen3/Eigen/src/Core/GeneralProduct.h:382:10: error: ‘add_const_t’ is not a member of ‘std’
     std::add_const_t<ActualLhsType> actualLhs = LhsBlasTraits::extract(lhs);
          ^~~~~~~~~~~
/usr/local/include/eigen3/Eigen/src/Core/SolverBase.h:136:16: error: ‘AdjointReturnType’ does not name a type; did you mean ‘CoeffReturnType’?
   inline const AdjointReturnType adjoint() const { return AdjointReturnType(derived().transpose()); }
                ^~~~~~~~~~~~~~~~~
                CoeffReturnType
/usr/local/include/eigen3/Eigen/src/Core/Transpose.h:120:11: note: suggested alternative: ‘conditional’
   typedef std::conditional_t<internal::is_lvalue<MatrixType>::value, Scalar, const Scalar> ScalarWithConstIfNotLvalue;
           ^~~
           conditional
/usr/local/include/eigen3/Eigen/src/Core/GeneralProduct.h:382:10: note: suggested alternative: ‘add_const’
     std::add_const_t<ActualLhsType> actualLhs = LhsBlasTraits::extract(lhs);
          ^~~~~~~~~~~
          add_const
/usr/local/include/eigen3/Eigen/src/Core/GeneralProduct.h:382:35: error: expected primary-expression before ‘>’ token
     std::add_const_t<ActualLhsType> actualLhs = LhsBlasTraits::extract(lhs);
                                   ^
/usr/local/include/eigen3/Eigen/src/Core/GeneralProduct.h:382:37: error: ‘actualLhs’ was not declared in this scope
     std::add_const_t<ActualLhsType> actualLhs = LhsBlasTraits::extract(lhs);
                                     ^~~~~~~~~
In file included from /usr/local/include/eigen3/Eigen/Core:330,
                 from /home/nvidia/opencv/modules/core/include/opencv2/core/private.hpp:66,
                 from /home/nvidia/opencv/modules/core/src/precomp.hpp:55,
                 from /home/nvidia/opencv/modules/core/src/alloc.cpp:43:
/usr/local/include/eigen3/Eigen/src/Core/Reshaped.h:185:26: error: ‘remove_reference_t’ in namespace ‘std’ does not name a template type
   EIGEN_DEVICE_FUNC std::remove_reference_t<XprType>& nestedExpression() { return m_xpr; }
                          ^~~~~~~~~~~~~~~~~~
/usr/local/include/eigen3/Eigen/src/Core/Reshaped.h:185:21: note: suggested alternative: ‘remove_reference’
   EIGEN_DEVICE_FUNC std::remove_reference_t<XprType>& nestedExpression() { return m_xpr; }
                     ^~~
                     remove_reference
/usr/local/include/eigen3/Eigen/src/Core/GeneralProduct.h:383:10: error: ‘add_const_t’ is not a member of ‘std’
     std::add_const_t<ActualRhsType> actualRhs = RhsBlasTraits::extract(rhs);
          ^~~~~~~~~~~
/usr/local/include/eigen3/Eigen/src/Core/GeneralProduct.h:383:10: note: suggested alternative: ‘add_const’
     std::add_const_t<ActualRhsType> actualRhs = RhsBlasTraits::extract(rhs);
          ^~~~~~~~~~~
          add_const
/usr/local/include/eigen3/Eigen/src/Core/GeneralProduct.h:383:35: error: expected primary-expression before ‘>’ token
     std::add_const_t<ActualRhsType> actualRhs = RhsBlasTraits::extract(rhs);
                                   ^
/usr/local/include/eigen3/Eigen/src/Core/GeneralProduct.h:383:37: error: ‘actualRhs’ was not declared in this scope
     std::add_const_t<ActualRhsType> actualRhs = RhsBlasTraits::extract(rhs);
                                     ^~~~~~~~~
^Cmodules/core/CMakeFiles/opencv_core.dir/build.make:541: recipe for target 'modules/core/CMakeFiles/opencv_core.dir/src/alloc.cpp.o' failed
make[2]: *** [modules/core/CMakeFiles/opencv_core.dir/src/alloc.cpp.o] Interrupt
modules/core/CMakeFiles/opencv_core.dir/build.make:589: recipe for target 'modules/core/CMakeFiles/opencv_core.dir/src/arithm.dispatch.cpp.o' failed
make[2]: *** [modules/core/CMakeFiles/opencv_core.dir/src/arithm.dispatch.cpp.o] Interrupt

I think it might be related to the gcc?

some details about the gcc (I might have changed it accidentally when I tried to install another stuff and I dont know how to change it back to th default Jetson GCC and I am not sure If I deleted the files of the default gcc)

gcc --version
gcc (Ubuntu/Linaro 8.4.0-1ubuntu1~18.04) 8.4.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


 ls /usr/bin/gcc
gcc           gcc-8         gcc-ar-7      gcc-nm        gcc-nm-8      gcc-ranlib-7
gcc-7         gcc-ar        gcc-ar-8      gcc-nm-7      gcc-ranlib    gcc-ranlib-8

Thanks

Hi,

Does OpenCV 4.6 work for you?

If yes, please check the below script to build it from the source.
The script is verified on the JetPack 5 environment (CUDA11.4).

Thanks.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.