We have the hello world sample and added dependency rand like
cargo add rand
then Cargo.toml looks like
$cat Cargo.toml
[package]
name = "hello"
version = "0.1.0"
edition = "2021"
[dependencies]
rand = "0.8.5"
and we are trying to pass the linker option for rustc through the cargo like
$cargo --config 'build.rustflags = ["-L /<path>/rust-1.70.0.0/x86_64-unknown-linux-gnu/bin/../lib/rustlib/aarch64-wrs-vxworks/lib/ -L <path>/rust-1.70.0.0/x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/"]' build --verbose
rand has the dependency like libc and cargo try to build and fails like
Some errors have detailed explanations: E0408, E0412, E0425, E0463, E0531.
For more information about an error, try `rustc --explain E0408`.
error: could not compile `libc` (build script) due to 50 previous errors
rustc --crate-name build_script_build CARGO_HOME/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libc-0.2.151/build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=138 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=97b99bae06b5ff0f -C extra-filename=-97b99bae06b5ff0f --out-dir /<path>/rust/hello/target/debug/build/libc-97b99bae06b5ff0f -L dependency=/<path>/rust/hello/target/debug/deps --cap-lints allow
note that from 1.70.0 rustc or cargo needs to pass the "-L/rustlib/" target libs path manually and before pervious version are working fine without ,hence we tried to pass through cargo like --config or RUSTFLAGS ,which is not effective and cargo is not passing to rustc like mentioned above ...
any suggestions here to avoid these errors or how we make cargo search the target libs by default without manually intervention from command-line /RUSTFLAGS/ etc ?
like
export RUSTFLAGS="-L <path>/rust-1.70.0.0/x86_64-unknown-linux-gnu/bin/../lib/rustlib/aarch64-wrs-vxworks/lib/ -L <path>rust-1.70.0.0/x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/"
Compiling libc v0.2.151
Compiling cfg-if v1.0.0
Compiling ppv-lite86 v0.2.17
Running `rustc --crate-name cfg_if --edition=2018 <path>/rust/../../usr/rust/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cfg-if-1.0.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=138 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=1f5677bb9cb2f9d9 -C extra-filename=-1f5677bb9cb2f9d9 --out-dir <path>/rust/hello/target/x86_64-unknown-linux-gnu/debug/deps --target x86_64-unknown-linux-gnu -L dependency=<path>/rust/hello/target/x86_64-unknown-linux-gnu/debug/deps -L dependency=/<path>/rust/hello/target/debug/deps --cap-lints allow -L <path>/rust-1.70.0.0/x86_64-unknown-linux-gnu/bin/../lib/rustlib/aarch64-wrs-vxworks/lib/ -L<path>/rust-1.70.0.0/x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/`
Running `rustc --crate-name ppv_lite86 --edition=2018 <path>/rust/../../usr/rust/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ppv-lite86-0.2.17/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=138 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 --cfg 'feature="simd"' --cfg 'feature="std"' -C metadata=3911f71223ba48c3 -C extra-filename=-3911f71223ba48c3 --out-dir <path>/hello/target/x86_64-unknown-linux-gnu/debug/deps --target x86_64-unknown-linux-gnu -L dependency=<path>/rust/hello/target/x86_64-unknown-linux-gnu/debug/deps -L dependency=/<path>/rust/hello/target/debug/deps --cap-lints allow -L /<path>/rust-1.70.0.0/x86_64-unknown-linux-gnu/bin/../lib/rustlib/aarch64-wrs-vxworks/lib/ -L /<path>/rust-1.70.0.0/x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/`
Running `rustc --crate-name build_script_build <path>/rust/../../usr/rust/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libc-0.2.151/build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=138 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=97b99bae06b5ff0f -C extra-filename=-97b99bae06b5ff0f --out-dir /<path>/rust/hello/target/debug/build/libc-97b99bae06b5ff0f -L dependency=/<path>/rust/hello/target/debug/deps --cap-lints allow`
no luck also with
cargo rustc -- "-L /<path>/rust-1.70.0.0/x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/ "
from above cargo verbose ,you see that the library search was appended to CFG-IF and PPV-lite86 compilation ,but "-L " was not passed to LIBC compilation.
any inputs from experts will helps us to debug the issue further ,thanks in advance