Comments (7)
Thanks for the report! Since this is largely just forwarding flags from pkg-config
though, I'm not sure what this repository would do differently?
from pkg-config-rs.
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/...".
from pkg-config-rs.
I found the problem. I tried to link to another package libpng, test.c:
#include <png.h>
void test()
{
unsigned char x[8];
png_sig_cmp(x, 0, sizeof(x));
}
With this code in build.rs:
fn main()
{
pkg_config::probe_library("libpng").unwrap();
cc::Build::new().file("test.c").compile("test");
}
On ubuntu gives error "undefined reference to `png_sig_cmp'". On OSX is this working.
But this compiles ok:
fn main()
{
cc::Build::new().file("test.c").compile("test");
pkg_config::probe_library("libpng").unwrap();
}
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):
cargo:rustc-link-lib=png16
cargo:rustc-link-lib=z
cargo:rustc-link-lib=static=test
...
Running `rustc --crate-name test test.rs --crate-type bin ... -l png16 -l z -l static=test`
error: linking with `cc` failed: exit code: 1
|
= note: "cc" ... "-l" "png16" "-l" "z" ... "-l" "test" ... "-l" "dl" "-l" "rt" "-l" "pthread" "-l" "pthread" "-l" "gcc_s" "-l" "c" "-l" "m" "-l" "rt" "-l" "pthread" "-l" "util" "-l" "util"
= note: /home/miso/test/target/debug/build/test-4eee4af9b8645a50/out/libtest.a(test.o): In function `test':
/home/miso/test/test.c:8: undefined reference to `png_sig_cmp'
collect2: error: ld returned 1 exit status
And here for second:
cargo:rustc-link-lib=static=test
cargo:rustc-link-lib=png16
cargo:rustc-link-lib=z
Running `rustc --crate-name test test.rs --crate-type bin ... -l static=test -l png16 -l z`
Finished dev [unoptimized + debuginfo] target(s) in 1.20s
"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:
fn main()
{
pkg_config::probe_library("libpng").unwrap();
cc::Build::new().file("test.c").compile("test");
pkg_config::probe_library("libpng").unwrap();
}
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"'.
from pkg-config-rs.
You can disable printing andprint it out later yourself perhaps?
from pkg-config-rs.
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.
from pkg-config-rs.
Maybe this is a bug for metadeps in that case? I'm not sure what should change in this library?
from pkg-config-rs.
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.
from pkg-config-rs.
Related Issues (20)
- Dependency being constantly rebuilt due to 'env_metadata' being set to 'true' HOT 8
- Should we parse -isystem Cflags? HOT 2
- customized pkg-config is incomplete? HOT 1
- Bug: Missing support for `pkgconf` for Fedora HOT 3
- v0.3.21 raised MSRV to 1.47.0 HOT 4
- Placing pkg-config.exe file to this git if possible HOT 3
- Libraries linked in incorrect order HOT 3
- Incorrect parse result for raw archive path HOT 3
- [Feature Request] Add configurable linking modifiers HOT 6
- `PKG_CONFIG_PATH_FOR_BUILD` env var HOT 4
- Allow disabling pkg-config altogether HOT 7
- static-nobundle option
- Unable to correctly identify a type of Windows static library name, such as `foo.lib` HOT 7
- Cargo build say "library name must not be empty" while using statik(true) HOT 4
- fails with pkgconf 2.0.0 breaking changes HOT 1
- Cannot link static libraries on Windows MinGW because the Libs.private flags are ignored
- Reduce -L flag pollution by resolving -L -l flags to on-disk files
- Rustdoc docs are missing information about environment variables present in README HOT 2
- Cannot link statically against `alsa` library HOT 2
- Add tag for 0.3.30 release? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pkg-config-rs.