Code Monkey home page Code Monkey logo

Comments (7)

alexcrichton avatar alexcrichton commented on August 15, 2024

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.

misos1 avatar misos1 commented on August 15, 2024

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.

misos1 avatar misos1 commented on August 15, 2024

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.

alexcrichton avatar alexcrichton commented on August 15, 2024

You can disable printing andprint it out later yourself perhaps?

from pkg-config-rs.

misos1 avatar misos1 commented on August 15, 2024

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.

alexcrichton avatar alexcrichton commented on August 15, 2024

Maybe this is a bug for metadeps in that case? I'm not sure what should change in this library?

from pkg-config-rs.

misos1 avatar misos1 commented on August 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.