Bug 237388 - net/kitinerary: Fails to link: libzxing.so: undefined reference to `cv::* (opencv symbols)
Summary: net/kitinerary: Fails to link: libzxing.so: undefined reference to `cv::* (op...
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: i386 Any
: --- Affects Only Me
Assignee: Yuri Victorovich
URL:
Keywords: regression
Depends on:
Blocks:
 
Reported: 2019-04-19 14:34 UTC by Martin Birgmeier
Modified: 2019-04-22 06:44 UTC (History)
3 users (show)

See Also:
tcberner: maintainer-feedback+


Attachments
make log when running "make" for the second time in ports/net/kitinerary (4.37 KB, text/plain)
2019-04-19 14:34 UTC, Martin Birgmeier
no flags Details
result of running "portmaster kitinerary-19.04.0 |& tee /tmp/portmaster.log" (131.87 KB, text/plain)
2019-04-20 17:45 UTC, Martin Birgmeier
no flags Details
Add USES=localbase:ldflags (530 bytes, patch)
2019-04-20 17:51 UTC, Yuri Victorovich
no flags Details | Diff
patch-CMakeLists.txt (1.29 KB, text/plain)
2019-04-21 02:05 UTC, Hiroo Ono
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Birgmeier 2019-04-19 14:34:17 UTC
Created attachment 203799 [details]
make log when running "make" for the second time in ports/net/kitinerary

Scenario:
- FreeBSD 12.0 pl 3 i386 running under VirtualBox (host FreeBSD 12.0 pl 3 amd64)
- x11/kde5 and many other ports installed
- updating from 18.12.3 to 19.04.0 using portmaster

Result:
- linking fails with the following error:

FAILED: bin/kitinerary-extractor 
: && /usr/bin/c++  -O2 -pipe -fstack-protector -fno-strict-aliasing -std=c++0x -
fno-operator-names -fno-exceptions -Wno-gnu-zero-variadic-macro-arguments -Wall -Wextra -Wcast-align -Wchar-subscripts -Wformat-security -Wno-long-long -Wpointer-arith -Wundef -Wnon-virtual-dtor -Woverloaded-virtual -Werror=return-type -Wvla -Wdate-time -fdiagnostics-color=always -pedantic -Wzero-as-null-pointer-constant -O2 -pipe -fstack-protector -fno-strict-aliasing  -Wl,--enable-new-dtags  -fstack-protector src/cli/CMakeFiles/kitinerary-extractor.dir/kitinerary-extractor_autogen/mocs_compilation.cpp.o src/cli/CMakeFiles/kitinerary-extractor.dir/main.cpp.o  -o bin/kitinerary-extractor  -Wl,-rpath,/usr/tmp/a/SRC/FreeBSD-ports/head/net/kitinerary/work/.build/bin:/usr/local/lib:/usr/local/lib/qt5: bin/libKPimItinerary.so.5.11.0 /usr/local/lib/libKPimPkPass.so.5.11.0 /usr/local/lib/libKF5Mime.so.5.11.0 /usr/local/lib/libKF5CalendarCore.so.5.11.0 /usr/local/lib/qt5/libQt5Gui.so.5.12.2 /usr/local/lib/qt5/libQt5Core.so.5.12.2 -Wl,-rpath-link,/usr/local/lib:/usr/local/lib/qt5 && :
/usr/local/lib/libzxing.so: undefined reference to `cv::fastFree(void*)'
/usr/local/lib/libzxing.so: undefined reference to `cv::Mat::copyTo(cv::_OutputArray const&) const'
/usr/local/lib/libzxing.so: undefined reference to `cv::Mat::deallocate()'
c++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
===> Compilation failed unexpectedly.
Try to set MAKE_JOBS_UNSAFE=yes and rebuild before reporting the failure to
the maintainer.
*** Error code 1

Stop.
make[1]: stopped in /a/SRC/FreeBSD-ports/head/net/kitinerary
*** Error code 1

Stop.
make: stopped in /a/SRC/FreeBSD-ports/head/net/kitinerary

Note:
- There was no such issue when upgrading the amd64 variant (in a VirtualBox VM running FreeBSD 12 pl 3 amd64)

-- Martin
Comment 1 Kubilay Kocak freebsd_committer freebsd_triage 2019-04-19 14:54:52 UTC
Thank you for the report Martin

Looks related to libzxing.so (via textproc/zxing-cpp, maintainer CC'd)
Comment 2 Yuri Victorovich freebsd_committer freebsd_triage 2019-04-19 15:56:30 UTC
textproc/zxing-cpp links with and has dependency on OpenCV:
> LIB_DEPENDS=    libopencv_core.so:graphics/opencv-core \
>                 libopencv_photo.so:graphics/opencv

Is is known what change triggered the problem?

I just updated textproc/zxing-cpp to the latest revision.
Comment 3 Martin Birgmeier 2019-04-19 16:03:56 UTC
For me the trigger was the update of KDE applications from 18.12.3 to 19.04.0.

The patch in zxing, textproc/zxing-cpp/files/patch-CMakeLists.txt, looks suspicious - why is it necessary if zxing support linking to opencv?

-- Martin
Comment 4 Yuri Victorovich freebsd_committer freebsd_triage 2019-04-19 16:28:52 UTC
Without this patch it fails to link with OpenCV:
> libzxing.so: undefined reference to `cv::Mat::deallocate()'



https://github.com/glassechidna/zxing-cpp/issues/84
Comment 5 Martin Birgmeier 2019-04-20 07:58:57 UTC
Maybe more is necessary for specifying the dependency on opencv so that zxing consumers can pick it up, too? I found https://docs.opencv.org/3.4.1/db/df5/tutorial_linux_gcc_cmake.html. Alas, I don't know cmake to be able to judge...

-- Martin
Comment 6 Martin Birgmeier 2019-04-20 10:31:13 UTC
Using the following patch I got it to work:

--- ./src/cli/CMakeLists.txt.ORIG       2019-04-08 13:52:31.000000000 +0200
+++ ./src/cli/CMakeLists.txt    2019-04-20 12:28:40.091467000 +0200
@@ -2,10 +2,12 @@
     return()
 endif()
 
+find_package( OpenCV REQUIRED )
 add_executable(kitinerary-extractor main.cpp)
 target_include_directories(kitinerary-extractor PRIVATE ${CMAKE_BINARY_DIR})
 target_link_libraries(kitinerary-extractor
     KPimItinerary
     KPim::PkPass
+    ${OpenCV_LIBS}
 )
 install(TARGETS kitinerary-extractor DESTINATION ${KF5_LIBEXEC_INSTALL_DIR})
Comment 7 Yuri Victorovich freebsd_committer freebsd_triage 2019-04-20 13:57:42 UTC
No, this fix is wrong.
The bug is in libzxing.so - it doesn't link with opencv.
Comment 8 commit-hook freebsd_committer freebsd_triage 2019-04-20 14:38:27 UTC
A commit references this bug:

Author: yuri
Date: Sat Apr 20 14:38:20 UTC 2019
New revision: 499444
URL: https://svnweb.freebsd.org/changeset/ports/499444

Log:
  textproc/zxing-cpp: Link OpenCV libs to the library

  Add the patch from the upstream pull request

  PR:		237388
  Reported by:	Martin Birgmeier <d8zNeCFG@aon.at>

Changes:
  head/textproc/zxing-cpp/Makefile
  head/textproc/zxing-cpp/distinfo
  head/textproc/zxing-cpp/files/patch-CMakeLists.txt
Comment 9 Yuri Victorovich freebsd_committer freebsd_triage 2019-04-20 14:38:47 UTC
Fix committed.
Thanks for reporting this problem!
Comment 10 Martin Birgmeier 2019-04-20 14:56:29 UTC
Thank you Yuri!

-- Martin
Comment 11 Yuri Victorovich freebsd_committer freebsd_triage 2019-04-20 15:06:19 UTC
(In reply to Martin Birgmeier from comment #10)

You are welcome!

Yuri
Comment 12 Martin Birgmeier 2019-04-20 16:17:47 UTC
There is still something problematic... now building kitinerary fails with

/usr/bin/ld: cannot find -lopencv_aruco
c++: error: linker command failed with exit code 1 (use -v to see invocation)
Comment 13 Martin Birgmeier 2019-04-20 16:20:35 UTC
On amd64 it now fails as well:

/usr/bin/ld: error: unable to find library -lopencv_aruco
/usr/bin/ld: error: unable to find library -lopencv_bgsegm
/usr/bin/ld: error: unable to find library -lopencv_bioinspired
/usr/bin/ld: error: unable to find library -lopencv_calib3d
/usr/bin/ld: error: unable to find library -lopencv_ccalib
/usr/bin/ld: error: unable to find library -lopencv_core
/usr/bin/ld: error: unable to find library -lopencv_datasets
/usr/bin/ld: error: unable to find library -lopencv_dnn
/usr/bin/ld: error: unable to find library -lopencv_dnn_modern
/usr/bin/ld: error: unable to find library -lopencv_dnn_objdetect
/usr/bin/ld: error: unable to find library -lopencv_dpm
/usr/bin/ld: error: unable to find library -lopencv_face
/usr/bin/ld: error: unable to find library -lopencv_features2d
/usr/bin/ld: error: unable to find library -lopencv_flann
/usr/bin/ld: error: unable to find library -lopencv_freetype
/usr/bin/ld: error: unable to find library -lopencv_fuzzy
/usr/bin/ld: error: unable to find library -lopencv_hdf
/usr/bin/ld: error: unable to find library -lopencv_hfs
/usr/bin/ld: error: unable to find library -lopencv_highgui
/usr/bin/ld: error: unable to find library -lopencv_img_hash
/usr/bin/ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
c++: error: linker command failed with exit code 1 (use -v to see invocation)
Comment 14 Yuri Victorovich freebsd_committer freebsd_triage 2019-04-20 16:34:25 UTC
reopening
Comment 15 Yuri Victorovich freebsd_committer freebsd_triage 2019-04-20 16:37:35 UTC
(In reply to Martin Birgmeier from comment #13)

Could you include the commands that cause this failure?
Comment 16 Martin Birgmeier 2019-04-20 17:26:06 UTC
As a first step, I ran "portmaster -a". Because I had updated recently, this resulted only in zxing being upgraded. From /var/log/messages:

Apr 20 18:11:00 v909 pkg-static[7195]: zxing-cpp-0.20190320 deinstalled
Apr 20 18:11:01 v909 pkg-static[7295]: zxing-cpp-0.20190320_1 installed

Then, knowing that kitinerary was a consumer of zxing, I ran "portmaster kitinerary-19.04.0". This started the recompilation of kitinerary, leading to errors on both i386 and amd64 (2 different VMs).

-- Martin
Comment 17 Yuri Victorovich freebsd_committer freebsd_triage 2019-04-20 17:34:11 UTC
I meant what is the command that fails with:
> /usr/bin/ld: error: unable to find library -lopencv_aruco
Comment 18 Martin Birgmeier 2019-04-20 17:45:38 UTC
Created attachment 203834 [details]
result of running "portmaster kitinerary-19.04.0 |& tee /tmp/portmaster.log"

Hi Yuri,

Please find the log file attached.

-- Martin
Comment 19 Martin Birgmeier 2019-04-20 17:47:41 UTC
This was from the run on amd64 btw.
Comment 20 Yuri Victorovich freebsd_committer freebsd_triage 2019-04-20 17:51:29 UTC
Created attachment 203835 [details]
Add USES=localbase:ldflags

Martin,

Could you please try and see if the attached patch fixes the problem?

Thanks,
Yuri
Comment 21 Yuri Victorovich freebsd_committer freebsd_triage 2019-04-20 18:02:38 UTC
Build failure in net/kitinerary should be handled by kde@.

The error happens to look much like the original error reported by Martin Birgmeier that I've fixed in textproc/zxing-cpp, but the cause now seemd to be different.
Comment 22 Martin Birgmeier 2019-04-20 18:07:52 UTC
Yes, this patch works (tested on both i386 and amd64).

It is strange however that this directory path is not recorded by the opencv dependency in zxing.

Thank you for the help!

-- Martin
Comment 23 Yuri Victorovich freebsd_committer freebsd_triage 2019-04-20 18:11:15 UTC
(In reply to Martin Birgmeier from comment #22)

This is something for kde@ to investigate: why don't cmake scripts get proper link paths from OpenCV. They can either investigate this, or just apply the attached patch.

Thank you for reporting the issue, Martin!


Yuri
Comment 24 Yuri Victorovich freebsd_committer freebsd_triage 2019-04-20 20:05:56 UTC
I think the real problem is still in zxing-cpp - due to wrong cmake scripts.
Comment 25 Hiroo Ono 2019-04-21 00:26:36 UTC
(In reply to Yuri Victorovich from comment #17)
opencv_aruco is a extra module in opencv_contrib. You need to enable EXTRA_MODULES option when building graphics/opencv.
Comment 26 Hiroo Ono 2019-04-21 00:30:53 UTC
(In reply to Hiroo Ono from comment #25)
Sorry. EXTRA_MODULES was default enabled. libopencv_aruco.so should exist.
Comment 27 Hiroo Ono 2019-04-21 01:39:05 UTC
ldd /usr/local/bin/zxing shows many opencv libraries, but from opencv-cli/src/main.cpp only core, imgproc, highgui is needed.
Also, ldd /usr/local/lib/libzxing.so shows no opencv libraries. It should link libopencv_core.so.
Apparently, the fix in upstream is not correct.
Comment 28 Hiroo Ono 2019-04-21 02:05:22 UTC
Created attachment 203850 [details]
patch-CMakeLists.txt

How about if you replaced textproc/zxing-cpp/files/patch-CMakeLists.txt with this file?
Comment 29 Yuri Victorovich freebsd_committer freebsd_triage 2019-04-21 02:13:11 UTC
(In reply to Hiroo Ono from comment #28)

Hi Hiroo,

The fix looks correct to me. The problem is that zxing-cpp links to OpenCV improperly.
It is causing user code to link to OpenCV when this is not necessary.
I will commit a fix later today.
I've already updated the upstream pull request: https://github.com/glassechidna/zxing-cpp/pull/86

Yuri
Comment 30 Yuri Victorovich freebsd_committer freebsd_triage 2019-04-21 16:18:08 UTC
(In reply to Hiroo Ono from comment #28)

I looked at the patch. This line:
> target_link_libraries(libzxing ${OpenCV_LIBS})
causes OpenCV libs to propagate into the installed cmake files. This causes all clients that link with libzxing to also link with OpenCV, which isn't necessary.
It needs the word PRIVATE in it. But I already have this in the updated pull request.


Thank you for your help,
Yuri
Comment 31 commit-hook freebsd_committer freebsd_triage 2019-04-21 21:12:01 UTC
A commit references this bug:

Author: yuri
Date: Sun Apr 21 21:11:36 UTC 2019
New revision: 499595
URL: https://svnweb.freebsd.org/changeset/ports/499595

Log:
  textproc/zxing-cpp: Patch to remove OpenCV libs from the installed cmake files

  net/kitinerary was broken because OpenCV libs were unnecessarily supplied to its build by
  cmake files from textproc/zxing-cpp. These OpenCV libs were missing -L/usr/local/lib for
  some reason, possiblt because OpenCV's cmake files provide LIBS without -L/usr/local/lib.

  PR:		237388
  Reported by:	Martin Birgmeier <d8zNeCFG@aon.at>

Changes:
  head/textproc/zxing-cpp/Makefile
  head/textproc/zxing-cpp/distinfo
Comment 32 Tobias C. Berner freebsd_committer freebsd_triage 2019-04-22 06:42:09 UTC
(In reply to commit-hook from comment #31)
Thanks for fixing this.
Comment 33 Yuri Victorovich freebsd_committer freebsd_triage 2019-04-22 06:44:19 UTC
(In reply to Tobias C. Berner from comment #32)

You're welcome.