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

Libraries linked in incorrect order #132

Open
benjaminmordaunt opened this issue Apr 16, 2022 · 3 comments
Open

Libraries linked in incorrect order #132

benjaminmordaunt opened this issue Apr 16, 2022 · 3 comments

Comments

@benjaminmordaunt
Copy link

Take for example a Rust-SDL2 setup with vcpkg, which resolves some dependencies via pkgconfig-rs. Towards the end, we see:

"-Wl,-Bdynamic" "-lSDL2_ttf" "-lSDL2" "-lSDL2main" "-lfreetype" "-lz" "-lpng" "-lpng16" "-lbz2" "-lbrotlidec-static" "-lbrotlienc-static" "-lbrotlicommon-static" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" 

However, this fails to link, claiming there are missing symbols one would expect from zlib. libpng depends on zlib, therefore -lpng should appear before -lz. I'm not exactly sure where this issue is originating from, but if you can investigate, that would be grand.

@sdroege
Copy link
Collaborator

sdroege commented Apr 16, 2022

Can you provide the output of pkg-config --libs $pkg for all the packages you're depending on in the order they're called by the build.rs?

@Be-ing
Copy link
Contributor

Be-ing commented Oct 21, 2022

rustc does not preserve the order of -l arguments: rust-lang/rust#99427

@petrochenkov
Copy link

petrochenkov commented Oct 22, 2022

@Be-ing
rustc does preserve the order of -l arguments (*), that's why the order preserving -l link-arg is using -l in the first place.

(*) Except for dynamic libraries, but that's something I want to fix (rust-lang/rust#102832 (comment)). Libraries with unspecified kind are considered dynamic. UPD: And relative order between dynamic libraries is also preserved.

# 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

4 participants