Skip to content

Linker error on a crates that link with system frameworks and add library search paths #36250

Closed
@kornelski

Description

@kornelski

On OS X rustdoc somehow ends up linking the tested crate with ImageIO.framework and libjpeg, even if the crate doesn't link with any library.

If the tested crate's build script merely sets a search path (cargo:rustc-link-search=native=/usr/local/lib) to a path contains a version of libjpeg, rustdoc will link with it. This is problematic, because rustdoc also links with OS X's ImageIO.framework which can't coexist with non-Apple libjpeg in the same program.

$ cargo test --doc

Finished debug [unoptimized + debuginfo] target(s) in 0.0 secs
Doc-tests testing
dyld: Symbol not found: __cg_jpeg_resync_to_restart
Referenced from: /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
Expected in: /usr/local/lib/libJPEG.dylib
in /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
error: Process didn't exit successfully: rustdoc --test /private/tmp/testing/src/lib.rs --crate-name testing -L dependency=/private/tmp/testing/target/debug/deps -L native=/usr/local/lib --extern testing=/private/tmp/testing/target/debug/deps/libtesting.rlib (signal: 5, SIGTRAP: trace/breakpoint trap)

What makes even more bizarre is that if I run the failing command myself from terminal, it works:

$ rustdoc --test /private/tmp/testing/src/lib.rs --crate-name testing -L dependency=/private/tmp/testing/target/debug/deps -L native=/usr/local/lib --extern testing=/private/tmp/testing/target/debug/deps/libtesting.rlib

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured

rustc 1.13.0-nightly (497d67d 2016-09-01)

To reproduce:

brew install libjpeg && brew link libjpeg
cargo new testing

add build.rs with

fn main() {
    println!("cargo:rustc-link-search=native=/usr/local/lib");
}
cargo test --doc

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-dev-toolsRelevant to the dev-tools subteam, which will review and decide on the PR/issue.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions