Bug 34504

Summary: Libraries are reported in search order, rather than request order
Product: pkg-config Reporter: Diego Elio Pettenò <flameeyes>
Component: srcAssignee: Tollef Fog Heen <tfheen>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: medium    
Version: unspecified   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:

Description Diego Elio Pettenò 2011-02-20 11:50:06 UTC
Example:

flame@yamato static % PKG_CONFIG_PATH=$(pwd)/libavformat:$(pwd)/libavcodec:$(pwd)/libavutil:$(pwd)/libavcore pkg-config --libs 'libavformat >= 52.31.0 libavcodec >= 51' 
/home/flame/devel/repos/git/ffmpeg/static/libavformat/libavformat.a -pthread /home/flame/devel/repos/git/ffmpeg/static/libavcodec/libavcodec.a /home/flame/devel/repos/git/ffmpeg/static/libavutil/libavutil.a /home/flame/devel/repos/git/ffmpeg/static/libavcore/libavcore.a -ldl -lasound -lm -lbz2 -lz  
flame@yamato static % PKG_CONFIG_PATH=$(pwd)/libavcodec:$(pwd)/libavformat:$(pwd)/libavutil:$(pwd)/libavcore pkg-config --libs 'libavformat >= 52.31.0 libavcodec >= 51'
/home/flame/devel/repos/git/ffmpeg/static/libavcodec/libavcodec.a -pthread /home/flame/devel/repos/git/ffmpeg/static/libavformat/libavformat.a /home/flame/devel/repos/git/ffmpeg/static/libavutil/libavutil.a /home/flame/devel/repos/git/ffmpeg/static/libavcore/libavcore.a -ldl -lasound -lm -lbz2 -lz  

The problem here is that if you pass the library paths as in the second call, the linker will discard libavcodec.a as unnecessary right away, and then will not find the symbols required by libavformat.a.
Comment 1 Tollef Fog Heen 2011-05-15 01:32:25 UTC
Looks like a missing requires in libavformat's .pc file to me.
Comment 2 Diego Elio Pettenò 2011-05-15 04:36:08 UTC
Uhm no.


% pkg-config --libs 'libavformat >= 52.31.0 libavcodec >= 51'
/home/flame/devel/repos/git/libav/yamato/libavformat/libavformat.a -pthread /home/flame/devel/repos/git/libav/yamato/libavcodec/libavcodec.a -ldl -lasound -lm -lbz2 -lz  

you see again libavformat.a being before libavcodec.a as I said.

% fgrep Requires libavformat/libavformat-uninstalled.pc 
Requires: libavcodec = 52.114.0

so the Requires line is properly there.
Comment 3 Dan Nicholson 2012-05-11 09:28:49 UTC
Diego, could you attach (or inline) the .pc files where you're hitting this issue? I have an idea what the problem is, but I'd like to make sure I'm seeing the same thing you are.

Oh, I think I see the issue. pkg-config only treats -l as a library. /lib.a is just another argument in Libs. pkg-config is known to not handle these well. This is the same as people getting the ordering of their -Wl arguments hosed. You can see that pkg-config doesn't consider these libraries by running "pkg-config --libs-only-other".

A workaround is to just use -L with the uninstalled path. The linker will still use the static archive if it's all that's there.
Comment 4 Dan Nicholson 2012-10-13 15:41:11 UTC
Fixed (for this use case) in commit 6ecf318c. There was indeed a bug in ordering of non-l flags. I've now fixed that and added a test. However, there's still the issue that pkg-config breaks the ordering of -l and non-l flags. That's bug19950 and possibly bug16101. I have an idea to fix that but haven't pulled it together yet.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.