Bug 442555 - FindCanberra ignores any extra libs if provided by the libcanberra.pc
Summary: FindCanberra ignores any extra libs if provided by the libcanberra.pc
Status: RESOLVED FIXED
Alias: None
Product: extra-cmake-modules
Classification: Frameworks and Libraries
Component: general (other bugs)
Version First Reported In: 5.84.0
Platform: Other Other
: NOR normal
Target Milestone: ---
Assignee: ecm-bugs-null@kde.org
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-09-16 19:42 UTC by Dawid Wróbel
Modified: 2023-05-14 20:12 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dawid Wróbel 2021-09-16 19:42:26 UTC
SUMMARY

Consider following pkgconfig for libcanberra compiled statically:

prefix=${pcfiledir}/../..

exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: libcanberra
Description: Event Sound API
Version: 0.30
Libs: -L"${libdir}" -lcanberra  -L/opt/homebrew/opt/libtool/lib -lltdl
Cflags: -D_REENTRANT -I"${includedir}" -I/opt/homebrew/opt/libtool/include
Requires:


The pkg_check_modules(PC_Canberra libcanberra QUIET) in FindCanberra.cmake sets up all the extra information in following variables:

PC_Canberra_LDFLAGS: -L/Users/cromo/Documents/Sourcecode/vcpkg/installed/arm64-osx/debug/lib/pkgconfig/../../lib;-L/opt/homebrew/opt/libtool/lib;-lcanberra;-lltdl
PC_Canberra_LIBRARIES: canberra;ltdl
PC_Canberra_CFLAGS: -D_REENTRANT;-I/Users/cromo/Documents/Sourcecode/vcpkg/installed/arm64-osx/debug/lib/pkgconfig/../../../include;-I/opt/homebrew/opt/libtool/include

However, only the PC_Canberra_CFLAGS is passed down as INTERFACE_COMPILE_OPTIONS, effectively ignoring the information about the additional libraries that need to be linked against.
Comment 2 Nicolas Fella 2021-09-16 22:50:41 UTC
Could you show what the resulting linker invocation looks like and what you expect it to be?
Comment 3 Dawid Wróbel 2021-11-19 11:06:03 UTC
(In reply to Nicolas Fella from comment #2)
> Could you show what the resulting linker invocation looks like and what you
> expect it to be?

I don't have it handy right now, but before making the proposed change, the -lltdl was missing from the linker invocation, and is correctly applied after the change.
Comment 4 Christophe Marin 2021-11-19 13:33:03 UTC
If it's a static lib, why would it have to link to anything else? sounds like something is broken is the canberra build system
Comment 5 Dawid Wróbel 2021-11-19 13:37:23 UTC
(In reply to Christophe Giboudeaux from comment #4)
> If it's a static lib, why would it have to link to anything else? sounds
> like something is broken is the canberra build system

Linking happens at build time of the static app, not of the library itself. That information must be conveyed to the linker so it knows which libraries are needed, including the indirect dependencies of the direct ones. Please refer to https://people.freedesktop.org/~dbn/pkg-config-guide.html on the Requires.private, Libs.private and Requires.private explanation.
Comment 6 Christophe Marin 2021-11-22 09:35:07 UTC
Static libraries are not supposed to have external link dependencies. If linking fails if ltdl isn't also linked, that's a strong indication that it's a public link target.
Comment 7 Christoph Cullmann 2023-05-14 20:12:39 UTC
Git commit 028d2afde1b5ec765c206bf3db6574c85d200e5e by Christoph Cullmann, on behalf of Dawid Wróbel.
Committed on 14/05/2023 at 19:59.
Pushed by cullmann into branch 'master'.

FindCanberra: link against target provided by pkgconfig

target_link_libraries() against the target generated by
pkg_check_modules() so that the additional linker options are not
lost, such as the additional libraries to link against when
building statically.

M  +4    -1    find-modules/FindCanberra.cmake

https://invent.kde.org/frameworks/extra-cmake-modules/commit/028d2afde1b5ec765c206bf3db6574c85d200e5e