Hi,
I having a strange library linking problem. TLDR: Linking my rust program with the GSL library causes gnuplot
subprocess to load wrong libraries. Any hints on what is happening are greatly appreciated!
I'm running gnuplot
as a subprocess (what follows is a minimal example):
src/main.rs
use std::process::Command;
fn main() {
let output = Command::new("gnuplot")
.output().unwrap();
println!("status: {}", output.status);
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
}
cargo run
prints:
status: exit code: 0
stdout:
stderr:
as expected. So far so good.
Now I want to use the GSL library from my rust code (ultimately through the GSL
crate). To link it to my program, I simply use a build script with pkg-config
:
Cargo.toml
[package]
name = "gnuplot-test"
version = "0.1.0"
build = "build.rs"
[build-dependencies]
pkg-config="0.3"
build.rs
extern crate pkg_config;
fn main() {
pkg_config::probe_library("gsl").unwrap();
}
But now gnuplot
fails because it's loading wrong libraries! Output of cargo run
:
status: signal: 6
stdout:
stderr: dyld: Symbol not found: __cg_jpeg_resync_to_restart
Referenced from: /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
Expected in: /opt/local/lib/libjpeg.9.dylib
in /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
I must be missing something important, but I don't understand how what my program is linked against influences the search paths for the dynamic libraries of any other programs that I might call. For instance, ImageIO above depends on a completely different libJPEG.dylib
:
$ otool -L /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
...
/System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libJPEG.dylib (compatibility version 1.0.0, current version 1.0.0)
...
But for some reason it picks the wrong one from /opt/local/lib
where libgsl.dylib
is located.
I am on macOS sierra 10.12.1, having installed GSL (v2.1) and gnuplot
(v. 5.0.5) both via MacPorts (so they live in /opt/local
).
$ rustc --version master *
rustc 1.12.1 (d4f39402a 2016-10-19)
I haven't set any DYLD_*
env variables.