有没有办法链接不在当前包路径中的库.
此链接建议将所有内容放在本地目录下.我们的包安装在其他地方的某个存储库中 我只想在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/"
Run Code Online (Sandbox Code Playgroud)
但尝试货物建造-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
Run Code Online (Sandbox Code Playgroud)
从货物构建脚本支持指南,它似乎表明这应该工作.但我可以看到它没有添加路径.bin\x68_64-pc-windows-gnu\然而,将lib移动到本地路径中是有效的.
更新 感谢下面的答案,我想我会更新这个,以便给出我的机器上有效的最终结果,以便其他人发现它很有用.
在Cargo.toml中添加
links = "CDbax"
build = "build.rs"
Run Code Online (Sandbox Code Playgroud)
即使没有build.rs文件,它似乎需要它(?)否则抱怨
package `xxx v0.1.0` specifies that it links to `CDbax` but does not have a custom build script
Run Code Online (Sandbox Code Playgroud)
随后Vaelden回答在.cargo中创建一个'配置'文件
如果这是一个子包,你不需要将links =标记放在父包中,即使它是一个dll; 即使是'货运'.我假设它将dll路径添加到执行环境中
我正在 Windows 上使用 mingw 运行 Rust(可能是我的第一个错误,但我不会放弃)。我下载了 64 位的所有内容,当我构建项目时,我得到了
error: linking with `gcc` failed: exit code: 1
note: gcc '-Wl,--enable-long-section-names' '-fno-use-linker-plugin' '-Wl,--nxcompat' '-static-libgcc' '-m64' '-L' 'C:\R
ust\bin\rustlib\x86_64-pc-windows-gnu\lib' '-o' 'C:\Users\jay\projects\hello_world\target\hello_world.exe' 'C:\Users\jay
\projects\hello_world\target\hello_world.o' '-Wl,--gc-sections' 'C:\Users\jay\projects\hello_world\target\deps\libglfw-5
007f9fddc425da6.rlib' 'C:\Users\jay\projects\hello_world\target\deps\libbitflags-57b03d5337bba57b.rlib' 'C:\Users\jay\pr
ojects\hello_world\target\deps\libsemver-693b3d5412b8e4b9.rlib' 'C:\Users\jay\projects\hello_world\target\deps\liblog-4e
79c2d7625e8c6f.rlib' 'C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib\libstd-4e7c5e5c.rlib' 'C:\Rust\bin\rustlib\x86_64-pc
-windows-gnu\lib\libcollections-4e7c5e5c.rlib' 'C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib\libunicode-4e7c5e5c.rlib'
'C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib\librand-4e7c5e5c.rlib' 'C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib\lib
alloc-4e7c5e5c.rlib' 'C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib\liblibc-4e7c5e5c.rlib' 'C:\Rust\bin\rustlib\x86_64-p
c-windows-gnu\lib\libcore-4e7c5e5c.rlib' '-L' 'C:\Users\jay\projects\hello_world\target' '-L' 'C:\Users\jay\projects\hel
lo_world\target\deps' '-L' 'C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib' '-L' 'C:\Users\jay\projects\hello_world\.rust
\bin\x86_64-pc-windows-gnu' '-L' 'C:\Users\jay\projects\hello_world\bin\x86_64-pc-windows-gnu' '-Wl,--whole-archive' '-W
l,-Bstatic' '-Wl,--no-whole-archive' '-Wl,-Bdynamic' '-lglfw3' '-lopengl32' '-lgdi32' '-lws2_32' '-lcompiler-rt'
note: ld: cannot find -lglfw3
error: aborting due to previous …Run Code Online (Sandbox Code Playgroud)