Skip to content
New issue

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

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

Already on GitHub? # to your account

Reduce -L flag pollution by resolving -L -l flags to on-disk files #155

Open
nirbheek opened this issue Aug 30, 2023 · 0 comments
Open

Reduce -L flag pollution by resolving -L -l flags to on-disk files #155

nirbheek opened this issue Aug 30, 2023 · 0 comments

Comments

@nirbheek
Copy link
Contributor

When picking up libraries from multiple prefixes (which is quite common in practice, for example when you have /usr and /opt), it is very easy to get into a situation where the wrong library is being picked up by the linker. For example:

/prefix1/lib/libfoo.a
/prefix1/lib/libbar.a
/prefix1/lib/pkgconfig/foo.pc
/prefix1/lib/pkgconfig/bar.pc

/prefix2/lib/libfaz.a
/prefix2/lib/libbar.a
/prefix2/lib/pkgconfig/faz.pc
/prefix2/lib/pkgconfig/bar.pc

With PKG_CONFIG_PATH=/prefix1/lib/pkgconfig:/prefix2/lib/pkgconfig you'd expect libbar.a to be picked up from prefix1. But if you are aggregating flags like so:

pkg_config::probe_library("faz").unwrap();
pkg_config::probe_library("bar").unwrap();

This will generate a linker line like:

[...] -L/prefix2/lib -L/prefix1/lib  [...] -lfaz -lbar

The linker will resolve this to:

/prefix2/lib/libfaz.a /prefix2/lib/libbar.a

The solution is that probe_library() should resolve the -L -l flags it receives from the pc file to on-disk files immediately, and pass those files to the linker:

/prefix2/lib/libfaz.a /prefix1/lib/libbar.a

If it is unable to find the corresponding library, it can fall back to the current behaviour. This should reduce the likelihood of incorrect libs being picked up considerably.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant