首页 > 解决方案 > build.rs 中设置的 LD_LIBRARY_PATH 不会传递给 vscode 中的调试器

问题描述

所以我有两个简单的项目,一个有一个带有 c 库的子文件夹,它在运行时链接到另一个只是一个全新的 hello-world 应用程序。

我正在看这个:https ://www.youtube.com/watch?v= EzQ7YIIo1rY&t=3386s 非常好的教程视频,我正在研究使用 rust 插件设置 vscode。

所以我安装了rust analyserCodeLLDB. 两者在这两个项目上都表现出色。到目前为止,一切都很好。然后我想在代码行debug上方运行该选项fn main() {。这非常适合简单的 hello world 应用程序。对于还链接到共享对象库的应用程序,它会尝试运行,但出现错误:

/home/user/bbb/development/rust_test/target/debug/rust_test: error while loading shared libraries: libadd_x64Linuxd.so: cannot open shared object file: No such file or directory

我对此并不感到惊讶,在其他 C++ 调试器中,我必须设置一个 settings/launcher.json 并在其中添加 LD_LIBRARY_PATH 。但是对于生锈,我不太确定。我原以为build.rs会处理好这件事-其中包含:

use std::process::Command;

fn main() {
    // EXTERN_C
    // The name of the library to link to, i.e. like: -l<lib>
    println!("cargo:rustc-link-lib=dylib=add_x64Linuxd");
    // The library search path for linking, i.e. like -L<path>
    println!("cargo:rustc-link-search=native=cadd/lib");
    // The run-time library search path (LD_LIBRARY_PATH)
    println!("cargo:rustc-env=LD_LIBRARY_PATH=cadd/lib");
}

所以路径都设置在这里。cargo run工作,它链接到我的共享库。所以问题是我如何在运行调试器时传递/设置 LD_LIBRARY_PATH(就像在 youtube 视频中显示的那样,通过按下代码内的“调试”选项)?

标签: debuggingvisual-studio-coderustshared-libraries

解决方案


推荐阅读