Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 928605 - media-libs/opencv: undefined reference to `__cxa_call_terminate'
Summary: media-libs/opencv: undefined reference to `__cxa_call_terminate'
Status: RESOLVED WORKSFORME
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Paul Zander
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-04-04 23:14 UTC by look
Modified: 2024-04-21 17:48 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
The build log. (build.log,353.32 KB, text/x-log)
2024-04-04 23:14 UTC, look
Details
The build environment. (environment,252.10 KB, text/plain)
2024-04-04 23:15 UTC, look
Details
The emerge --info output (emerge-info-output.txt,19.62 KB, text/plain)
2024-04-04 23:15 UTC, look
Details
New build log after changes (build-log-2.log.gz,61.85 KB, application/gzip)
2024-04-09 01:46 UTC, look
Details
Build log after changes (redone! ignore previous one) (build-log-3.log,27.97 KB, text/x-log)
2024-04-09 05:18 UTC, look
Details

Note You need to log in before you can comment on or make changes to this bug.
Description look 2024-04-04 23:14:54 UTC
Created attachment 889472 [details]
The build log.

Hello. I am having trouble compiling some CUDA-related packages as this seems related to https://bugs.gentoo.org/928580. I have declared
TORCH_CUDA_ARCH_LIST="6.1"
CUDA_GENERATION="Pascal"
CUDA_ARCH="sm_61"

in my make.conf and disabled sandbox as well as my custom CFLAGS but still opencv does not compile:

FAILED: lib/libopencv_core.so.4.9.0 
: && /usr/bin/x86_64-pc-linux-gnu-g++ -fPIC -march=native -O2 -pipe -fprefetch-loop-arrays   -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Winit-self -Wpointer-arith -Wsign-promo -Wuninitialized -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 -mssse3 -msse4.1 -mpopcnt -msse4.2 -mf16c -mfma -mavx -mavx2 -mavx512f -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp -Wno-undef -Wno-enum-compare -Wno-unused-function -Wno-shadow  -Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs  -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined -shared -Wl,-soname,libopencv_core.so.409 -o lib/libopencv_core.so.4.9.0 modules/core/CMakeFiles/opencv_core.dir/src/algorithm.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/alloc.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/arithm.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/arithm.dispatch.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/array.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/async.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/batch_distance.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/bindings_utils.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/buffer_area.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/channels.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/check.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/command_line_parser.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/conjugate_gradient.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/convert.dispatch.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/convert_c.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/convert_scale.dispatch.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/copy.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/count_non_zero.dispatch.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/cuda_gpu_mat.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/cuda_gpu_mat_nd.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/cuda_host_mem.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/cuda_info.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/cuda_stream.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/datastructs.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/directx.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/downhill_simplex.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/dxt.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/gl_core_3_1.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/glob.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/hal_internal.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/has_non_zero.dispatch.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/kmeans.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/lapack.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/lda.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/logger.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/lpsolver.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/lut.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/mathfuncs.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/mathfuncs_core.dispatch.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/matmul.dispatch.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/matrix.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/matrix_c.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/matrix_decomp.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/matrix_expressions.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/matrix_iterator.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/matrix_operations.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/matrix_sparse.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/matrix_transform.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/matrix_wrap.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/mean.dispatch.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/merge.dispatch.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/minmax.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/norm.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/ocl.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/opencl/runtime/opencl_clblas.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/opencl/runtime/opencl_clfft.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/opencl/runtime/opencl_core.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/opengl.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/out.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/ovx.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/parallel.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/parallel/parallel.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/parallel/parallel_openmp.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/parallel/parallel_tbb.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/parallel_impl.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/pca.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/persistence.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/persistence_base64_encoding.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/persistence_json.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/persistence_types.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/persistence_xml.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/persistence_yml.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/rand.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/softfloat.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/split.dispatch.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/stat.dispatch.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/stat_c.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/stl.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/sum.dispatch.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/system.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/tables.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/trace.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/types.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/umatrix.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/utils/datafile.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/utils/filesystem.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/utils/logtagconfigparser.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/utils/logtagmanager.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/utils/samples.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/va_intel.cpp.o modules/core/CMakeFiles/opencv_core.dir/opencl_kernels_core.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/cuda/gpu_mat.cu.o modules/core/CMakeFiles/opencv_core.dir/src/cuda/gpu_mat_nd.cu.o -L/opt/cuda/targets/x86_64-linux/lib/stubs   -L/opt/cuda/targets/x86_64-linux/lib   -L/usr/lib/gcc/x86_64-pc-linux-gnu/12 -Wl,-rpath,/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv-4.9.0_build-abi_x86_64.amd64-python3_11/lib:  lib/libopencv_cudev.so.4.9.0  -ldl  -lm  -lpthread  -lrt  /lib64/libz.so  /lib64/libOpenGL.so  /lib64/libGLX.so  /lib64/libGLU.so  /usr/lib/gcc/x86_64-pc-linux-gnu/14/libgomp.so  /usr/lib64/libpthread.a  -lcudadevrt  -lcudart_static  -lrt  -lpthread  -ldl && :
/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../x86_64-pc-linux-gnu/bin/ld: modules/core/CMakeFiles/opencv_core.dir/src/async.cpp.o: in function `cv::AsyncPromise::AsyncPromise() [clone .cold]':
async.cpp:(.text.unlikely._ZN2cv12AsyncPromiseC2Ev+0x44): undefined reference to `__cxa_call_terminate'
/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../x86_64-pc-linux-gnu/bin/ld: modules/core/CMakeFiles/opencv_core.dir/src/async.cpp.o: in function `cv::AsyncArray::Impl::~Impl()':
async.cpp:(.text._ZN2cv10AsyncArray4ImplD2Ev[_ZN2cv10AsyncArray4ImplD5Ev]+0x5b6): undefined reference to `__cxa_call_terminate'
/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../x86_64-pc-linux-gnu/bin/ld: modules/core/CMakeFiles/opencv_core.dir/src/parallel.cpp.o: in function `cv::parallel_for_impl(cv::Range const&, cv::ParallelLoopBody const&, double) [clone ._omp_fn.0] [clone .cold]':
parallel.cpp:(.text.unlikely._ZN2cvL17parallel_for_implERKNS_5RangeERKNS_16ParallelLoopBodyEd._omp_fn.0+0x31): undefined reference to `__cxa_call_terminate'
/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../x86_64-pc-linux-gnu/bin/ld: modules/core/CMakeFiles/opencv_core.dir/src/system.cpp.o: in function `cv::TLSDataAccumulator<cv::instr::NodeDataTls>::~TLSDataAccumulator()':
system.cpp:(.text._ZN2cv18TLSDataAccumulatorINS_5instr11NodeDataTlsEED2Ev[_ZN2cv18TLSDataAccumulatorINS_5instr11NodeDataTlsEED5Ev]+0x21a): undefined reference to `__cxa_call_terminate'
/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../x86_64-pc-linux-gnu/bin/ld: modules/core/CMakeFiles/opencv_core.dir/src/umatrix.cpp.o: in function `cv::UMatDataAutoLock::~UMatDataAutoLock() [clone .cold]':
umatrix.cpp:(.text.unlikely._ZN2cv16UMatDataAutoLockD2Ev+0xf): undefined reference to `__cxa_call_terminate'
/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../x86_64-pc-linux-gnu/bin/ld: modules/core/CMakeFiles/opencv_core.dir/src/utils/filesystem.cpp.o:filesystem.cpp:(.text.unlikely._ZN2cv6plugin4impl10DynamicLibD2Ev+0x12): more undefined references to `__cxa_call_terminate' follow
collect2: error: ld returned 1 exit status

It seems like my CUDA device is not being detected even though when I run the CUDA-provided /opt/cuda/extras/demo_suite/deviceQuery, my device is detected:

./deviceQuery 
/opt/cuda/extras/demo_suite/deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "NVIDIA GeForce GTX 1080 Ti"
  CUDA Driver Version / Runtime Version          12.4 / 12.3
  CUDA Capability Major/Minor version number:    6.1
  Total amount of global memory:                 11143 MBytes (11684282368 bytes)
  (28) Multiprocessors, (128) CUDA Cores/MP:     3584 CUDA Cores
  GPU Max Clock rate:                            1582 MHz (1.58 GHz)
  Memory Clock rate:                             5505 Mhz
  Memory Bus Width:                              352-bit
  L2 Cache Size:                                 2883584 bytes
  Maximum Texture Dimension Size (x,y,z)         1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
  Maximum Layered 1D Texture Size, (num) layers  1D=(32768), 2048 layers
  Maximum Layered 2D Texture Size, (num) layers  2D=(32768, 32768), 2048 layers
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total number of registers available per block: 65536
  Warp size:                                     32
  Maximum number of threads per multiprocessor:  2048
  Maximum number of threads per block:           1024
  Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
  Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and kernel execution:          Yes with 2 copy engine(s)
  Run time limit on kernels:                     Yes
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Disabled
  Device supports Unified Addressing (UVA):      Yes
  Device supports Compute Preemption:            Yes
  Supports Cooperative Kernel Launch:            Yes
  Supports MultiDevice Co-op Kernel Launch:      Yes
  Device PCI Domain ID / Bus ID / location ID:   0 / 2 / 0
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 12.4, CUDA Runtime Version = 12.3, NumDevs = 1, Device0 = NVIDIA GeForce GTX 1080 Ti
Result = PASS
/opt/cuda/extras/demo_suite λ
Comment 1 look 2024-04-04 23:15:24 UTC
Created attachment 889473 [details]
The build environment.
Comment 2 look 2024-04-04 23:15:32 UTC
Created attachment 889474 [details]
The emerge --info output
Comment 3 look 2024-04-04 23:53:36 UTC
Hi. I just fixed this by following the instructions here https://www.reddit.com/r/Gentoo/comments/1arlsfi/cuda_gcc_too_recent/ to use GCC12 as the compiler for opencv.
Comment 4 Paul Zander 2024-04-08 15:00:13 UTC
set `CUDA_ARCH_BIN="6.1"` aswell for opencv. It seems I forgot the logic for CUDA_GENERATION. 

Not sure why __nvcc_device_query fails, but that might be due to nvidia-drivers-550. The fix for that got pushed recently. A reinstall of nvidia-cuda-toolkit-12.3.2 might fix that.

I also see `-L/usr/lib/gcc/x86_64-pc-linux-gnu/12` in the two failing lines. That shouldn't be in there. Maybe that's from the CC=gcc-12 stuff.
Comment 5 look 2024-04-09 01:46:07 UTC
Okay. I did that and I rebuilt world, now I'm getting:
FAILED: modules/cudaoptflow/CMakeFiles/opencv_cudaoptflow.dir/src/farneback.cpp.o 
/usr/bin/x86_64-pc-linux-gnu-g++ -DCVAPI_EXPORTS -D_USE_MATH_DEFINES -D__OPENCV_BUILD=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv_contrib-4.9.0/modules/cudaoptflow/include -I/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv-4.9.0_build-abi_x86_64.amd64-python3_11/modules/cudaoptflow -I/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv-4.9.0/modules/core/include -I/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv_contrib-4.9.0/modules/cudaarithm/include -I/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv-4.9.0/modules/flann/include -I/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv-4.9.0/modules/imgproc/include -I/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv_contrib-4.9.0/modules/cudafilters/include -I/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv_contrib-4.9.0/modules/cudaimgproc/include -I/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv_contrib-4.9.0/modules/cudawarping/include -I/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv-4.9.0/modules/features2d/include -I/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv-4.9.0/modules/imgcodecs/include -I/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv-4.9.0/modules/calib3d/include -I/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv-4.9.0/modules/video/include -I/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv_contrib-4.9.0/modules/ximgproc/include -I/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv_contrib-4.9.0/modules/optflow/include -isystem /var/tmp/portage/media-libs/opencv-4.9.0/work/opencv-4.9.0_build-abi_x86_64.amd64-python3_11 -isystem /opt/cuda/targets/x86_64-linux/include -isystem /usr/include/eigen3  -march=native -O3 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -pipe -fuse-linker-plugin -fgraphite-identity -floop-nest-optimize -fdevirtualize-at-ltrans -fipa-pta -fno-semantic-interposition -ggdb3 -fprefetch-loop-arrays   -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Winit-self -Wpointer-arith -Wsign-promo -Wuninitialized -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 -mssse3 -msse4.1 -mpopcnt -msse4.2 -mf16c -mfma -mavx -mavx2 -mavx512f -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp -Wno-undef -Wno-missing-declarations -Wno-shadow -Wno-strict-aliasing -std=c++17 -fPIC -MD -MT modules/cudaoptflow/CMakeFiles/opencv_cudaoptflow.dir/src/farneback.cpp.o -MF modules/cudaoptflow/CMakeFiles/opencv_cudaoptflow.dir/src/farneback.cpp.o.d -o modules/cudaoptflow/CMakeFiles/opencv_cudaoptflow.dir/src/farneback.cpp.o -c /var/tmp/portage/media-libs/opencv-4.9.0/work/opencv_contrib-4.9.0/modules/cudaoptflow/src/farneback.cpp
/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv_contrib-4.9.0/modules/cudaoptflow/src/farneback.cpp:50:25: error: template argument 1 is invalid
   50 | Ptr<FarnebackOpticalFlow> cv::cuda::FarnebackOpticalFlow::create(int, double, bool, int, int, int, double, int) { throw_no_cuda(); return Ptr<FarnebackOpticalFlow>(); }
      |                         ^
/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv_contrib-4.9.0/modules/cudaoptflow/src/farneback.cpp:50:27: error: no declaration matches ‘int cv::cuda::FarnebackOpticalFlow::create(int, double, bool, int, int, int, double, int)’
   50 | Ptr<FarnebackOpticalFlow> cv::cuda::FarnebackOpticalFlow::create(int, double, bool, int, int, int, double, int) { throw_no_cuda(); return Ptr<FarnebackOpticalFlow>(); }
Comment 6 look 2024-04-09 01:46:46 UTC
Created attachment 889964 [details]
New build log after changes
Comment 7 look 2024-04-09 02:26:47 UTC
Ah never mind! I had CUDAARCHS="6.1" in my make.conf and that somehow was messing up the compilation. Now I don't use an env file for opencv, just have:

CUDAHOSTCXX="/usr/x86_64-pc-linux-gnu/gcc-bin/12"
CUDA_ARCH="sm_61"
CUDA_ARCH_BIN="6.1"
CUDA_GENERATION="Pascal"
CUDA_VERBOSE="false"
TORCH_CUDA_ARCH_LIST="6.1"

in my make.conf and it compiles.
Comment 8 look 2024-04-09 05:18:52 UTC
Created attachment 889978 [details]
Build log after changes (redone! ignore previous one)

Oh wait, my bad. It compiled with a gcc12.conf env file:
CC="gcc-12"
CXX="g++-12"
NVCC_PREPEND_FLAGS="--compiler-bindir /usr/x86_64-pc-linux-gnu/gcc-bin/12"
CUDAHOSTCXX="/usr/x86_64-pc-linux-gnu/gcc-bin/12"

and when I disable it, the build fails:

FAILED: lib/libopencv_core.so.4.9.0 
: && /usr/bin/x86_64-pc-linux-gnu-g++ -fPIC -march=native -O3 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -pipe -fuse-linker-plugin -fgraphite-identity -floop-nest-optimize -fdevirtualize-at-ltrans -fipa-pta -fno-semantic-interposition -ggdb3 -fprefetch-loop-arrays   -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Winit-self -Wpointer-arith -Wsign-promo -Wuninitialized -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 -mssse3 -msse4.1 -mpopcnt -msse4.2 -mf16c -mfma -mavx -mavx2 -mavx512f -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp -Wno-undef -Wno-enum-compare -Wno-unused-function -Wno-shadow  -Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs  -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined -shared -Wl,-soname,libopencv_core.so.409 -o lib/libopencv_core.so.4.9.0 modules/core/CMakeFiles/opencv_core.dir/src/algorithm.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/alloc.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/arithm.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/arithm.dispatch.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/array.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/async.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/batch_distance.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/bindings_utils.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/buffer_area.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/channels.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/check.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/command_line_parser.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/conjugate_gradient.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/convert.dispatch.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/convert_c.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/convert_scale.dispatch.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/copy.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/count_non_zero.dispatch.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/cuda_gpu_mat.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/cuda_gpu_mat_nd.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/cuda_host_mem.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/cuda_info.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/cuda_stream.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/datastructs.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/directx.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/downhill_simplex.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/dxt.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/gl_core_3_1.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/glob.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/hal_internal.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/has_non_zero.dispatch.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/kmeans.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/lapack.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/lda.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/logger.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/lpsolver.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/lut.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/mathfuncs.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/mathfuncs_core.dispatch.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/matmul.dispatch.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/matrix.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/matrix_c.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/matrix_decomp.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/matrix_expressions.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/matrix_iterator.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/matrix_operations.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/matrix_sparse.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/matrix_transform.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/matrix_wrap.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/mean.dispatch.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/merge.dispatch.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/minmax.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/norm.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/ocl.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/opencl/runtime/opencl_clblas.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/opencl/runtime/opencl_clfft.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/opencl/runtime/opencl_core.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/opengl.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/out.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/ovx.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/parallel.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/parallel/parallel.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/parallel/parallel_openmp.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/parallel/parallel_tbb.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/parallel_impl.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/pca.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/persistence.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/persistence_base64_encoding.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/persistence_json.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/persistence_types.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/persistence_xml.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/persistence_yml.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/rand.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/softfloat.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/split.dispatch.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/stat.dispatch.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/stat_c.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/stl.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/sum.dispatch.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/system.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/tables.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/trace.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/types.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/umatrix.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/utils/datafile.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/utils/filesystem.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/utils/logtagconfigparser.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/utils/logtagmanager.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/utils/samples.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/va_intel.cpp.o modules/core/CMakeFiles/opencv_core.dir/opencl_kernels_core.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/cuda/gpu_mat.cu.o modules/core/CMakeFiles/opencv_core.dir/src/cuda/gpu_mat_nd.cu.o -L/opt/cuda/targets/x86_64-linux/lib/stubs   -L/opt/cuda/targets/x86_64-linux/lib   -L/usr/lib/gcc/x86_64-pc-linux-gnu/12 -Wl,-rpath,/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv-4.9.0_build-abi_x86_64.amd64-python3_11/lib:  lib/libopencv_cudev.so.4.9.0  -ldl  -lm  -lpthread  -lrt  /lib64/libz.so  /lib64/libOpenGL.so  /lib64/libGLX.so  /lib64/libGLU.so  /usr/lib/gcc/x86_64-pc-linux-gnu/14/libgomp.so  /usr/lib64/libpthread.a  -lcudadevrt  -lcudart_static  -lrt  -lpthread  -ldl && :
/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../x86_64-pc-linux-gnu/bin/ld: modules/core/CMakeFiles/opencv_core.dir/src/async.cpp.o: in function `cv::AsyncArray::Impl::~Impl()':
/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv-4.9.0/modules/core/src/async.cpp:73:(.text._ZN2cv10AsyncArray4ImplD2Ev[_ZN2cv10AsyncArray4ImplD5Ev]+0x5a7): undefined reference to `__cxa_call_terminate'
/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../x86_64-pc-linux-gnu/bin/ld: modules/core/CMakeFiles/opencv_core.dir/src/async.cpp.o: in function `cv::AsyncPromise::AsyncPromise()':
/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv-4.9.0/modules/core/src/async.cpp:471:(.text.unlikely._ZN2cv12AsyncPromiseC2Ev+0x44): undefined reference to `__cxa_call_terminate'
/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../x86_64-pc-linux-gnu/bin/ld: modules/core/CMakeFiles/opencv_core.dir/src/parallel.cpp.o: in function `cv::details::FPDenormalsIgnoreHintScope::~FPDenormalsIgnoreHintScope()':
/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv-4.9.0/modules/core/include/opencv2/core/utils/fp_control_utils.hpp:37:(.text.unlikely._ZN2cvL17parallel_for_implERKNS_5RangeERKNS_16ParallelLoopBodyEd._omp_fn.0+0x31): undefined reference to `__cxa_call_terminate'
/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../x86_64-pc-linux-gnu/bin/ld: modules/core/CMakeFiles/opencv_core.dir/src/system.cpp.o: in function `cv::TLSDataContainer::~TLSDataContainer()':
/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv-4.9.0/modules/core/src/system.cpp:2067:(.text.unlikely._ZN2cv16TLSDataContainerD2Ev.part.0+0x22): undefined reference to `__cxa_call_terminate'
/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../x86_64-pc-linux-gnu/bin/ld: modules/core/CMakeFiles/opencv_core.dir/src/system.cpp.o: in function `cv::TLSData<cv::CoreTLSData>::~TLSData()':
/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv-4.9.0/modules/core/include/opencv2/core/utils/tls.hpp:67:(.text._ZN2cv7TLSDataINS_11CoreTLSDataEED0Ev[_ZN2cv7TLSDataINS_11CoreTLSDataEED5Ev]+0x3dd): undefined reference to `__cxa_call_terminate'
/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../x86_64-pc-linux-gnu/bin/ld: modules/core/CMakeFiles/opencv_core.dir/src/system.cpp.o:/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv-4.9.0/modules/core/include/opencv2/core/utils/tls.hpp:67: more undefined references to `__cxa_call_terminate' follow
collect2: error: ld returned 1 exit status
[177/1133] /opt/cuda/bin/nvcc -forward-unknown-to-host-compiler -ccbin=/usr/x86_64-pc-linux-gnu/gcc-bin/12 -DCVAPI_EXPORTS -D_USE_MATH_DEFINES -D__OPENCV_BUILD=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv_contrib-4.9.0/modules/cudaarithm/include -I/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv-4.9.0_build-abi_x86_64.amd64-python3_11/modules/cudaarithm -I/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv_contrib-4.9.0/modules/cudev/include -I/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv-4.9.0/modules/core/include -isystem /var/tmp/portage/media-libs/opencv-4.9.0/work/opencv-4.9.0_build-abi_x86_64.amd64-python3_11 -isystem /opt/cuda/targets/x86_64-linux/include -isystem /usr/include/eigen3 -O2 -g -DNDEBUG -std=c++14 "--generate-code=arch=compute_52,code=[compute_52,sm_52]" "--generate-code=arch=compute_52,code=[sm_52]" "--generate-code=arch=compute_52,code=[compute_52]" -Xcompiler=-fPIC -D_FORCE_INLINES -Xcompiler=-DCVAPI_EXPORTS -Xcompiler=-fPIC "-Xcompiler=-march=native -O3 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -pipe -fuse-linker-plugin -fgraphite-identity -floop-nest-optimize -fdevirtualize-at-ltrans -fipa-pta -fno-semantic-interposition  -fprefetch-loop-arrays   -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Winit-self -Wpointer-arith  -Wuninitialized   -Wno-comment -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -mssse3 -msse4.1 -mpopcnt -msse4.2 -mf16c -mfma -mavx -mavx2 -mavx512f -fvisibility=hidden  -fopenmp -Wno-undef -Wno-missing-declarations -Wno-shadow -Wno-unused-but-set-variable    " -MD -MT modules/cudaarithm/CMakeFiles/opencv_cudaarithm.dir/src/cuda/sub_scalar.cu.o -MF modules/cudaarithm/CMakeFiles/opencv_cudaarithm.dir/src/cuda/sub_scalar.cu.o.d -x cu -c /var/tmp/portage/media-libs/opencv-4.9.0/work/opencv_contrib-4.9.0/modules/cudaarithm/src/cuda/sub_scalar.cu -o modules/cudaarithm/CMakeFiles/opencv_cudaarithm.dir/src/cuda/sub_scalar.cu.o
[178/1133] /usr/bin/x86_64-pc-linux-gnu-g++ -DCVAPI_EXPORTS -D_USE_MATH_DEFINES -D__OPENCV_BUILD=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv-4.9.0/modules/flann/include -I/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv-4.9.0_build-abi_x86_64.amd64-python3_11/modules/flann -I/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv_contrib-4.9.0/modules/cudev/include -I/var/tmp/portage/media-libs/opencv-4.9.0/work/opencv-4.9.0/modules/core/include -isystem /var/tmp/portage/media-libs/opencv-4.9.0/work/opencv-4.9.0_build-abi_x86_64.amd64-python3_11 -isystem /usr/include/eigen3  -march=native -O3 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -pipe -fuse-linker-plugin -fgraphite-identity -floop-nest-optimize -fdevirtualize-at-ltrans -fipa-pta -fno-semantic-interposition -ggdb3 -fprefetch-loop-arrays   -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -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 -mssse3 -msse4.1 -mpopcnt -msse4.2 -mf16c -mfma -mavx -mavx2 -mavx512f -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp -std=c++17 -fPIC -MD -MT modules/flann/CMakeFiles/opencv_flann.dir/src/miniflann.cpp.o -MF modules/flann/CMakeFiles/opencv_flann.dir/src/miniflann.cpp.o.d -o modules/flann/CMakeFiles/opencv_flann.dir/src/miniflann.cpp.o -c /var/tmp/portage/media-libs/opencv-4.9.0/work/opencv-4.9.0/modules/flann/src/miniflann.cpp
ninja: build stopped: subcommand failed.
 * ERROR: media-libs/opencv-4.9.0::gentoo failed (compile phase):
 *   ninja -v -j32 -l32 failed
Comment 9 Paul Zander 2024-04-09 10:18:23 UTC
Does it compile with out 
>CC="gcc-12"
>CXX="g++-12"
?
Comment 10 look 2024-04-09 15:03:54 UTC
N(In reply to Paul Zander from comment #9)
> Does it compile with out 
> >CC="gcc-12"
> >CXX="g++-12"
> ?

No, it does not compile for me without those two lines.
Comment 11 Paul Zander 2024-04-14 12:49:15 UTC
Can you add a full log without your gcc12.conf, but with the settings from https://bugs.gentoo.org/928605#c7. 
The attached log in https://bugs.gentoo.org/928605#c8 is for sci-libs/caffe2.

https://wiki.gentoo.org/wiki/Upgrading_GCC#undefined_reference_to_.60_cxa_call_terminate.40CXXABI_1.3.15.27
Comment 12 Paul Zander 2024-04-14 13:01:30 UTC
If that fails as well try USE="-openmp" please.
Comment 13 look 2024-04-18 04:34:17 UTC
Now it compiled without the gcc12.conf and without removing cuda nor openmp.

CUDAHOSTCXX="/usr/x86_64-pc-linux-gnu/gcc-bin/12"
CUDA_ARCH="sm_61"
CUDA_ARCH_BIN="6.1"
CUDA_GENERATION="Pascal"
CUDA_VERBOSE="false"
TORCH_CUDA_ARCH_LIST="6.1"
NVCC_PREPEND_FLAGS="--compiler-bindir /usr/x86_64-pc-linux-gnu/gcc-bin/12"

I had this in an env file, though probably some of the options are redundant with my make.conf or not necessary. Still, it finally works. Thank you!