-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Undefined references when linking with poppler on Ubuntu 17.10 #69
Comments
Thanks for the report! Since this is largely just forwarding flags from |
Preventing already emitted strings from emitting them again to stdout should remove these warnings like when you call pkg-config with multiple packages it will output each library only once. Maybe problem with compilation is on rustc side or there are needed some additional flags due to something what this crate is emitting I am not sure. The best would be to compare what is this crate emitting to stdout or doing vs what you would emit by calling "pkg-config --libs poppler-glib cairo pangocairo" or "pkg-config --libs-only-l --libs-only-L poppler-glib cairo pangocairo" which both worked when I parsed and put output in this form "cargo:rustc-flags=-l cairo -l poppler -L /usr/...". |
I found the problem. I tried to link to another package libpng, test.c:
With this code in build.rs:
On ubuntu gives error "undefined reference to `png_sig_cmp'". On OSX is this working. But this compiles ok:
Same is true also for example with poppler. So library probing must be done after compilation. But this beats one purpose of pkg_config crate because then I cannot get include paths for package for compilation stage. When is called probe_library both before and after compilation it is also not working. Maybe solution could be to not emit "rustc-link-lib" immediately to stdout during probe_library but to have possibility to emit it later after I collect "pkg_config::Library" structures from probe_library and compile c code. Core of problem is that during final compilation test lib must be on command line before libpng. There is output from first build.rs (some details omitted, visible are mainly -l flags):
And here for second:
"cargo:rustc-link-lib=static=test" is emitted to stdout by "cc::Build::new().file("test.c").compile("test");" So problem is in order of -l flags passed to cc called from rustc. In this case:
Rustc is called with "-l png16 -l z -l static=test -l png16 -l z" but it will pass only first "-l png16" to cc '"-l" "png16" "-l" "z" ... "-l" "test"'. |
You can disable printing andprint it out later yourself perhaps? |
But not when using metadeps: https://docs.rs/metadeps/1.1.2/metadeps/ And printing it manually is not so comfortable, maybe here I could first call probe without printing and use include paths and after compilation enable printing and probe again but this is not very nice and still not doable with metadeps. |
Maybe this is a bug for metadeps in that case? I'm not sure what should change in this library? |
Maybe there can be configurable sink with trait std::io::Write in Config where will go prints instead of fixed stdout. Maybe this could be good also for cc-rs crate. Or maybe it could collect these strings into vector. Regarding rustc warnings about redundant linker flags maybe this crate could output same flags only once but then should keep latter occurrences so right dependencies are conserved. This is causing just warnings but as I realised rustc is ignoring duplicated "-l" flags when passing them to cc in way that are kept only first occurrences which could cause linker errors when is order of probed packages reordered. |
When I run cargo build on attached sample rust program test.zip I am getting undefined references:
Dependencies are from these ubuntu packages: libpoppler-glib-dev libcairo2-dev libpango1.0-dev
It is working for example on OSX but on both I am getting these warnings:
These warnings are probably because pkg-config is not checking whether emitting duplicated dependencies from multiple packages into stdout:
Here is output from terminal from cargo build -v on Ubuntu:
Rust version stable 1.27.1.
When I try to emit dependencies manually into stdout then it is compiling without problems.
The text was updated successfully, but these errors were encountered: