Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 700176

Summary: media-libs/opencv - ld: lib/libopencv_core.so.3.4.1: undefined reference to `cblas_zgemm'
Product: Gentoo Linux Reporter: Thomas Beutin <tb>
Component: Current packagesAssignee: Amy Liffey <amynka>
Status: RESOLVED FIXED    
Severity: normal CC: axl, cafaia, frp.bissey, leonchik1976, lumin, mail, rossbridger.cc, sam, sci
Priority: Normal Keywords: PullRequest
Version: unspecified   
Hardware: All   
OS: Linux   
URL: https://wiki.gentoo.org/wiki/Blas-lapack-switch
See Also: https://github.com/gentoo/gentoo/pull/17964
Whiteboard:
Package list:
Runtime testing required: ---
Bug Depends on:    
Bug Blocks: 746596    
Attachments: build.log (gzipped)

Description Thomas Beutin 2019-11-15 13:55:58 UTC
[...]
[544/680] : && /usr/bin/x86_64-pc-linux-gnu-g++  -march=sandybridge -fomit-frame-pointer -O2 -pipe   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-securi
ty -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -Wno-implicit-fallthrough -fdiagnostics-show-option -Wno-long-long -p
thread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -mssse3 -msse4.1 -mpopcnt -msse4.2 -mavx -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp  -Wl,-O1 -Wl,--as-needed  -Wl,--gc-sections    -rdynami
c modules/flann/CMakeFiles/opencv_test_flann.dir/test/test_lshtable_badarg.cpp.o modules/flann/CMakeFiles/opencv_test_flann.dir/test/test_main.cpp.o  -o bin/opencv_test_flann  lib/libopencv_ts.a lib/libopencv_flann.so.3.4.1 lib/libopencv_
highgui.so.3.4.1 -ldl -lm -lpthread -lrt -lGL -lGLU /usr/lib64/libtbb.so lib/libopencv_videoio.so.3.4.1 lib/libopencv_imgcodecs.so.3.4.1 lib/libopencv_imgproc.so.3.4.1 -L/usr/lib64 lib/libopencv_core.so.3.4.1 && :
FAILED: bin/opencv_test_flann 
: && /usr/bin/x86_64-pc-linux-gnu-g++  -march=sandybridge -fomit-frame-pointer -O2 -pipe   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissi
ng-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -Wno-implicit-fallthrough -fdiagnostics-show-option -Wno-long-long -pthread -fo
mit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -mssse3 -msse4.1 -mpopcnt -msse4.2 -mavx -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp  -Wl,-O1 -Wl,--as-needed  -Wl,--gc-sections    -rdynamic modules/
flann/CMakeFiles/opencv_test_flann.dir/test/test_lshtable_badarg.cpp.o modules/flann/CMakeFiles/opencv_test_flann.dir/test/test_main.cpp.o  -o bin/opencv_test_flann  lib/libopencv_ts.a lib/libopencv_flann.so.3.4.1 lib/libopencv_highgui.so
.3.4.1 -ldl -lm -lpthread -lrt -lGL -lGLU /usr/lib64/libtbb.so lib/libopencv_videoio.so.3.4.1 lib/libopencv_imgcodecs.so.3.4.1 lib/libopencv_imgproc.so.3.4.1 -L/usr/lib64 lib/libopencv_core.so.3.4.1 && :
/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: lib/libopencv_core.so.3.4.1: undefined reference to `cblas_zgemm'
/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: lib/libopencv_core.so.3.4.1: undefined reference to `cblas_sgemm'
/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: lib/libopencv_core.so.3.4.1: undefined reference to `cblas_dgemm'
/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: lib/libopencv_core.so.3.4.1: undefined reference to `cblas_cgemm'
collect2: error: ld returned 1 exit status


This might somewhat related to bug 698756 - i'm running on app-eselect/eselect-blas-0.2,virtual/{lapack.blas}-3.8,sci-libs/lapack-3.8, but have this issue on the system:

# eselect blas list
Available BLAS/CBLAS (lib32) candidates:
  (none found)
Available BLAS/CBLAS (lib64) candidates:
  (none found)



Reproducible: Always




# emerge --info '=media-libs/opencv-3.4.1-r6::gentoo'
Portage 2.3.76 (python 3.6.9-final-0, default/linux/amd64/17.0/desktop, gcc-9.2.0, glibc-2.29-r2, 5.3.11-gentoo x86_64)
=================================================================
                         System Settings
=================================================================
System uname: Linux-5.3.11-gentoo-x86_64-Intel_Xeon_E312xx_-Sandy_Bridge-with-gentoo-2.6
KiB Mem:    49353364 total,  33656896 free
KiB Swap:   33554428 total,  33553404 free
Timestamp of repository gentoo: Thu, 14 Nov 2019 08:45:01 +0000
Head commit of repository gentoo: e64d6fba8ed13603a8280f7c633211d4542cb5d0
sh bash 4.4_p23-r1
ld GNU ld (Gentoo 2.32 p2) 2.32.0
app-shells/bash:          4.4_p23-r1::gentoo
dev-java/java-config:     2.2.0-r4::gentoo
dev-lang/perl:            5.28.2-r1::gentoo
dev-lang/python:          2.7.16::gentoo, 3.6.9::gentoo
dev-util/cmake:           3.14.6::gentoo
dev-util/pkgconfig:       0.29.2::gentoo
sys-apps/baselayout:      2.6-r1::gentoo
sys-apps/openrc:          0.41.2::gentoo
sys-apps/sandbox:         2.13::gentoo
sys-devel/autoconf:       2.13-r1::gentoo, 2.69-r4::gentoo
sys-devel/automake:       1.11.6-r3::gentoo, 1.13.4-r2::gentoo, 1.15.1-r2::gentoo, 1.16.1-r1::gentoo
sys-devel/binutils:       2.32-r1::gentoo
sys-devel/gcc:            9.2.0-r2::gentoo
sys-devel/gcc-config:     2.1::gentoo
sys-devel/libtool:        2.4.6-r3::gentoo
sys-devel/make:           4.2.1-r4::gentoo
sys-kernel/linux-headers: 5.1::gentoo (virtual/os-headers)
sys-libs/glibc:           2.29-r2::gentoo
Repositories:

gentoo
    location: /usr/portage
    sync-type: rsync
    sync-uri: rsync://192.168.45.107/gentoo-portage
    priority: -1000
    sync-rsync-verify-max-age: 24
    sync-rsync-verify-jobs: 1
    sync-rsync-extra-opts: 
    sync-rsync-verify-metamanifest: yes

x-portage
    location: /usr/local/portage
    masters: gentoo
    priority: 0

barzog-overlay
    location: /var/lib/layman/barzog-overlay
    masters: gentoo
    priority: 50

java
    location: /var/lib/layman/java
    masters: gentoo
    priority: 50

python
    location: /var/lib/layman/python
    masters: gentoo
    priority: 50

rion
    location: /var/lib/layman/rion
    masters: gentoo
    priority: 50

science
    location: /var/lib/layman/science
    masters: gentoo
    priority: 50

seden
    location: /var/lib/layman/seden
    masters: gentoo
    priority: 50

ACCEPT_KEYWORDS="amd64"
ACCEPT_LICENSE="*"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=sandybridge -fomit-frame-pointer -O2 -pipe"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/lib64/fax /usr/share/gnupg/qualified.txt /var/spool/fax/etc /var/spool/munin-async/.ssh"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/php/apache2-php5.6/ext-active/ /etc/php/apache2-php7.2/ext-active/ /etc/php/apache2-php7.3/ext-active/ /etc/php
/cgi-php5.6/ext-active/ /etc/php/cgi-php7.2/ext-active/ /etc/php/cgi-php7.3/ext-active/ /etc/php/cli-php5.6/ext-active/ /etc/php/cli-php7.2/ext-active/ /etc/php/cli-php7.3/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo /etc/
texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c /var/spool/fax/etc/xferfaxlog"
CXXFLAGS="-march=sandybridge -fomit-frame-pointer -O2 -pipe"
DISTDIR="/mnt/gentoo/distfiles/"
ENV_UNSET="DBUS_SESSION_BUS_ADDRESS DISPLAY GOBIN PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs buildpkg config-protect-if-modified distlocks ebuild-locks fixlafiles ipc-sandbox merge-sync multilib-strict network-sandbox news parallel-fetch pid-sandbox preserve-li
bs protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="http://distfiles.gentoo.org"
INSTALL_MASK="/usr/lib/systemd/"
LANG="en_IE.utf8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
LINGUAS="en_GB en en_US de_DE de"
MAKEOPTS="-j28"
PKGDIR="/mnt/gentoo/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.gi
t"
PORTAGE_TMPDIR="/mnt/gentoo/tmp"
USE="R X X509 a52 aac aalib accounting acl acpi adns aim aio alsa amd64 amr ansi ao aot apache2 apng applet archive asm ass audio audiofile automount avahi avx awt bacula-console bash-completion bazaar bcmath berkdb bidi bind-mysql bittor
rent blas bluetooth bluray bonobo boost bzip2 cacert cairo caja calendar caps ccache cdb cdda cddb cdio cdparanoia cdr cgi chipcard chroot clang colord command-args corefonts cpudetection cpulimit cracklib cramfs crypt cscope css csv ctyp
e cue cups curl curlwrappers customlog cvs cvsgraph cxx cyrus dba dbi dbm dbus dbx devhelp device-mapper devmap dga dhcp dirac directfb djvu dlna dlopen dnsdb dri dri3 drm dts dv dvb dvd dvda dvdr dvi ecc egl elogind enchant encode eselec
t-ldso excel exif expat faad fam fastcgi fat fdk ffmpeg fftw fits flac flash flatfile fltk fontconfig fonts fpx ftp fuse fusefs gallium gd gdal gdbm gdu gegl geoclue geoip geos ggi gif gimp ginac git glib glpk glut gmp gnome-keyring gnupl
ot gpg gphoto2 graphviz gs gsf gsl gsm gssapi gstreamer gtk gtk2 gtk3 gudev gzip h323 hardened hardenedphp hddtemp hdf5 hdri highlight hpn html http hunspell hwdb iconv icq icu idea idled idn imagemagick imap imlib imlib2 inifile innodb i
nt64 introspection ios ipalias ipc ipod ipv6 iso jabber jack java javascript jbig jingle jit jpeg jpeg2k json kdrive kerberos keymap kmod kpathsea lame lapack latex lcms ldap lensfun less libass libcaca libcerf libcxx libnotify libsampler
ate libv4l libv4l2 libwww live llvm lm_sensors lmtp logrotate logwatch lua lz4 lzma lzo mad magic mathml matplotlib matroska mbox mcal md5sum memlimit mercurial metis mgetty mhash midi milter mime mimencode ming mmap mms mmx mmxext mng mp
3 mp4 mpeg mpir mplayer msn mtp multilib mumps musepack musicbrainz mysql mysqli nagios-dns nagios-game nagios-ntp nagios-ping nagios-ssh natspec ncurses net netboot netcdf netlink network network-uri networkmanager nfs nis nls nntp nptl 
nsplugin nss ntfs ntp oav ocaml ocamlopt ocatve ocr octave odbc offensive ogg openal opencl openexr opengl openh264 openmp openrc openssh openssl opus orc ortp osc oscar pam pam_chroot pam_console pam_timestamp pango parse-clocks pcf pci 
pcntl pcre pda pdf pdfkit pdflib perl pgo php pic plotutils png policykit portaudio posix postfix postgis postgres postproc postscript ppds procmail ps pulseaudio pwdb python qdbm qt5 quotas quvi radius raw rdesktop rdp readline recode re
iserfs rpc rrdtool rss rtmp ruby samba sample sasl scanner schroedinger scotch screen sendfile sensord session sftp sftplogging shaper shared sharedext shorten shout sieve simplexml slang slp smartcard smime smp sms smtp sna sndfile snmp 
snortsam soap sockets socks5 sound sox spamassassin sparse spatialite speex spell spice spl split-usr sql sqlite sqlite3 sse sse2 sse3 sse4 sse4_1 ssh ssl ssse3 stream subversion svg sysfs syslog sysvipc szip t1lib taglib tcpd telepathy t
est-programs theora threads tidy tiff timidity tokenizer tools transparent-proxy truetype truetype-fonts tslib twolame type1-fonts udev udisks unicode upnp upnp-av upower usb userlocales utf8 uuid v4l vaapi vala vcd vdpau vhosts video vim
-syntax virtual-users virus-scan vnc vorbis vpx vte wavpack wayland wddx weather webdav webkit webm webp wifi win32codecs withsamplescripts wmf x264 x265 xattr xcb xcomposite xetex xface xfs xft xinerama xinetd xml xml2 xmlrpc xmp xmpp xo
rg xosd xpdf-headers xpm xps xrandr xscreensaver xsl xslt xv xvfb xvid xvmc xz yahoo yaml yaz zeromq zlib zstd zvbi" ABI_X86="32 64" APACHE2_MODULES="access auth auth_basic auth_digest authn_default authn_core authn_file authn_dbm authn_d
bd authn_alias authn_anon authz_core authz_groupfile authz_host authz_user authz_dbd authz_dbm authz_owner authz_default dbd ident imagemap alias echo charset_lite cache file_cache disk_cache mem_cache ext_filter case_filter case-filter-i
n deflate filter mime_magic cern_meta proxy proxy_connect proxy_ftp http2 proxy_html proxy_http proxy_ajp proxy_balancer proxy_fcgi proxy_wstunnel expires headers usertrack info include cgi cgid dav dav_lock dav_fs vhost_alias speling rew
rite log_config logio env setenvif mime status substitute autoindex asis negotiation dir imap actions userdir so unique_id version dumpio log_forensic reqtimeout socache_shmcb unixd slotmem_shm ratelimit remoteip lbmethod_bybusyness lbmet
hod_byrequests lbmethod_bytraffic lbmethod_heartbeat xml2enc brotli watchdog" APACHE2_MPMS="worker" CPU_FLAGS_X86="aes avx mmx mmxext popcnt sse sse2 sse3 sse4_1 sse4_2 ssse3" CURL_SSL="openssl" ELIBC="glibc" FFTOOLS="cws2fws ffhash pktdu
mper sidxindex qt-faststart aviocat ismindex" GPSD_PROTOCOLS="aivdm sirf mtk3301 gpsclock superstar2 timing nmea" GRUB_PLATFORMS="pc multiboot efi coreboot efi-64" INPUT_DEVICES="keyboard mouse evdev wacom synaptics" KERNEL="linux" L10N="
en_GB en en_US de_DE de" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer nlpsolver pdfimport wiki-publisher scripting-beanshell" LLVM_TARGETS="X86 NVPTX" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php7-2 php7-3" POSTGR
ES_TARGETS="postgres11 postgres12" PYTHON_SINGLE_TARGET="python3_6" PYTHON_TARGETS="python2_7 python3_6" QEMU_SOFTMMU_TARGETS="i386 x86_64" QEMU_USER_TARGETS="i386 x86_64" RUBY_TARGETS="ruby24 ruby25" SANE_BACKENDS="net hp" USERLAND="GNU"
 VIDEO_CARDS="vga intel i915 i965 fbdev vesa" XFCE_PLUGINS="clock multiload-nandhp power trash"
Unset:  CC, CPPFLAGS, CTARGET, CXX, EMERGE_DEFAULT_OPTS, LC_ALL, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 1 Thomas Beutin 2019-11-15 14:34:53 UTC
Created attachment 596234 [details]
build.log (gzipped)
Comment 2 Benda Xu gentoo-dev 2019-11-16 02:20:33 UTC
I have pinned down the bug.

Please run:

`eselect blas add lib64 /usr/lib64/blas/reference reference`

manually.


@lumin, the upgrade path from sci-libs/blas-reference to sci-libs/lapack-3.8 is not smooth.  Somehow the above command in pkg_postinst() does not succeed leaving  no viable blas candidates.
Comment 3 Benda Xu gentoo-dev 2019-11-16 05:23:23 UTC
Uninstallation of sci-libs/blas-reference removes /etc/env.d/blas/lib64/reference, and uninstallation of sci-libs/lapack-reference removes /etc/env.d/lapack/lib64/reference. Unfortunately they are uninstalled after sci-libs/lapack is installed, and /etc/env.d/blas/lib64/reference is not in the package file list and is not protected.
Comment 4 Thomas Beutin 2020-01-06 13:13:04 UTC
(In reply to Benda Xu from comment #2)
> I have pinned down the bug.
> 
> Please run:
> 
> `eselect blas add lib64 /usr/lib64/blas/reference reference`
> 
> manually.

i did it, but it doesn't helps - the issue persists.
Comment 5 François Bissey 2020-01-06 19:49:36 UTC
I am more inclined to think there is a flaw in the build system. The run of cmake on the 64bit ABI arch finds /usr/lib64/liblapack.so, however the error is on a cblas symbol. I think libopencv_core.so.3.4.1 expect to be compiled with a lapack that includes cblas symbols as well.

[90/680] : && /usr/bin/x86_64-pc-linux-gnu-g++ -fPIC -march=sandybridge -fomit-frame-pointer -O2 -pipe   -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 -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -Wno-implicit-fallthrough -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -mssse3 -msse4.1 -mpopcnt -msse4.2 -mavx -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp  -Wl,-O1 -Wl,--as-needed -shared -Wl,-soname,libopencv_core.so.3.4 -o lib/libopencv_core.so.3.4.1 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/array.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/batch_distance.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/channels.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.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/convert.sse4_1.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/convert_c.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/convert_scale.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/copy.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/count_non_zero.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/cuda_gpu_mat.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/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.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_wrap.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/mean.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/merge.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_clamdblas.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/opencl/runtime/opencl_clamdfft.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_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.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/persistence_c.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/persistence_cpp.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.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.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/filesystem.cpp.o modules/core/CMakeFiles/opencv_core.dir/src/va_intel.cpp.o modules/core/CMakeFiles/opencv_core.dir/opencl_kernels_core.cpp.o  -ldl -lm -lpthread -lrt -lGL -lGLU /usr/lib64/libtbb.so -lz -lva -lva-drm -llapack -L/usr/lib64 && :

If -llapack doesn't provide cblas and lib/libopencv_core.so.3.4.1 does use cblas directly, then of course it is underlinked.
Using openblas instead of reference would probably fix the issue. A more general fix would be pass -lcblas as well.
Comment 6 François Bissey 2020-01-07 07:48:40 UTC
A deep look at cmake/OpenCVFindLAPACK.cmake in opencv's source shows that for mkl, openblas and accelerate they are actually after
* lapacke (headers)
* cblas (headers)
* lapack (libraries)
stuff. The compilation check for the libraries only look for lapack functions. opencv also seem to provide its alternate lapacke headers in any case. I don't know that lapacke is actually required. But cblas definitely is. cmake doesn't really have a FindCBLAS module, just BLAS and LAPACK.

My recommendation would be for the ebuild to pass
-DLAPACK_LIBRARIES="-llapack -lcblas" 
to cmake when lapack is required. Probably should add virtual/cblas to the dependencies as well.
Comment 7 Benda Xu gentoo-dev 2020-01-26 09:08:00 UTC
(In reply to Thomas Beutin from comment #4)
> (In reply to Benda Xu from comment #2)
> > I have pinned down the bug.
> > 
> > Please run:
> > 
> > `eselect blas add lib64 /usr/lib64/blas/reference reference`
> > 
> > manually.
> 
> i did it, but it doesn't helps - the issue persists.

How about reinstalling sci-libs/lapack?
Comment 8 Benda Xu gentoo-dev 2020-01-26 09:10:18 UTC
(In reply to François Bissey from comment #6)
> A deep look at cmake/OpenCVFindLAPACK.cmake in opencv's source shows that
> for mkl, openblas and accelerate they are actually after
> * lapacke (headers)
> * cblas (headers)
> * lapack (libraries)
> stuff. The compilation check for the libraries only look for lapack
> functions. opencv also seem to provide its alternate lapacke headers in any
> case. I don't know that lapacke is actually required. But cblas definitely
> is. cmake doesn't really have a FindCBLAS module, just BLAS and LAPACK.
> 
> My recommendation would be for the ebuild to pass
> -DLAPACK_LIBRARIES="-llapack -lcblas" 
> to cmake when lapack is required. Probably should add virtual/cblas to the
> dependencies as well.

I don't understand. Lapack is a fortran library. Why does it depend on a c library?
Comment 9 François Bissey 2020-01-26 09:27:58 UTC
Lapack is indeed a fortran library. There is also lapacke (notice the final "e") which a c interface to it or a c version. Lapack depends on blas which also has c version called cblas.

The point is, big libraries like openblas or MKL present one library that includes:
lapack
lapacke
blas
cblas
and sometimes more. All in one single library I repeat. The issue here is that opencv actually depends not only on lapack but on cblas. But it expect to get everything from one single library. And the *-reference libraries in Gentoo are definitely separate libraries.
Comment 10 François Bissey 2020-01-26 09:32:49 UTC
I was a bit hasty and may be not clear. opencv calls functions from both lapack and cblas so needs to be linked with both. opencv is actually in C so it just wraps lapack's fortran calls but it is using cblas directly.
Comment 11 Benda Xu gentoo-dev 2020-01-26 13:36:52 UTC
(In reply to François Bissey from comment #10)
> I was a bit hasty and may be not clear. opencv calls functions from both
> lapack and cblas so needs to be linked with both. opencv is actually in C so
> it just wraps lapack's fortran calls but it is using cblas directly.

Thanks François, that makes a lot of sense to me now.  It is not a bug of lapack we are providing.

Let's call opencv maintainer for help, hopefully adding cblas linking explicitly.
Comment 12 Jeroen Roovers (RETIRED) gentoo-dev 2020-09-23 05:02:08 UTC
*** Bug 741626 has been marked as a duplicate of this bug. ***
Comment 13 Jeroen Roovers (RETIRED) gentoo-dev 2020-09-23 05:02:17 UTC
*** Bug 701940 has been marked as a duplicate of this bug. ***
Comment 14 Larry the Git Cow gentoo-dev 2020-10-16 21:48:05 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=5c21b91ad2464439514aae406a0c0d5f310aca1d

commit 5c21b91ad2464439514aae406a0c0d5f310aca1d
Author:     Ross Charles Campbell <rossbridger.cc@gmail.com>
AuthorDate: 2020-10-14 02:17:02 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2020-10-16 21:47:50 +0000

    media-libs/opencv: version bump to 4.5.0
    
    Bug: https://bugs.gentoo.org/701790
    Bug: https://bugs.gentoo.org/700176
    Bug: https://bugs.gentoo.org/717812
    Bug: https://bugs.gentoo.org/703658
    Bug: https://bugs.gentoo.org/689838
    Closes: https://bugs.gentoo.org/666716
    Closes: https://bugs.gentoo.org/747163
    Closes: https://bugs.gentoo.org/729190
    Closes: https://bugs.gentoo.org/699730
    Closes: https://bugs.gentoo.org/672840
    Package-Manager: Portage-3.0.8, Repoman-3.0.1
    
    Signed-off-by: Ross Charles Campbell <rossbridger.cc@gmail.com>
    Closes: https://github.com/gentoo/gentoo/pull/17899
    Signed-off-by: Sam James <sam@gentoo.org>

 media-libs/opencv/Manifest            |   2 +
 media-libs/opencv/opencv-4.5.0.ebuild | 555 ++++++++++++++++++++++++++++++++++
 2 files changed, 557 insertions(+)
Comment 15 Maciej S. Szmigiero 2020-10-17 21:16:26 UTC
Still a thing in media-libs/opencv-4.5.0[lapack]:
[108/488] : && /usr/bin/x86_64-pc-linux-gnu-g++ -O3 -pipe -march=znver1   -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 -flto  -msse -msse2 -msse3 -mssse3 -msse4.1 -mpopcnt -msse4.2 -mf16c -mfma -mavx -mavx2 -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp -Wl,-O1 -Wl,--as-needed  -Wl,--gc-sections -Wl,--as-needed apps/version/CMakeFiles/opencv_version.dir/opencv_version.cpp.o -o bin/opencv_version  -ldl  -lm  -lpthread  -lrt  /usr/lib64/libGL.so  /usr/lib64/libGLU.so  lib/libopencv_core.so.4.5.0  -Wl,-rpath-link,"\$ORIGIN" && :
FAILED: bin/opencv_version 
: && /usr/bin/x86_64-pc-linux-gnu-g++ -O3 -pipe -march=znver1   -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 -flto  -msse -msse2 -msse3 -mssse3 -msse4.1 -mpopcnt -msse4.2 -mf16c -mfma -mavx -mavx2 -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp -Wl,-O1 -Wl,--as-needed  -Wl,--gc-sections -Wl,--as-needed apps/version/CMakeFiles/opencv_version.dir/opencv_version.cpp.o -o bin/opencv_version  -ldl  -lm  -lpthread  -lrt  /usr/lib64/libGL.so  /usr/lib64/libGLU.so  lib/libopencv_core.so.4.5.0  -Wl,-rpath-link,"\$ORIGIN" && :
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: lib/libopencv_core.so.4.5.0: undefined reference to `cblas_zgemm'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: lib/libopencv_core.so.4.5.0: undefined reference to `cblas_sgemm'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: lib/libopencv_core.so.4.5.0: undefined reference to `cblas_dgemm'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: lib/libopencv_core.so.4.5.0: undefined reference to `cblas_cgemm'
collect2: error: ld returned 1 exit status

This is with sci-libs/lapack-3.9.0 USE="lapacke -doc -eselect-ldso -test", currently the latest one in the tree.
Comment 16 François Bissey 2020-10-17 21:53:06 UTC
Nothing changed, still not using -cblas when linking. I suggested a work around during src_config in an earlier comment.
Comment 17 Ross Charles C. 2020-10-18 01:12:35 UTC
I didn't enable lapacke USE for lapack, and opencv compiles fine, but after I rebuilt lapack with that USE, I was able to reproduce the same error.
Comment 18 François Bissey 2020-10-18 01:20:44 UTC
That's an interesting comment. It suggests that some internal functions are used when a system lapacke is not found.
What does
eselect lapack show
say for you?
Comment 19 Ross Charles C. 2020-10-18 01:25:23 UTC
(In reply to François Bissey from comment #18)
> That's an interesting comment. It suggests that some internal functions are
> used when a system lapacke is not found.
> What does
> eselect lapack show
> say for you?

# eselect lapack show
!!! Error: Can't load module lapack
exiting
Comment 20 Maciej S. Szmigiero 2020-10-18 01:25:55 UTC
(In reply to François Bissey from comment #18)
> That's an interesting comment. It suggests that some internal functions are
> used when a system lapacke is not found.
> What does
> eselect lapack show
> say for you?

I'm running with USE="-eselect-ldso" (which is the default), so there is no lapack eselect module at all.
Comment 21 François Bissey 2020-10-18 01:32:52 UTC
OK, I didn't realise that. So just netlib lapack/cblas/blas/lapacke. Which are all in separate libraries and not one super library like openblas or mkl.
Comment 22 Ross Charles C. 2020-10-18 02:30:01 UTC
The situation is getting more elusive: it turns out opencv doesn't even link with lapack if lapacke USE is not enabled
Comment 23 François Bissey 2020-10-18 03:54:29 UTC
(In reply to Ross Charles C. from comment #22)
> The situation is getting more elusive: it turns out opencv doesn't even link
> with lapack if lapacke USE is not enabled

Not really, I suspected as much from Maciej's comments earlier. It looks like a case where the real dependency should be lapacke. And I suspect an internal copy is used if no external library is provided.
Comment 24 Ross Charles C. 2020-10-18 12:25:25 UTC
So as I see it, this bug contains two levels:

1. OpenCV requires a lapacke implementation (virtual/lapacke) or lapack support will be disabled implicitly by its cmake script.

2. Linking with cblas library is required when sci-libs/lapack is supplemented as the implementation for virtual/lapacke.
Comment 25 Ross Charles C. 2020-10-18 13:26:40 UTC
Correction: opencv probably doesn't actually use lapacke API per se, but it still detects the existence of lapacke.h or implicitly disables lapack support if it can't find one when sci-libs/lapack is supplemented as the lapack implementation.
Comment 26 Larry the Git Cow gentoo-dev 2020-11-03 07:18:36 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=c92eaa6a7d93400503334e9c65df2b8e400ab90f

commit c92eaa6a7d93400503334e9c65df2b8e400ab90f
Author:     Ross Charles Campbell <rossbridger.cc@gmail.com>
AuthorDate: 2020-10-18 14:59:46 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2020-11-03 07:18:26 +0000

    media-libs/opencv: various fixes
    
     - Explicitly depends on virtual/lapacke to prevent its cmake build scripts from
    implicitly disabling lapack support when it can't find lapacke.h.
    
     - Link with cblas when sci-libs/lapack is supplimented as the default lapack
    implementation.
    
     - examples USE requires contribdnn USE to be enabled to prevent build failure.
    
    Closes: https://bugs.gentoo.org/700176
    Closes: https://bugs.gentoo.org/749681
    Closes: https://bugs.gentoo.org/717812
    Closes: https://bugs.gentoo.org/701790
    Closes: https://bugs.gentoo.org/704518
    Package-Manager: Portage-3.0.8, Repoman-3.0.1
    Signed-off-by: Ross Charles Campbell <rossbridger.cc@gmail.com>
    Closes: https://github.com/gentoo/gentoo/pull/17964
    Signed-off-by: Sam James <sam@gentoo.org>

 .../opencv-4.5.0-link-with-cblas-for-lapack.patch      | 18 ++++++++++++++++++
 media-libs/opencv/opencv-4.5.0.ebuild                  |  8 +++++++-
 2 files changed, 25 insertions(+), 1 deletion(-)

Additionally, it has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=41748611705de3c85338e2bfc6c61aabf4aed2fb

commit 41748611705de3c85338e2bfc6c61aabf4aed2fb
Author:     Ross Charles Campbell <rossbridger.cc@gmail.com>
AuthorDate: 2020-10-18 14:45:00 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2020-11-03 07:18:26 +0000

    virtual/lapacke: add sci-libs/openblas as an alternative
    
    The current sci-libs/openblas versions come with an implementation
    for lapacke API, therefore adding it as a conditional dep for virtual/lapacke.
    
    Bug: https://bugs.gentoo.org/700176
    Bug: https://bugs.gentoo.org/749921
    Package-Manager: Portage-3.0.8, Repoman-3.0.1
    Signed-off-by: Ross Charles Campbell <rossbridger.cc@gmail.com>
    Signed-off-by: Sam James <sam@gentoo.org>

 virtual/lapacke/lapacke-3.8.ebuild | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)