Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 572836 - media-libs/opencv-3.1.0 - /usr/lib64/libtesseract.so.3: undefined reference to `clBuildProgram'
Summary: media-libs/opencv-3.1.0 - /usr/lib64/libtesseract.so.3: undefined reference t...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Library (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Amy Liffey
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 566920
  Show dependency tree
 
Reported: 2016-01-25 07:56 UTC by Juergen Rose
Modified: 2016-11-14 16:08 UTC (History)
8 users (show)

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


Attachments
build.log (build.log,836.17 KB, text/plain)
2016-01-25 07:56 UTC, Juergen Rose
Details
opencv-tesseract.patch (opencv-tesseract.patch,4.69 KB, patch)
2016-06-22 16:41 UTC, Adrian
Details | Diff
tesseract-3.04.00-fix-link-with-opencl.patch (tesseract-3.04.00-fix-link-with-opencl.patch,455 bytes, patch)
2016-06-23 10:21 UTC, Adrian
Details | Diff
opencv-tesseract-test.patch (opencv-tesseract-test.patch,2.54 KB, patch)
2016-06-23 10:26 UTC, Adrian
Details | Diff
opencv_contrib-3.1.0-tesseract-opencl-test.patch (opencv_contrib-3.1.0-tesseract-opencl-test.patch,840 bytes, patch)
2016-06-23 10:29 UTC, Adrian
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Juergen Rose 2016-01-25 07:56:29 UTC
Created attachment 423854 [details]
build.log

'MAKEOPTS=-j1 emerge -v1 opencv' fails with:
...
cd /var/tmp/portage/media-libs/opencv-3.1.0/work/opencv-3.1.0_build/modules/text && /usr/bin/cmake -E cmake_link_script CMakeFiles/example_text_cropped_word_recognition.dir/link.txt --verbose=1
/usr/bin/x86_64-pc-linux-gnu-g++   -march=amdfam10 -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 -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp   -Wl,-O1 -Wl,--as-needed  CMakeFiles/example_text_cropped_word_recognition.dir/samples/cropped_word_recognition.cpp.o  -o ../../bin/example_text_cropped_word_recognition -rdynamic ../../lib/libopencv_text.so.3.1.0 ../../lib/libopencv_features2d.so.3.1.0 ../../lib/libopencv_highgui.so.3.1.0 ../../lib/libopencv_flann.so.3.1.0 ../../lib/libopencv_ml.so.3.1.0 ../../lib/libopencv_videoio.so.3.1.0 ../../lib/libopencv_imgcodecs.so.3.1.0 ../../lib/libopencv_imgproc.so.3.1.0 ../../lib/libopencv_core.so.3.1.0 
/usr/lib64/libtesseract.so.3: undefined reference to `clBuildProgram'
/usr/lib64/libtesseract.so.3: undefined reference to `clEnqueueNDRangeKernel'
...
/usr/lib64/libtesseract.so.3: undefined reference to `clCreateBuffer'
/usr/lib64/libtesseract.so.3: undefined reference to `clCreateProgramWithSource'
collect2: error: ld returned 1 exit status
modules/text/CMakeFiles/example_text_cropped_word_recognition.dir/build.make:103: recipe for target 'bin/example_text_cropped_word_recognition' failed






root@caiman:/root(35)# emerge --info '=media-libs/opencv-3.1.0::gentoo'
Portage 2.2.27 (python 3.4.3-final-0, default/linux/amd64/13.0, gcc-5.3.0, glibc-2.22-r1, 4.4.0-gentoo x86_64)
=================================================================
                         System Settings
=================================================================
System uname: Linux-4.4.0-gentoo-x86_64-AMD_Phenom-tm-_II_X6_1090T_Processor-with-gentoo-2.2
KiB Mem:    16177080 total,   2184780 free
KiB Swap:  100663280 total, 100609472 free
Timestamp of repository gentoo: Mon, 25 Jan 2016 03:00:01 +0000
sh bash 4.3_p42-r1
ld GNU ld (Gentoo 2.25.1 p1.1) 2.25.1
app-shells/bash:          4.3_p42-r1::gentoo
dev-java/java-config:     2.2.0::gentoo
dev-lang/perl:            5.22.1::gentoo
dev-lang/python:          2.7.11-r2::gentoo, 3.4.3-r7::gentoo, 3.5.1-r2::gentoo
dev-util/cmake:           3.4.2::gentoo
dev-util/pkgconfig:       0.29::gentoo
sys-apps/baselayout:      2.2::gentoo
sys-apps/openrc:          0.20.4::gentoo
sys-apps/sandbox:         2.10-r1::gentoo
sys-devel/autoconf:       2.13::gentoo, 2.69-r1::gentoo
sys-devel/automake:       1.11.6-r2::gentoo, 1.12.6-r1::gentoo, 1.13.4-r1::gentoo, 1.14.1-r1::gentoo, 1.15-r1::gentoo
sys-devel/binutils:       2.25.1-r1::gentoo
sys-devel/gcc:            5.3.0::gentoo
sys-devel/gcc-config:     1.8::gentoo
sys-devel/libtool:        2.4.6-r1::gentoo
sys-devel/make:           4.1-r1::gentoo
sys-kernel/linux-headers: 4.4::gentoo (virtual/os-headers)
sys-libs/glibc:           2.22-r1::gentoo
Repositories:

gentoo
    location: /usr/portage_caiman
    sync-type: rsync
    sync-uri: rsync://rsync.gentoo.org/gentoo-portage
    priority: -1000

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

g-cpan
    location: /var/lib/cpan
    masters: gentoo
    priority: 1

g-octave
    location: /var/lib/g-octave
    masters: gentoo
    priority: 2

sage-on-gentoo
    location: /var/lib/layman/sage-on-gentoo
    masters: gentoo science
    priority: 50

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

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

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

ACCEPT_KEYWORDS="amd64 ~amd64"
ACCEPT_LICENSE="* -@EULA PUEL Intel-SDP dlj-1.1 skype-eula skype-4.0.0.7-copyright googleearth AdobeFlash-11.x cadsoft Oracle-BCLA-JavaSE MakeMKV-EULA NVIDIA-CUDA Nero-AAC-EULA GIMPS"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=amdfam10 -O2 -pipe"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/lib64/libreoffice/program/sofficerc /usr/share/config /usr/share/gnupg/qualified.txt /var/lib/hsqldb"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/php/apache2-php7.0/ext-active/ /etc/php/cgi-php7.0/ext-active/ /etc/php/cli-php7.0/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"
CXXFLAGS="-march=amdfam10 -O2 -pipe"
DISTDIR="/usr/portage/distfiles"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-logs config-protect-if-modified distlocks ebuild-locks fixlafiles merge-sync news parallel-fetch preserve-libs 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"
LANG="en_US.UTF-8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j7"
PKGDIR="/usr/portage/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=/.git"
PORTAGE_TMPDIR="/var/tmp"
USE="3dnow 3dnowext 64bit R X Xaw3d a52 aac acl acpi admin afs alsa amd64 amr ao apache2 apng applet archive armadillo arpack asf aspell assistant atlas audacious audiofile automap automount bash-completion berkdb blas blast bluetooth bluray boost bzip2 cairo cdda cddb cdf cdio cdparanoia cdr cgi chm cilk cli cmake collada cracklib crypt css cups curl cxx daap db dbi dbm dbus declarative designer devhelp device-mapper dga dia dirac djvu doc dot dri ds2490 ds9097 ds9097u dts dv dvb dvd dvdr dvi dynamicplugin eds egl elf emacs emboss emf encode epiphany evo examples excel exif expat extensions extra extras faac faad fam ffmpeg fftw firefox fits flac fltk fontconfig foomaticdb fortran fortran95 fpm fpx ftp fuse gcj gd gdal gdbm gdu gedit geoip geolocation geos gfortran gif gimp git glade glib glpk gml gmp gnome gnome-keyring gnuplot gnutls gold gphoto2 gpm grammar graphics graphtft graphviz grass gsl gsm gstreamer gtk gtk3 gudev guile hddtemp hdf hdf5 hdri html http httpd hvm hwdb iconv icq icu id3tag ide imagemagick imap inotify introspection ipod ipv6 irda ithreads jadetex java jbig jit john jpeg jpeg2k kate kdepim kdrive kerberos keymap kpathsea kvm ladspa lame lapack latex lcms ldap lensfun libffi libgda libkms libnotify libsamplerate live lm_sensors lua lzma lzo mad mail maildir mapnik math matroska media-library mercurial mikmod mkl mmx mmxext mng mod modules mono motif mozilla mp3 mp4 mpeg mpi mpi-threads mplayer mtp multilib multimedia musepack musicbrainz mysql mysqli nautilus ncurses netcdf netpbm network networking nfs nls nntp nptl nsplugin ntfs ntp numpy obex objc ocaml ocr octave odbc ofa ogdi ogg opencl opencv openexr opengl openmp openvg pam pango pcre pda pdf pdl2 perl plasma plotutils plugins png podcast policykit portaudio posix postgres postscript ppds preview-latex proj projectm pstricks pulseaudio python q16 q32 qemu qhull qt3support qt4 qt5 quicktime raw readline reiserfs reports rle romio rpc rrdcgi rrdtool sage samba sasl schroedinger science sdk sdl seccomp secure-delete semantic-desktop server session shout sip slang slp smart smbclient smp sms sndfile snmp soap sockets sound soup sox speex spell sql sqlite sse sse2 sse4a ssl stlport subtitles subversion sudo suexec svg svm swig systemd szip t1lib tbb tcl tcpd tex tex4ht texmacs theora thesaurus threads thunderbird tidy tiff tk toolbar tools truetype udev udisks unicode usb utempter v4l v4l2 vaapi vala valgrind vdpau video virt-network virtualbox visio vorbis vpx vtk wav wayland webdav webdav-serf webkit wmf wxwidgets x264 xa xattr xcb xetex xext xft xine xml xmlreader xmlrpc xpm xv xvid xvmc yaml youtube zlib zvbi" ABI_X86="64" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" APACHE2_MODULES="actions alias auth_basic auth_digest authn_anon authn_dbd authn_core authn_dbm authn_default authn_file authz_core authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgid dav dav_fs dav_lock dbd deflate dir disk_cache env expires ext_filter file_cache filter headers ident imagemap include info lbmethod_byrequests log_config logio mem_cache mime mime_magic negotiation proxy proxy_ajp proxy_balancer proxy_connect proxy_http rewrite setenvif slotmem_shm so socache_shmcb speling status unique_id unixd userdir usertrack vhost_alias" APACHE2_MPMS="worker" CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump author" CAMERAS="canon fuji ptp2" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="3dnow 3dnowext mmx mmxext popcnt sse sse2 sse3 sse4a" CURL_SSL="nss" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ublox ubx" INPUT_DEVICES="keyboard mouse evdev void" KERNEL="linux" LCD_DEVICES="cfontz hd44780 mtxorb ncurses X lcd2usb lcdlinux png usblcd SureElec" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LINGUAS="de en fr ru" NETBEANS_MODULES="apisupport cnd dlight enterprise ergonomics groovy gsf harness ide identity j2ee java mobility nb php profiler websvccommon xml" OFFICE_IMPLEMENTATION="libreoffice" PYTHON_SINGLE_TARGET="python2_7" PYTHON_TARGETS="python2_7 python3_4" QEMU_SOFTMMU_TARGETS="arm i386 x86_64" QEMU_USER_TARGETS="arm i386 x86_64" RUBY_TARGETS="ruby20 ruby21" USERLAND="GNU" VIDEO_CARDS="radeon displaylink" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CC, CPPFLAGS, CTARGET, CXX, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, USE_PYTHON




root@caiman:/root(36)# emerge -pqv '=media-libs/opencv-3.1.0::gentoo'
[ebuild     U ] media-libs/opencv-3.1.0 [3.0.0] USE="contrib doc eigen examples ffmpeg gdal%* gphoto2%* gstreamer gtk java jpeg jpeg2k opencl openexr opengl openmp png python qt5 threads tiff v4l vaapi%* vtk xine -cuda -ieee1394 (-ipp) -libav -pch -qt4 -testprograms -webp%" PYTHON_SINGLE_TARGET="python2_7 -python3_3 -python3_4" PYTHON_TARGETS="python2_7 python3_4 -python3_3"
Comment 1 Göktürk Yüksek archtester gentoo-dev 2016-01-25 18:59:12 UTC
Can you double check that app-text/tesseract is compiled with the "opencl" USE flag?
Comment 2 Juergen Rose 2016-01-26 08:11:44 UTC
(In reply to Gokturk Yuksek from comment #1)
> Can you double check that app-text/tesseract is compiled with the "opencl"
> USE flag?


tesseract was compiled with the opencl USE flag and I compiled it just once more:

root@caiman:/root(31)# date
Tue Jan 26 08:18:43 CET 2016
root@caiman:/root(32)# emerge -pvD tesseract

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R    ] app-text/tesseract-3.04.00-r3::gentoo  USE="doc examples jpeg math opencl png scrollview tiff -osd -static-libs -training -webp" LINGUAS="de fr ru -ar -bg -ca -chr -cs -da -el -es -fi -he -hi -hu -id -it -jp -ko -lt -lv -nl -no -pl -pt -ro -sk -sl -sr -sv -th -tl -tr -uk -vi -zh_CN -zh_TW" 0 KiB

Total: 1 package (1 reinstall), Size of downloads: 0 KiB
root@caiman:/root(33)# emerge -v1 tesseract
...
>>> Original instance of package unmerged safely.
>>> app-text/tesseract-3.04.00-r3 merged.
>>> Regenerating /etc/ld.so.cache...
>>> Auto-cleaning packages...

>>> No outdated packages were found on your system.
...
root@caiman:/root(35)# MAKEOPTS=-j1 emerge -v1 opencv

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild     U  ] media-libs/opencv-3.1.0:0/3.0::gentoo [3.0.0:0/3.0::x-portage] USE="contrib doc eigen examples ffmpeg gdal%* gphoto2%* gstreamer gtk java jpeg jpeg2k opencl openexr opengl openmp png python qt5 threads tiff v4l vaapi%* vtk xine -cuda -ieee1394 (-ipp) -libav -pch -qt4 -testprograms -webp%" PYTHON_SINGLE_TARGET="python2_7 -python3_3 -python3_4" PYTHON_TARGETS="python2_7 python3_4 -python3_3" 0 KiB
...
/usr/bin/x86_64-pc-linux-gnu-g++   -march=amdfam10 -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 -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp   -Wl,-O1 -Wl,--as-needed  CMakeFiles/example_text_cropped_word_recognition.dir/samples/cropped_word_recognition.cpp.o  -o ../../bin/example_text_cropped_word_recognition -rdynamic ../../lib/libopencv_text.so.3.1.0 ../../lib/libopencv_features2d.so.3.1.0 ../../lib/libopencv_highgui.so.3.1.0 ../../lib/libopencv_flann.so.3.1.0 ../../lib/libopencv_ml.so.3.1.0 ../../lib/libopencv_videoio.so.3.1.0 ../../lib/libopencv_imgcodecs.so.3.1.0 ../../lib/libopencv_imgproc.so.3.1.0 ../../lib/libopencv_core.so.3.1.0 
/usr/lib64/libtesseract.so.3: undefined reference to `clBuildProgram'
...



The only packages, where I removed the opencl USE flag, is hwloc:

root@caiman:/root(36)# grep opencl /etc/portage/package.use
sys-apps/hwloc -opencl
>=virtual/opencl-0-r4 abi_x86_32
root@caiman:/root(37)#
Comment 3 Juergen Rose 2016-01-26 09:28:15 UTC
BTW., mesa is selected as OpenCL implementation, ati-drivers are not installed:

root@caiman:/root(42)# eselect opencl list
Available OpenCL implementations:
  [1]   mesa *

root@caiman:/root(43)# USE=opencl emerge -v1 hwloc

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild     UD ] x11-base/xorg-server-1.17.4:0/1.17.4::gentoo [1.18.0:0/1.18.0::gentoo] USE="doc glamor ipv6 kdrive nptl%* suid systemd udev wayland xorg xvfb -dmx -libressl -minimal (-selinux) -static-libs -tslib -unwind -xephyr -xnest" 0 KiB
[ebuild  N     ] x11-drivers/ati-drivers-15.12-r1:1::gentoo  USE="modules qt4 -debug -gdm-hack -pax_kernel -static-libs" ABI_X86="32 (64)" 181,617 KiB
[ebuild   R    ] sys-apps/hwloc-1.10.1-r1:0/5::gentoo  USE="X cairo numa opencl* pci plugins svg xml -cuda -debug -gl -static-libs" ABI_X86="(64) -32 (-x32)" 0 KiB

Total: 3 packages (1 downgrade, 1 new, 1 reinstall), Size of downloads: 181,617 KiB

!!! Multiple package instances within a single package slot have been pulled
!!! into the dependency graph, resulting in a slot conflict:

x11-base/xorg-server:0

  (x11-base/xorg-server-1.17.4:0/1.17.4::gentoo, ebuild scheduled for merge) pulled in by
    <=x11-base/xorg-server-1.17.49[-minimal] required by (x11-drivers/ati-drivers-15.12-r1:1/1::gentoo, ebuild scheduled for merge)
    ^^                     ^^^^^^^
  (x11-base/xorg-server-1.18.0:0/1.18.0::gentoo, installed) pulled in by
    x11-base/xorg-server:0/1.18.0= required by (x11-drivers/xf86-video-ati-7.6.1:0/0::gentoo, installed)
                        ^^^^^^^^^^
    >=x11-base/xorg-server-1.18[udev] required by (x11-drivers/xf86-input-evdev-2.10.1:0/0::gentoo, installed)
    ^^                     ^^^^
    (and 4 more with the same problems)


I would like to avoid the installation of ati-drivers. Is it possible to have a working gentoo installation with opencl and without ati-drivers?
Comment 4 Juergen Rose 2016-01-31 14:48:29 UTC
Even 'USE=-opencl MAKEOPTS=-j1 emerge -v1 opencv' fails with the same error.
Should there not be any reference to a mesa library in the failing linker call:

/usr/bin/x86_64-pc-linux-gnu-g++   -march=amdfam10 -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 -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp   -Wl,-O1 -Wl,--as-needed  CMakeFiles/example_text_cropped_word_recognition.dir/samples/cropped_word_recognition.cpp.o  -o ../../bin/example_text_cropped_word_recognition -rdynamic ../../lib/libopencv_text.so.3.1.0 ../../lib/libopencv_features2d.so.3.1.0 ../../lib/libopencv_highgui.so.3.1.0 ../../lib/libopencv_flann.so.3.1.0 ../../lib/libopencv_ml.so.3.1.0 ../../lib/libopencv_videoio.so.3.1.0 ../../lib/libopencv_imgcodecs.so.3.1.0 ../../lib/libopencv_imgproc.so.3.1.0 ../../lib/libopencv_core.so.3.1.0 ?
Comment 5 Juergen Rose 2016-01-31 19:00:57 UTC
After emerging tesseract with -opencl I was able to emerge opencv-3.1.0 with -opencl, too.
Comment 6 Juergen Rose 2016-02-03 09:58:18 UTC
The same happens with the new tesseract-3.04.00-r4 and opencv-3.1.0-r1. If tesseract is compiled with the opencl USE flag, 'emerge -v1 opencv' fails with:
/usr/lib64/libtesseract.so.3: undefined reference to `clBuildProgram'.
This happens if the opencl USE flag is set for opencv and if the opencl USE flag is not set for opencv.

If tesseract is compiled without the opencl USE flag, 'emerge -v1 opencv' works independent of the state of opencl USE flag for opencv.
Comment 7 Amy Liffey gentoo-dev 2016-02-03 10:36:23 UTC
(In reply to Juergen Rose from comment #6)
> The same happens with the new tesseract-3.04.00-r4 and opencv-3.1.0-r1. If
> tesseract is compiled with the opencl USE flag, 'emerge -v1 opencv' fails
> with:
> /usr/lib64/libtesseract.so.3: undefined reference to `clBuildProgram'.
> This happens if the opencl USE flag is set for opencv and if the opencl USE
> flag is not set for opencv.
> 
> If tesseract is compiled without the opencl USE flag, 'emerge -v1 opencv'
> works independent of the state of opencl USE flag for opencv.

