Richard Ash
2014-Aug-09 22:04 UTC
[Vorbis] libvorbisfile dynamic linkage with pkg-config - inter-library dependencies?
Audacity is preparing to release version 2.0.6 shortly, so I have been doing numerous test builds. Since the last Audacity release, my development system (Gentoo Linux) has updated to libvorbis-1.3.4 and libogg-1.3.1. As a result (I think) of this, I now get link errors when trying to compile Audacity against the system copies of libogg and libvorbis (standard dynamic linkage to the system libraries). There has not been significant change to the Audacity calling code since this was last working. The problem seems to be that pkg-config --libs --print-errors "vorbisfile" outputs -lvorbisfile but when I try to link Audacity with only -lvorbisfile on the linker command line, the link fails with /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/../../../../x86_64-pc-linux-gnu/bin/ld: export/audacity-ExportOGG.o: undefined reference to symbol 'vorbis_block_init' /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/../../../../x86_64-pc-linux-gnu/bin/ld: note: 'vorbis_block_init' is definedExportOGG.o in DSO /usr/lib64/libvorbis.so.0 so try adding it to the linker command line /usr/lib64/libvorbis.so.0: could not read symbols: Invalid operation collect2: error: ld returned 1 exit status make[2]: *** [audacity] Error 1 vorbis_block_init() is called from ExportOGG.cpp, although that file doesn't #include vorbis/codec.h - the only include from libvorbis is #include <vorbis/vorbisenc.h>, which presumably brings the necessary headers in indirectly? The only solution I have found is to explicitly ask pkg-config for the dependent libraries (libvorbis and libogg) when calling pkg-config, so do pkg-config --libs --print-errors "vorbisfile vorbis ogg" in order to get -lvorbisfile -lvorbis -logg which then links correctly. This does not seem (to me) to be the intended behaviour of pkg-config, and it certainly isn't how it used to happen the last time I had to work on this, but I'm not 100% sure what has changed in the mean time! Is there any documentation on the "correct" way to link to the higher-level Vorbis APIs using pkg-config? Is this intended, or an accidental change? Richard
Ralph Giles
2014-Aug-11 20:03 UTC
[Vorbis] libvorbisfile dynamic linkage with pkg-config - inter-library dependencies?
On 2014-08-09 3:04 PM, Richard Ash wrote:> vorbis_block_init() is called from ExportOGG.cpp, although that file > doesn't #include vorbis/codec.h - the only include from libvorbis is > #include <vorbis/vorbisenc.h>, which presumably brings the necessary > headers in indirectly?Yes, vorbisenc.h includes codec.h.> The only solution I have found is to explicitly ask pkg-config for the > dependent libraries (libvorbis and libogg) when calling pkg-config, so > do > pkg-config --libs --print-errors "vorbisfile vorbis ogg" > in order to get > -lvorbisfile -lvorbis -loggSo vorbisfile.pc has vorbis as a Requires.private. I think the way this is supposed to work is that if you're linking to the shared libraries, transitive deps in the .so files will pull in vorbis when you '-l vorbisfile'. When you link statically (so pkg-config --libs --static vorbisfile) then you get -lvorbis -logg -lm, etc. The question is why this isn't working for you. Are you linking statically? Is the build system passing --static to pkg-config? There are systems where the linker doesn't see dependencies inside .so files, but x86_64-pc-linux-gnu isn't one of them. For theora, we use a 'Requires' instead of a 'Requires.private' so it works unconditionally. If my understand above is correct, that's not optimal, but might work around your problem. Try that as well? -r