在Windows上使用板条箱cargo-vcpkg和magic将magic(c库)链接到cargo项目

问题描述 投票:0回答:1

我的货运项目依赖于 vcpkg 上的 libmagic。我正在使用一个名为“cargo-vcpkg”的板条箱来管理我的 C 依赖项,并且板条箱 magic 提供了该库的绑定。
我使用的是最新版本的 Windows 11 64 位

我在 Cargo.toml 中的依赖项如下所示 -

[package]
...

[dependencies]
magic = "0.13.0"
...

[package.metadata.vcpkg]
git = "https://github.com/microsoft/vcpkg"
rev = "master"
dependencies = ["libmagic:x64-windows-static"]

我已经运行

cargo vcpkg build
将 deps 编译为 dll 文件。 但是,尝试使用
cargo build
cargo run
构建我的项目时,出现以下错误 -

error: linking with `link.exe` failed: exit code: 1181
  |
  = note: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.36.32532\\bin\\HostX64\\x64\\link.exe" "/NOLOGO" "C:\\Users\\Aneesh\\AppData\\Local\\Temp\\rustcYqpdl0\\symbols.o" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\rs_scanner.152qdkerunruxlqv.rcgu.o" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\rs_scanner.1na65qeveik0qnpq.rcgu.o" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\rs_scanner.22n0x11id0zf6hiv.rcgu.o" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\rs_scanner.28tmfw8517vjdlmu.rcgu.o" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\rs_scanner.2gfxobmw3h98vo1m.rcgu.o" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\rs_scanner.3bg3vv1eyq0p7udf.rcgu.o" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\rs_scanner.3ccpwil2kk68vish.rcgu.o" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\rs_scanner.3wx5dp82njfwzazw.rcgu.o" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\rs_scanner.44fbvxv1wr6ykiz.rcgu.o" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\rs_scanner.4f6vo3uh66np7th4.rcgu.o" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\rs_scanner.4j6dbetzj5qfqm14.rcgu.o" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\rs_scanner.4mpznxwgvbbni019.rcgu.o" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\rs_scanner.4q0reje1o97ppegu.rcgu.o" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\rs_scanner.555s2h2oscidcxxi.rcgu.o" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\rs_scanner.57h1itq083jjremb.rcgu.o" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\rs_scanner.586g5zuj6j23g4ja.rcgu.o" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\rs_scanner.cihb7uubmxyo720.rcgu.o" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\rs_scanner.sa88ub53ueep7rf.rcgu.o" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\rs_scanner.yn3urfo1ou5tt8o.rcgu.o" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\rs_scanner.zpgo9dggrfd8nup.rcgu.o" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\rs_scanner.4rv3n8fl9pkyt9pq.rcgu.o" "/LIBPATH:C:\\code-projects\\rs-scanner\\target\\debug\\deps" "/LIBPATH:C:\\Users\\Aneesh\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libmagic-cb25c5444dddd9d6.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libthiserror-a8e3d939053c7cbd.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\liberrno-a73d78a339d97992.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libbitflags-238d36ea99b67de1.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libmagic_sys-9056894aa60c1ef8.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libdotext-3fb72eda7bdda76e.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libzip-d19bcb5dbafbf57c.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libpodio-0138f35bfb8141fb.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libmsdos_time-50fe6c8c1215e9fa.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libtime-20d4860c002a2be9.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libflate2-f9b22d867ad504e1.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libminiz_oxide-66f7887b6aad37b7.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libadler-1116f4304d1673ea.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libcrc32fast-78cb9ea565c30f1a.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libquick_xml-29750ab50af99bc0.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libmemchr-906ccb6e1de1661e.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\liblibc-4d1e58e66fd338fe.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\liberror_chain-af01b26ea8a44293.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libbacktrace-ed65579888b8fe68.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\librustc_demangle-899df4110a728f86.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libencoding_rs-30651bbb6b14fc5a.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libcfg_if-6fd6fae1aec07fe0.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libaho_corasick-fc942a1d303f6d35.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libmemchr-c0fbe447489da9b2.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libsnafu-80a83afec7c1409c.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libdoc_comment-c5c1ad394bc426e5.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libwalkdir-ddb0bca90507e1b0.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libsame_file-7e57d0559f18daae.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libwinapi_util-e22c32a9cdf592de.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libwinapi-97715c78c457b800.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\librayon-a3ec2a1cd875fb3e.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\librayon_core-8a1afbd866efc3fe.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libnum_cpus-7e9a3c2c49a19d10.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libcrossbeam_deque-37df0e2c80518ba0.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libcrossbeam_epoch-3ed081d8c7288141.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libmemoffset-2bfda58f6c387739.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libscopeguard-2f60b7f0eb7b7422.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libcrossbeam_channel-dcc8c793356e2f36.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libcrossbeam_utils-20f55305a540803b.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libcfg_if-5ddb140102fcb6a2.rlib" "C:\\code-projects\\rs-scanner\\target\\debug\\deps\\libeither-07d6d1ee9e96223b.rlib" "C:\\Users\\Aneesh\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-391022a4250a8b9a.rlib" "C:\\Users\\Aneesh\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-3069c74fd845ecc2.rlib" "C:\\Users\\Aneesh\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_demangle-cae8325b8f11cb55.rlib" "C:\\Users\\Aneesh\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd_detect-6ecbb4a24be3ec33.rlib" "C:\\Users\\Aneesh\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libhashbrown-7cef55517a70b408.rlib" "C:\\Users\\Aneesh\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libminiz_oxide-d1e72b1788c7e8f6.rlib" "C:\\Users\\Aneesh\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libadler-65d80753bac4b1a6.rlib" "C:\\Users\\Aneesh\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-932a6231bea08890.rlib" "C:\\Users\\Aneesh\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-04ed514427316340.rlib" "C:\\Users\\Aneesh\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcfg_if-9b75e26b1d0a074f.rlib" "C:\\Users\\Aneesh\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-95c2795d82b7b742.rlib" "C:\\Users\\Aneesh\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-1bf02ac2d8cdb80a.rlib" "C:\\Users\\Aneesh\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-117dfa1fe8688bcf.rlib" "C:\\Users\\Aneesh\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-9ac5797c0b4842d0.rlib" "C:\\Users\\Aneesh\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-ad271357e078d260.rlib" "magic.lib" "legacy_stdio_definitions.lib" "kernel32.lib" "advapi32.lib" "cfgmgr32.lib" "gdi32.lib" "kernel32.lib" "msimg32.lib" "opengl32.lib" "user32.lib" "winspool.lib" "kernel32.lib" "advapi32.lib" "userenv.lib" "kernel32.lib" "ws2_32.lib" "bcrypt.lib" "ntdll.lib" "msvcrt.lib" "legacy_stdio_definitions.lib" "/NXCOMPAT" "/LIBPATH:C:\\Users\\Aneesh\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "/OUT:C:\\code-projects\\rs-scanner\\target\\debug\\deps\\rs_scanner.exe" "/OPT:REF,NOICF" "/DEBUG" "/NATVIS:C:\\Users\\Aneesh\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users\\Aneesh\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\Aneesh\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/NATVIS:C:\\Users\\Aneesh\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libstd.natvis"
  = note: LINK : fatal error LNK1181: cannot open input file 'magic.lib'

这表明文件 magic.lib 不存在。

我的文件夹树如下所示 -
项目目录

  • 来源/
  • ...
  • vcpkg/
    • bin/已安装/x64-windows-static/lib/magic.lib
  • 货物.toml

我尝试过以下方法 -

  • 清洁并重新运行
    cargo vcpkg build
  • 在 vcpkg 目录中手动运行
    vcpkg integrate install
  • 使用不同的魔法绑定箱,称为
    magic-sys
  • 从 Visual Studio 2019 安装程序重新安装 C++ 构建工具
windows rust rust-cargo vcpkg libmagic
1个回答
0
投票

大多数 Rust 绑定库都有自己的构建命令,只需指定它们即可自动应用于链接。

magic 库在内部使用 magic-sys 进行构建后链接。如果需要指定版本,可以使用 magic-sys 中的功能进行修改。

如果需要静态构建,则需要克隆 magic 和 magic-sys 存储库,在本地修改它们,并使用 path = "../path" 指定它们。

© www.soinside.com 2019 - 2024. All rights reserved.