I am trying to reproduce it. Trying to find out whats happening.
Comment 8 Adrian 2016-06-21 01:06:01 UTC
I am able to reproduce this on my system with
1) eselect opencl mesa
2) emerge tesseract with opencl
3) emerge opencv without opencl or cuda

It only occurs with opencv >= 3.0.0
It does not occur with when opencv has either cuda or opencl enabled

I think the issue may be resolved by preventing autodetection of tesseract at compile time. I plan to add a tesseract use flag which will allow the opencv to explicitly depend on opencl or cuda if tesseract is compiled with opencl.
Comment 9 Adrian 2016-06-21 14:22:03 UTC
It is also necessary to build opencv with the contrib use flag in order for it to fail.
Comment 10 Amy Liffey gentoo-dev 2016-06-21 14:43:54 UTC
(In reply to Adrian from comment #9)
> It is also necessary to build opencv with the contrib use flag in order for
> it to fail.

Yes as I told you all of those bugs are contrib bugs meaning they are in opencv_contrib.
Comment 11 Adrian 2016-06-22 16:41:27 UTC
Created attachment 438450 [details, diff]
opencv-tesseract.patch

Here is a first attempt at a patch to resolve this bug.

It adds a tesseract USE flag to enable tesseract-ocr support. If tesseract is disabled then the contrib/modules/text will be compiled without tesseract. If tesseract is enabled, app-text/tesseract becomes a dependency. If tesseract was compiled with opencl support, then at least one of cuda or opencl must be enabled for opencv (I test for the converse). This provides /usr/lib/libOpenCL via eselect which has the clBuildProgram... functions to prevent this bug from occurring.

It was necessary to prevent the ebuild from disabling cuda and then continuing to build if gcc>4.8 were used. If I build tesseract with opencl and opencv built with cuda but not opencl, the previous code lead to a disconnect between the cuda USE flag (enabled) and the WITH_CUDA parameter (turned off).

The ebuild test for cuda/opencl support passes when it should fail, as it finds the cuda USE flag set for opencv even though it will soon be disabled. When cuda is disabled the WITH_CUDA parameter is turned off and the patch for FindTesseract.cmake does not link with the required libOpenCL. To fix this I call die if opencv is called with cuda enabled and gcc>4.8.

Thoughts:
The root cause of this bug is that libtesseract.so.3 has undefined symbols for the dynamic links to functions provided by libOpenCL. So any package in the tree which links to tesseract may suffer from this bug. Rather than making the changes to each package individually should a change be made the way app-text/tesseract links to libOpenCL instead to ensure the symbols are defined? Or does this defeat the purpose of dynamic linking and prevent eselect opencl from swapping out the opencl implementations without recompiling everything?
Comment 12 Amy Liffey gentoo-dev 2016-06-22 17:17:10 UTC
(In reply to Adrian from comment #11)
> Created attachment 438450 [details, diff] [details, diff]
> opencv-tesseract.patch
> 
> Here is a first attempt at a patch to resolve this bug.
> 
> It adds a tesseract USE flag to enable tesseract-ocr support. If tesseract
> is disabled then the contrib/modules/text will be compiled without
> tesseract. If tesseract is enabled, app-text/tesseract becomes a dependency.
> If tesseract was compiled with opencl support, then at least one of cuda or
> opencl must be enabled for opencv (I test for the converse). This provides
> /usr/lib/libOpenCL via eselect which has the clBuildProgram... functions to
> prevent this bug from occurring.
> 
> It was necessary to prevent the ebuild from disabling cuda and then
> continuing to build if gcc>4.8 were used. If I build tesseract with opencl
> and opencv built with cuda but not opencl, the previous code lead to a
> disconnect between the cuda USE flag (enabled) and the WITH_CUDA parameter
> (turned off).
> 
> The ebuild test for cuda/opencl support passes when it should fail, as it
> finds the cuda USE flag set for opencv even though it will soon be disabled.
> When cuda is disabled the WITH_CUDA parameter is turned off and the patch
> for FindTesseract.cmake does not link with the required libOpenCL. To fix
> this I call die if opencv is called with cuda enabled and gcc>4.8.
> 
> Thoughts:
> The root cause of this bug is that libtesseract.so.3 has undefined symbols
> for the dynamic links to functions provided by libOpenCL. So any package in
> the tree which links to tesseract may suffer from this bug. Rather than
> making the changes to each package individually should a change be made the
> way app-text/tesseract links to libOpenCL instead to ensure the symbols are
> defined? Or does this defeat the purpose of dynamic linking and prevent
> eselect opencl from swapping out the opencl implementations without
> recompiling everything?
		
I will look at it but from first view I am not very fond of this line:
!opencl? ( !cuda? ( app-text/tesseract[-opencl] ) )
Comment 13 Adrian 2016-06-23 10:21:52 UTC
Created attachment 438512 [details, diff]
tesseract-3.04.00-fix-link-with-opencl.patch

Regarding my thought above I have tried patching tesseract to encourage it to link directly to /usr/lib/libOpenCL.

Unfortunately this has the side effect that using eselect opencl to set a different opencl implementation causes build failures. The linker looks for the clBuildProgram_OPENCL_1_0 functions from the implementation in use when tesseract was compiled.

Otherwise this would have greatly simplified the ebuild logic:
- The RDEPEND simplifies to tesseract? ( app-text/tesseract )
- The patch to the CMakeLists.txt just handles the use flag, the code to find and link libOpenCL is not required.
- The gcc-4.9+ logic from the previous ebuild can still be used.
Comment 14 Adrian 2016-06-23 10:26:13 UTC
Created attachment 438514 [details, diff]
opencv-tesseract-test.patch

Unfortunately from my testing above this patch does not work if eselect opencv is used to change the opencl implementation (eg nvidia to mesa) without recompiling tesseract.

It is much simpler than my previous patch, however.
Comment 15 Adrian 2016-06-23 10:29:32 UTC
Created attachment 438516 [details, diff]
opencv_contrib-3.1.0-tesseract-opencl-test.patch

This is the simplified version of the patch to the CMakeLists.txt for my test above. As noted, it does not work after when opencv implementation is changed without recompiling tesseract.
Comment 16 Adrian 2016-06-23 10:43:33 UTC
I have been trying to find another way to get rid of the 
!opencl? ( !cuda? ( app-text/tesseract[-opencl] ) )

Patches to tesseract itself do not work after eselect is used to change the opencl implementation. This means that tesseract will have undefined dynamically linked functions and that linking to tesseract will fail unless /usr/lib64/libOpenCL.so is linked in as well.

If tesseract is built with opencl, linking with libOpenCL is required when we build opencv with tesseract and either cuda or opencl set.

So I still can't find another way to get rid of that line. Perhaps it looks clearer to write:

tesseract? (
  opencl? ( app-text/tesseract[opencl] )
  cuda? ( app-text/tesseract[opencl] )
  !opencl? ( !cuda? ( app-text/tesseract[-opencl] ) )
)

or

tesseract? (
  opencl? ( app-text/tesseract[opencl] )
  !opencl? (
    cuda? ( app-text/tesseract[opencl] )
    !cuda? ( app-text/tesseract[-opencl] )
  )
)
Comment 17 Adrian 2016-06-23 19:24:13 UTC
The code patch to the contrib directory fails if the use flag contrib is not enabled. It needs to be enclosed in an if clause.
Comment 18 Jonathan Scruggs (RETIRED) gentoo-dev 2016-11-04 15:27:11 UTC
Hey all. I'm hoping I have this fixed in the newest revision. If someone could test this before committing it to portage, that'd be great. You'll need to grab it from here:
https://github.com/dracwyrm/gentoo-ebuilds/tree/master/media-libs/opencv

Thanks.
Comment 19 Jonathan Scruggs (RETIRED) gentoo-dev 2016-11-11 10:47:46 UTC
Is this fixed with OpenCV 3.1.0-r6? I can't test the CUDA aspect of it, but I was able to test the OpenCL part. Please report back here whether or not this is working.

Thanks.
Comment 20 Jonathan Scruggs (RETIRED) gentoo-dev 2016-11-14 16:08:58 UTC
No response, so closing this as resolved. If not, please ask for the bug to be reopened.