无法使用cairo-rs链接程序:“与`cc`链接失败”和“找不到-lgobject-2.0的库”

时间:2018-05-26 05:52:28

标签: rust rust-cargo

我正在关注this tutorial使用cairo-rs为图像绘制一些东西。当我运行我的代码时,我得到一个非常冗长的错误。重要的一点似乎是:

linking with "cc" failed: exit code: 1

ld: library not found for -lgobject-2.0 
clang: error: linker command failed with exit code 1

我通过MacPorts安装了Cairo,所以这应该不是问题。我从教程中复制了Cargo.toml文件,除了最新的软件包:

[dependencies]
png = "0.12.0"
cairo-rs = {version = "0.4.1", features = ["png"]}

我也尝试过本教程中列出的版本,但是我得到了同样的错误。

Rust issue 18610似乎有类似的错误,建议安装libc-dev。我不知道那是什么或为什么会解决任何问题。

我在某个地方看到它可能是一个命名冲突,所以我改变了我的项目的名称,以免冲突,但它没有帮助。

详细

  • 我正在使用Rust,我甚至重新安装了它。
  • MacOS High Sierra,版本10.13.3(17D47)

完整错误

error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-m64" "-L" "/Users/davidsullivan/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6.138pesuvab4dy035.rcgu.o" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6.15kq92zzbmxot4k9.rcgu.o" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6.16u6js6g0l3k1ic6.rcgu.o" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6.18w6p8ltrgxnoslg.rcgu.o" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6.1kduva7sc7em934m.rcgu.o" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6.1vut2eft6nlujjxr.rcgu.o" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6.1y16o1qfye96o7m0.rcgu.o" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6.1zeawhkbeobww1zn.rcgu.o" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6.2f1hnlzab9mh7h5g.rcgu.o" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6.2jqywn86b2gsqohu.rcgu.o" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6.2qhkzqx5zqexj20y.rcgu.o" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6.3171x0bwu82dptu7.rcgu.o" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6.3bupun14v400xrjn.rcgu.o" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6.3cx7oljifvb206q7.rcgu.o" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6.3gri9e66l1z4vy9t.rcgu.o" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6.3rngp6bm2u2q5z0y.rcgu.o" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6.45nf4z58qqykpcpi.rcgu.o" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6.49a7n47po4ttqjl7.rcgu.o" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6.49lx1q7cxvpykyv0.rcgu.o" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6.4ezmh1vbs95c5ack.rcgu.o" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6.4pd8ez09p90ytr94.rcgu.o" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6.4xq48u46a1pwiqn7.rcgu.o" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6.4yh8x2b62dcih00t.rcgu.o" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6.5adk9fi3m3eo99v4.rcgu.o" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6.8xzrsc1ux72v29j.rcgu.o" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6.9elsx31vb4it187.rcgu.o" "-o" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/using_cairo-0c2716712c3e8ee6.crate.allocator.rcgu.o" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps" "-L" "/Users/davidsullivan/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/libcairo-02af06cb5f843585.rlib" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/libglib-9b2eaf5a04b666f1.rlib" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/libgobject_sys-dffb3413958eb3eb.rlib" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/libglib_sys-d80b4885044879d2.rlib" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/liblazy_static-ecb17a6c9c859f76.rlib" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/libbitflags-bcdfdc861d8d5eb6.rlib" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/libc_vec-21d683c350f5dff1.rlib" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/libcairo_sys-778a9ff4a1493728.rlib" "/Users/davidsullivan/Desktop/Programing/Rust/graphics/using_cairo/target/debug/deps/liblibc-83288e07e4750a07.rlib" "/Users/davidsullivan/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd-844f948b7f44d010.rlib" "/Users/davidsullivan/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-1d305abaf51b5849.rlib" "/Users/davidsullivan/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc_jemalloc-480b35384c455cd2.rlib" "/Users/davidsullivan/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libunwind-579e24175a3d2d71.rlib" "/Users/davidsullivan/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc_system-2600026bf2ff8eb5.rlib" "/Users/davidsullivan/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liblibc-7bb0ccf08d309fa4.rlib" "/Users/davidsullivan/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc-d90d94404b7883e9.rlib" "/Users/davidsullivan/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd_unicode-6be41d1b0b4956a1.rlib" "/Users/davidsullivan/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcore-788f4f091335111f.rlib" "/Users/davidsullivan/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-e26406cc89e6bd21.rlib" "-l" "gobject-2.0" "-l" "glib-2.0" "-l" "gobject-2.0" "-l" "cairo" "-l" "System" "-l" "resolv" "-l" "pthread" "-l" "c" "-l" "m"
  = note: ld: library not found for -lgobject-2.0
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

Cargo.toml

[package]
name = "using_cairo"
version = "0.1.0"
authors = ["davidsullivan <touisbetterthanpi@gmail.com>"]

[dependencies]
png = "0.12.0"
cairo-rs = {version = "0.4.1", features = ["png"]}

main.rs

extern crate cairo;

use cairo::{Context, Format, ImageSurface};
use std::fs::File;

fn main() {
    let surface = ImageSurface::create(Format::ARgb32, 600, 600).expect("could not create surface");
    let context = Context::new(&surface);

    context.set_source_rgb(1.0, 0.0, 0.0);
    context.paint();

    let mut file = File::create("output.png").expect("Could not create file");

    surface
        .write_to_png(&mut file)
        .expect("could not write to file");
}

1 个答案:

答案 0 :(得分:4)

您需要安装glibcairo的正确开发库。

如果您的操作系统与Debian相关,请输入apt install libglib2.0-dev

如果您使用的是macOS和Homebrew,请键入brew install glib,然后brew install cairo