与构建文件夹外的 Windows 库链接
Linking with a Windows library outside the build folder
有没有办法 link 使用不在当前包路径中的库。
这 建议将所有内容都放在本地目录下。我们的软件包安装在其他地方的某个存储库中。我只想在 windows.
上指定它的 libpath
authors = ["Me"]
links = "CDbax"
[target.x86_64-pc-windows-gnu.CDbax]
rustc-link-lib = ["CDbax"]
rustc-link-search = ["Z:/Somepath//CPP/CDbax/x64/Debug/"]
root = "Z:/Somepath//CPP/CDbax/x64/Debug/"
但是尝试 cargo build -v 给了我
package `hello v0.1.0 (file:///H:/Users/Mushfaque.Cradle/Documents/Rustc/hello)` specifies that it links to `CDbax` but does not have a custom build script
从 cargo build script support 指南看来,这似乎是可行的。但是我可以看到它没有添加路径。但是,将库移动到本地 bin\x68_64-pc-windows-gnu\
路径是可行的。
更新
多亏了下面的答案,我想我会更新它以给出在我的机器上运行的最终结果,以便其他人发现它有用。
在Cargo.toml中添加
links = "CDbax"
build = "build.rs"
即使没有 build.rs 文件,它似乎需要它 (?) 否则会抱怨
package `xxx v0.1.0` specifies that it links to `CDbax` but does not have a custom build script
接着 Vaelden 回答在 .cargo
中创建一个 'config' 文件
如果这是一个子包,你不需要将 links= 标签放在父包中,即使它是一个 dll;即使有 'cargo run'。我假设它将 dll 路径添加到执行环境
我认为问题在于您将项目的 manifest 误认为是 cargo
配置.
- 清单 是项目根目录中的
Cargo.toml
文件。它描述了您的项目本身。
- cargo 配置 描述了 cargo 的特定设置,并允许例如覆盖依赖项,或者在您的情况下覆盖构建脚本。 cargo 配置文件 有一个 hierarchical structure:
Cargo allows to have local configuration for a particular project or
global configuration (like git). Cargo also extends this ability to a
hierarchical strategy. If, for example, cargo were invoked in
/home/foo/bar/baz, then the following configuration files would be
probed for:
/home/foo/bar/baz/.cargo/config
/home/foo/bar/.cargo/config
/home/foo/.cargo/config
/home/.cargo/config
/.cargo/config
With this structure you can specify local configuration per-project,
and even possibly check it into version control. You can also specify
personal default with a configuration file in your home directory.
因此,如果您移动相关部分:
[target.x86_64-pc-windows-gnu.CDbax]
rustc-link-lib = ["CDbax"]
rustc-link-search = ["Z:/Somepath//CPP/CDbax/x64/Debug/"]
root = "Z:/Somepath//CPP/CDbax/x64/Debug/"
到 cargo 配置文件的任何正确位置,它应该可以工作。
有没有办法 link 使用不在当前包路径中的库。
这
authors = ["Me"]
links = "CDbax"
[target.x86_64-pc-windows-gnu.CDbax]
rustc-link-lib = ["CDbax"]
rustc-link-search = ["Z:/Somepath//CPP/CDbax/x64/Debug/"]
root = "Z:/Somepath//CPP/CDbax/x64/Debug/"
但是尝试 cargo build -v 给了我
package `hello v0.1.0 (file:///H:/Users/Mushfaque.Cradle/Documents/Rustc/hello)` specifies that it links to `CDbax` but does not have a custom build script
从 cargo build script support 指南看来,这似乎是可行的。但是我可以看到它没有添加路径。但是,将库移动到本地 bin\x68_64-pc-windows-gnu\
路径是可行的。
更新 多亏了下面的答案,我想我会更新它以给出在我的机器上运行的最终结果,以便其他人发现它有用。
在Cargo.toml中添加
links = "CDbax"
build = "build.rs"
即使没有 build.rs 文件,它似乎需要它 (?) 否则会抱怨
package `xxx v0.1.0` specifies that it links to `CDbax` but does not have a custom build script
接着 Vaelden 回答在 .cargo
中创建一个 'config' 文件如果这是一个子包,你不需要将 links= 标签放在父包中,即使它是一个 dll;即使有 'cargo run'。我假设它将 dll 路径添加到执行环境
我认为问题在于您将项目的 manifest 误认为是 cargo 配置.
- 清单 是项目根目录中的
Cargo.toml
文件。它描述了您的项目本身。 - cargo 配置 描述了 cargo 的特定设置,并允许例如覆盖依赖项,或者在您的情况下覆盖构建脚本。 cargo 配置文件 有一个 hierarchical structure:
Cargo allows to have local configuration for a particular project or global configuration (like git). Cargo also extends this ability to a hierarchical strategy. If, for example, cargo were invoked in /home/foo/bar/baz, then the following configuration files would be probed for:
/home/foo/bar/baz/.cargo/config /home/foo/bar/.cargo/config /home/foo/.cargo/config /home/.cargo/config /.cargo/config
With this structure you can specify local configuration per-project, and even possibly check it into version control. You can also specify personal default with a configuration file in your home directory.
因此,如果您移动相关部分:
[target.x86_64-pc-windows-gnu.CDbax]
rustc-link-lib = ["CDbax"]
rustc-link-search = ["Z:/Somepath//CPP/CDbax/x64/Debug/"]
root = "Z:/Somepath//CPP/CDbax/x64/Debug/"
到 cargo 配置文件的任何正确位置,它应该可以工作。