-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rustc-link-arg wrong order #12833
Comments
I can look into the log and guess how it failed. However, to avoid misunderstanding, could you provide a minimal reproducer if possible, or at least a part of your build script related to linker args? |
commands: clang -c test.c
ar crv libtest.a test.o
cargo run test.c: #include <math.h> // This links to libm
double test_pow(double x, double y) {
return pow(x,y);
} build script: use std::{env, path::PathBuf};
fn main() {
// Won't compile:
let manifest = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
println!("cargo:rustc-link-arg={}", manifest.join("libtest.a").display());
// Will compile:
// let manifest = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
// println!("cargo:rustc-link-lib=static=test");
// println!("cargo:rustc-link-search={}",manifest.display());
} main.rs: fn main() {
unsafe {
let result = test_pow(2.0, 2.0);
println!("2^2={}", result);
}
}
extern "C" {
fn test_pow(x: f64, y: f64) -> f64;
} link error:
|
Hi. Thanks for the example.
I can see what you did with Close as Cargo has no control over how rustc manages the order of linker arguments for |
Although it's unrelated to this issue, I'd like to know your opinion on the "-l" parameter, specifically why we have search paths and link names. Why don't we default to linking to absolute paths? |
Problem
I'm trying to link to a static library with an absolute path using build scripts and rustc-link-arg, but I found that its additional arguments are appended to the end instead of in the middle This is different from rustc-link-lib.
In this example, the pow and log10 function exist in libm, but due to the issue, the linker is unable to resolve it.
Steps
No response
Possible Solution(s)
No response
Notes
No response
Version
No response
The text was updated successfully, but these errors were encountered: