Repository: opencv
Issue:  "Segmentation fault signal terminated program cc1plus" when make opencv lib on NX with cuda
Labels: category: build/install,category: 3rdparty

<!--
If you have a question rather than reporting a bug please go to https://forum.opencv.org where you get much faster responses.
If you need further assistance please read [How To Contribute](https://github.com/opencv/opencv/wiki/How_to_contribute).

This is a template helping you to create an issue which can be processed as quickly as possible. This is the bug reporting section for the OpenCV library.
-->

##### System information (version)
<!-- Example
- OpenCV => 4.5
- Operating System / Platform => Ubuntu 20.04 / Nvidia Jetson NX
- Compiler => gcc-7、gcc-8、gcc-9
-->

- OpenCV => 4.2
- Operating System / Platform => Ubuntu 20.04 / Nvidia Jetson NX /Linux 4.9.253-tegra SMP PREEMPT Mon Jul 26 12:19:28 PDT 2021 aarch64 aarch64 aarch64 GNU/Linux
- Compiler => gcc-7、gcc-8、gcc-9

##### Detailed description
After upgrade Ubuntu 20.04 to lastest packages,
when make opencv library with cuda and with opencv_calib3d,
and the compiler build the dls.cpp.o,
it will report "Segmentation fault signal terminated program cc1plus",
until make opencv library without opencv_calib3d.
##### Steps to reproduce

cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D INSTALL_C_EXAMPLES=OFF \
    -D OPENCV_EXTRA_MODULES_PATH='/home/ubuntu/Downloads/opencv_contrib/modules' \
    -D PYTHON_EXECUTABLE='/home/ubuntu/Downloads/opencv4/bin/python' \
    -D BUILD_EXAMPLES=ON \
    -D WITH_CUDA=ON \
    -D CUDA_ARCH_BIN=7.2 \
    -D CUDA_ARCH_PTX="" \
    -D ENABLE_FAST_MATH=ON \
    -D CUDA_FAST_MATH=ON \
    -D WITH_CUBLAS=ON \
    -D WITH_LIBV4L=ON \
    -D WITH_GSTREAMER=ON \
    -D WITH_GSTREAMER_0_10=OFF \
    -D WITH_TBB=ON \
    ../
make 

Scanning dependencies of target opencv_photo
[ 30%] Building CXX object modules/photo/CMakeFiles/opencv_photo.dir/src/align.cpp.o
[ 30%] Building CXX object modules/calib3d/CMakeFiles/opencv_calib3d.dir/src/fisheye.cpp.o
c++: internal compiler error: Segmentation fault signal terminated program cc1plus
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-9/README.Bugs> for instructions.
make[2]: *** [modules/calib3d/CMakeFiles/opencv_calib3d.dir/build.make:172: **modules/calib3d/CMakeFiles/opencv_calib3d.dir/src/dls.cpp.o] Error 4**
make[2]: *** Waiting for unfinished jobs....
[ 30%] Building CXX object modules/photo/CMakeFiles/opencv_photo.dir/src/calibrate.cpp.o
[ 30%] Building CXX object modules/photo/CMakeFiles/opencv_photo.dir/src/contrast_preserve.cpp.o
[ 30%] Building NVCC (Device) object modules/cudafeatures2d/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_bf_match.cu.o
[ 30%] Building CXX object modules/photo/CMakeFiles/opencv_photo.dir/src/denoise_tvl1.cpp.o
[ 30%] Building CXX object modules/photo/CMakeFiles/opencv_photo.dir/src/denoising.cpp.o
make[1]: *** [CMakeFiles/Makefile2:10555: modules/calib3d/CMakeFiles/opencv_calib3d.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 30%] Building CXX object modules/photo/CMakeFiles/opencv_photo.dir/src/denoising.cuda.cpp.o
^Cmake[2]: *** Deleting file 'modules/photo/CMakeFiles/opencv_photo.dir/src/denoise_tvl1.cpp.o'
make[2]: *** [modules/photo/CMakeFiles/opencv_photo.dir/build.make:127: modules/photo/CMakeFiles/opencv_photo.dir/src/denoising.cpp.o] Interrupt
make[2]: *** [modules/photo/CMakeFiles/opencv_photo.dir/build.make:140: modules/photo/CMakeFiles/opencv_photo.dir/src/denoising.cuda.cpp.o] Interrupt
make[2]: *** [modules/photo/CMakeFiles/opencv_photo.dir/build.make:114: modules/photo/CMakeFiles/opencv_photo.dir/src/denoise_tvl1.cpp.o] Interrupt
make[1]: *** [CMakeFiles/Makefile2:9100: modules/photo/CMakeFiles/opencv_photo.dir/all] Interrupt
make[2]: *** [modules/cudafeatures2d/CMakeFiles/opencv_cudafeatures2d.dir/build.make:72: modules/cudafeatures2d/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_bf_match.cu.o] Interrupt
make[1]: *** [CMakeFiles/Makefile2:10779: modules/cudafeatures2d/CMakeFiles/opencv_cudafeatures2d.dir/all] Interrupt
make: *** [Makefile:163: all] Interrupt
##### Issue submission checklist

 - [V ] I report the issue, it's not a question
   <!--
   OpenCV team works with forum.opencv.org, Stack Overflow and other communities
   to discuss problems. Tickets with question without real issue statement will be
   closed.
   -->
 - [V] I checked the problem with documentation, FAQ, open issues,
       forum.opencv.org, Stack Overflow, etc and have not found solution
   <!--
   Places to check:
   * OpenCV documentation: https://docs.opencv.org
   * FAQ page: https://github.com/opencv/opencv/wiki/FAQ
   * OpenCV forum: https://forum.opencv.org
   * OpenCV issue tracker: https://github.com/opencv/opencv/issues?q=is%3Aissue
   * Stack Overflow branch: https://stackoverflow.com/questions/tagged/opencv
   -->
 - [V] I updated to latest OpenCV version and the issue is still there
   <!--
   master branch for OpenCV 4.x and 3.4 branch for OpenCV 3.x releases.
   OpenCV team supports only latest release for each branch.
   The ticket is closed, if the problem is not reproduced with modern version.
   -->
 - [V] There is reproducer code and related data files: videos, images, onnx, etc
   <!--
   The best reproducer -- test case for OpenCV that we can add to the library.
   Recommendations for media files and binary files:
   * Try to reproduce the issue with images and videos in opencv_extra repository
     to reduce attachment size
   * Use PNG for images, if you report some CV related bug, but not image reader
     issue
   * Attach the image as archive to the ticket, if you report some reader issue.
     Image hosting services compress images and it breaks the repro code.
   * Provide ONNX file for some public model or ONNX file with with random weights,
     if you report ONNX parsing or handling issue. Architecture details diagram
     from netron tool can be very useful too. See https://lutzroeder.github.io/netron/
   -->