Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg-config is broken in OpenCV-2.4.0 #4359

Closed
opencv-pushbot opened this issue Jul 27, 2015 · 9 comments
Closed

pkg-config is broken in OpenCV-2.4.0 #4359

opencv-pushbot opened this issue Jul 27, 2015 · 9 comments

Comments

@opencv-pushbot
Copy link
Contributor

Transferred from http://code.opencv.org/issues/1925

|| Hiromasa YOSHIMOTO on 2012-05-12 09:24
|| Priority: Normal
|| Affected: 2.4.0 - 2.4.8
|| Category: build/install
|| Tracker: Bug
|| Difficulty: 
|| PR: 
|| Platform: Any / Linux

pkg-config is broken in OpenCV-2.4.0

OpenCV-2.4.0 has a regression bug in pkg-config support.

The following pkg-config commands return wrong information now.
- "pkg-config opencv --libs"
  It returns just filename list of libraries. It must use "-L" and "-l" linker flags.
- "pkg-config opencv --libs-only-L"
- "pkg-config opencv --libs-only-l"
  no output returned.

I wrote a patch to fix this issue. Please find the attachment.

History

Andrey Kamaev on 2012-05-12 12:18
Thanks for the patch but it introduces another regression - versioned opencv-2.4.0.pc becomes completely broken.

Could you point to any pkg-config documentation saying that it *must* use "-L" and "-l" linker flags?
-   Target version deleted (2.4.1)
-   Assignee changed from Alexander Shishkov to Andrey Kamaev
Hordur Johannsson on 2012-05-12 15:30
I looked at the pkg-config website (http://people.freedesktop.org/~dbn/pkg-config-guide.html) and they say that Libs: should contain the linker flags.
In the case of gcc the full shared library paths work, e.g

  gcc myapp.cpp -o myapp `pkg-config opencv --libs`

works fine when compiling with gcc, now I'm not sure if that would break with other compilers.

I most often use cmake for my build system. Then I can use the FindPkgConfig to find OpenCV,
it will set OpenCV_LDFLAGS to the shared libraries. Here is in example how you might use that.

  find_package(PkgConfig REQUIRED)
pkg_check_modules(OpenCV opencv)
include_directories(${OpenCV_INCLUDE_DIRS})  
add_executable(myapp myapp.cpp)
target_link_libraries(myapp ${OpenCV_LDFLAGS})
Hiromasa YOSHIMOTO on 2012-05-13 07:10
Thanks for your comments. I'll fix my patch later.

I mean that the "linker flags" *should* use -L and -l flags.

I could not find any explicit specification, but
pkg-config seems to expect -L and -l in linker flags.
Because it provides the following two options(*1,*2);
* --libs-only-L for printing -L/-R part of "--libs"
* --libs-only-l for printing -l part of "--libs"

Anyway, the issue is opencv.pc has been changed in OpenCV-2.4
and it breaks backword compatibility. Is there any reason to break it?


*1) see man page of pkg-config or http://linux.die.net/man/1/pkg-config 
*2) Please search pkg-config and "--libs-only-L" on Internet.
You will find how these options are used in makefile/autotools/cmake files.
Hiromasa YOSHIMOTO on 2012-05-14 10:45
When I checked versioned opencv-2.4.0.pc, 
I found another issue in shared library versioning.
See #1928 for details.

I'd like to update my patch when #1928 is closed
because this pkg-config issue depends on #1928.
Peter Housel on 2012-08-28 17:57
An important reason to use -L is that in cross-compilation environments, pkg-config will prefix -L and -I paths with the path found in PKG_CONFIG_SYSROOT_DIR. This variable normally points to a target sysroot directory containing include files, libraries, and pkgconfig files for the cross-compilation target.
Andrey Kamaev on 2012-10-22 08:48
-   Assignee deleted (Andrey Kamaev)
Ray Rashif on 2012-11-05 17:17
This is still broken in 2.4.3, and it breaks standard pkg-config usage. Another patch attached which makes use of CMake's functionality instead of string replacement.
-   File pkgconfig.patch added
Sebastian Krämer on 2012-11-14 17:03
I'm having the same issues with pkg-config on 64 bit linux. I tried your patch but it doesn't solve the issues for me (although the situation has improved a bit):
<pre>$ PKG_CONFIG_PATH="`pwd`" pkg-config --libs opencv
liblibpng /usr/lib64/libQtTest.so /usr/lib64/libQtCore.so /usr/lib64/libQtGui.so /usr/lib64/libQtOpenGL.so /lib64/libXext.so /lib64/libX11.so /lib64/libICE.so /lib64/libSM.so /lib64/libGL.so /lib64/libGLU.so rt pthread m dl stdc++ /lib64/libz.so -L/home/sebi/src/opencv/lib -lopencv_flann -lopencv_highgui -lopencv_imgproc -lopencv_ml -lopencv_core
</pre>
At least the opencv _-l_ parameters are there now.
Notice the _liblibpng_ at the beginning.
Vadim Pisarevsky on 2014-11-15 09:21
There have been some PR's fixing problems with pkg-config. Hopefully, the problem has been solved.
-   Affected version set to 2.4.0 - 2.4.8
-   Operating System set to Linux
-   HW Platform set to Any
-   Status changed from Open to Done
Timocheck Jackson on 2015-02-17 19:53
The problem is still seems to be present with version 2.4.10:

# pkg-config opencv --libs-only-l
-lrt -lpthread -lm -ldl  
# pkg-config opencv --libs-only-L

# 

Still no "-L" flags. Not possible to link opencv with other programs.
-   Assignee set to Hiromasa YOSHIMOTO
-   Status changed from Done to Incomplete
Steven Puttemans on 2015-02-19 09:11
@Timo

Is it possible that you are using the wrong pkg-config command? I have been using the command for ages on my Ubuntu system with 2.4.10 and it works perfectly.
My command:
<pre>
`pkg-config opencv --libs`
</pre>
@StevenPuttemans
Copy link

The pkg-config command works perfectly fine on both 2.4 and master branch. Also this is related to version 2.4.0 which is more than deprecated so this can be closed down.

@Marqin
Copy link

Marqin commented Mar 28, 2016

It's not working in 3.1.0 on Linux ( but works on OS X ) for me. --debug from pkg-config:

Reading 'opencv' from file '/usr/lib/pkgconfig/opencv.pc'
Parsing package file '/usr/lib/pkgconfig/opencv.pc'
  line>
  line>
  line>prefix=/usr
 Variable declaration, 'prefix' has value '/usr'
  line>exec_prefix=${prefix}
 Variable declaration, 'exec_prefix' has value '/usr'
  line>libdir=${exec_prefix}/lib
 Variable declaration, 'libdir' has value '/usr/lib'
  line>includedir_old=${prefix}/include/opencv
 Variable declaration, 'includedir_old' has value '/usr/include/opencv'
  line>includedir_new=${prefix}/include
 Variable declaration, 'includedir_new' has value '/usr/include'
  line>
  line>Name: OpenCV
  line>Description: Open Source Computer Vision Library
  line>Version: 3.1.0
  line>Libs: -L${exec_prefix}/lib -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn -lopencv_dpm -lopencv_fuzzy -lopencv_hdf -lopencv_line_descriptor -lopencv_optflow -lopencv_plot -lopencv_reg -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_rgbd -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_face -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_flann -lopencv_xobjdetect -lopencv_objdetect -lopencv_ml -lopencv_xphoto -lippicv -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_photo -lopencv_imgproc -lopencv_core
  line>Libs.private: -L/lib64 -lwebp -lpng -ltiff -ljasper -ljpeg -lImath -lIlmImf -lIex -lHalf -lIlmThread -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lgthread-2.0 -lglib-2.0 -ldc1394 -lxine -lv4l1 -lv4l2 -lavcodec -lavformat -lavutil -lswscale -lavresample -lgphoto2 -lgphoto2_port -lexif -lbz2 -lhdf5_hl -lhdf5 -lpthread -lz -ldl -lm -lrt -ltbb
Unknown keyword 'Libs.private' in '/usr/lib/pkgconfig/opencv.pc'
  line>Cflags: -I${includedir_old} -I${includedir_new}
Path position of 'opencv' is 1
Adding 'opencv' to list of known packages
Package opencv has -I/usr/include in Cflags
Removing -I/usr/include from cflags for opencv
Package opencv has -L /usr/lib in Libs
Removing -L /usr/lib from libs for opencv
  pre-remove: opencv
 post-remove: opencv
 original: opencv
   sorted: opencv
adding LIBS_L string ""
returning flags string ""

@StevenPuttemans
Copy link

Does that mean master branch of github? Because I just checked and it is still working perfectly fine here in Ubunto 14.04!

@Marqin
Copy link

Marqin commented Mar 28, 2016

Hmm, it's probably bug in pkg-config. When I changed "/usr/lib" to some other path here, he didn't removed it - it's only removing when -L path is /usr/lib.

But I found another way to find what I need - I need path to where is share/opencv/3rdparty/lib with libippicv.a.
Btw. why that's path is not put as another -L in your pkg-config file?

@alalek
Copy link
Member

alalek commented Mar 28, 2016

Unknown keyword 'Libs.private'

Looks like your version of pkg-config is too old

/usr/lib/pkgconfig/opencv.pc

Does this file come with some package? or is it result of manual build (how did you build it?)

libippicv.a

Just remove this entry from opencv.pc in case of .so files (like libopencv_core.so).

@Marqin
Copy link

Marqin commented Mar 28, 2016

Looks like your version of pkg-config is too old

It's 0.29.1

Does this file come with some package?

I don't see it in my distro and OS X packages, so it must've been put by make.

Just remove this entry from opencv.pc

But I'd like to have it. My problem is ( on both OS X and Linux ) that when I'm building with pkg-config --cflags --libs opencv it gives me -lippicv but doesn't give -L/path/to/dir/with_libippicv.a/ so compiler doesn't know where to search for that one lib. But that should be discussed in another issue - #6338

@strarsis
Copy link

strarsis commented Jul 1, 2017

I had a similar issue on Bash on Windows, I had to install the libopencv-dev package.
(I found the missing package out by using apt-file search opencv.pc command).

@StevenPuttemans
Copy link

I had a similar issue on Bash on Windows, I had to install the libopencv-dev package.

Actually if you install libopencv-dev package, then you are no longer installing your own version, but one kept stored in the repositories of your OS that is not actively maintained. This is not a good solution ...

@strarsis
Copy link

strarsis commented Jul 2, 2017

@StevenPuttemans: Good point, so I need an alternative to this on Bash on Windows.
I wasn't able to find one yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants