larksuite / rsmpeg

A Rust crate that exposes FFmpeg's power as much as possible.
https://docs.rs/rsmpeg/latest/rsmpeg/
MIT License
677 stars 41 forks source link

添加了rustflags后,运行示例代码还是出现链接错误。 #153

Closed yomiko451 closed 9 months ago

yomiko451 commented 9 months ago

一开始运行示例代码出现链接错误后,我看到issues里也有类似情况,需要在cargo.toml里添加rustflag链接需要的库,但是我按照说明修改后,依然不起作用,还是同样的错误。我试着自己捣鼓了一天还是无果,只能来这里问了,希望大佬能解答一下。

这是我的cargo.toml文件内容:

name = "mpp"
version = "0.1.0"
edition = "2021"

[target.x86_64-pc-windows-msvc]
rustflags = [
    "-C", "link-arg=Mfplat.lib",
    "-C", "link-arg=Strmiids.lib",
    "-C", "link-arg=Mfuuid.lib",
    "-C", "link-arg=Bcrypt.lib",
    "-C", "link-arg=Secur32.lib",
    "-C", "link-arg=Ole32.lib",
    "-C", "link-arg=User32.lib"
]

[package.metadata.vcpkg]
dependencies = ["ffmpeg[x264,vpx]:x64-windows-static-md"]
git = "https://github.com/microsoft/vcpkg"
rev = "4a600e9"

[dependencies]
rsmpeg = "0.14.1"

但是还是出现了链接错误:

warning: unused manifest key: target.x86_64-pc-windows-msvc.rustflags
   Compiling mpp v0.1.0 (C:\code\mpp)
error: linking with `link.exe` failed: exit code: 1120
  |
  = note: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.38.33130\\bin\\HostX64\\x64\\link.exe" "/NOLOGO" "C:\\Users\\kingc\\AppData\\Local\\Temp\\rustc0nc0qa\\symbols.o" "C:\\code\\mpp\\target\\debug\\deps\\mpp.10jfcsiaohwsu7cy.rcgu.o" "C:\\code\\mpp\\target\\debug\\deps\\mpp.1dwaetaehtiebkcu.rcgu.o" "C:\\code\\mpp\\target\\debug\\deps\\mpp.1ed1ptovfh1zsixm.rcgu.o" "C:\\code\\mpp\\target\\debug\\deps\\mpp.1hzpawfxlu5lp3a2.rcgu.o" "C:\\code\\mpp\\target\\debug\\deps\\mpp.1iewuom7lyfjb8fq.rcgu.o" "C:\\code\\mpp\\target\\debug\\deps\\mpp.1y5vlv8aaw348wqu.rcgu.o" "C:\\code\\mpp\\target\\debug\\deps\\mpp.23zz3tt4b91iucnp.rcgu.o" "C:\\code\\mpp\\target\\debug\\deps\\mpp.29b3duq5ue6lg260.rcgu.o" "C:\\code\\mpp\\target\\debug\\deps\\mpp.2gz7pe9298fgv2q6.rcgu.o" "C:\\code\\mpp\\target\\debug\\deps\\mpp.30nxobijqurwnf47.rcgu.o" "C:\\code\\mpp\\target\\debug\\deps\\mpp.36x9phlhh8s6c4pm.rcgu.o" "C:\\code\\mpp\\target\\debug\\deps\\mpp.3k7mw3lhlwihw0eg.rcgu.o" "C:\\code\\mpp\\target\\debug\\deps\\mpp.4aq327kwfuohyj43.rcgu.o" "C:\\code\\mpp\\target\\debug\\deps\\mpp.4k70t6unlscoiv4i.rcgu.o" "C:\\code\\mpp\\target\\debug\\deps\\mpp.4mn3q0dp8trvidb2.rcgu.o" "C:\\code\\mpp\\target\\debug\\deps\\mpp.4rpuwgstct9jq33s.rcgu.o" "C:\\code\\mpp\\target\\debug\\deps\\mpp.4v4xoyuimyttc4jd.rcgu.o" "C:\\code\\mpp\\target\\debug\\deps\\mpp.7k1nj8zrix8f36j.rcgu.o" "C:\\code\\mpp\\target\\debug\\deps\\mpp.e49rv0g5d6gs6ft.rcgu.o" "C:\\code\\mpp\\target\\debug\\deps\\mpp.1tbkblyq3dbj18l6.rcgu.o" "/LIBPATH:C:\\code\\mpp\\target\\debug\\deps" "/LIBPATH:C:\\code\\mpp\\target\\vcpkg\\installed\\x64-windows-static-md\\lib" "/LIBPATH:C:\\Users\\kingc\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\code\\mpp\\target\\debug\\deps\\librsmpeg-8a0e3a4cbd4d6468.rlib" "C:\\code\\mpp\\target\\debug\\deps\\libthiserror-1b34f2ea5416241a.rlib" "C:\\code\\mpp\\target\\debug\\deps\\librusty_ffmpeg-7bdaa30b8b9fde02.rlib" "C:\\code\\mpp\\target\\debug\\deps\\liblibc-eca98e9b7510f5a2.rlib" "C:\\Users\\kingc\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-e493bcbfdc66a475.rlib" "C:\\Users\\kingc\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-467acea86c440d1f.rlib" "C:\\Users\\kingc\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_demangle-8bcec20f8d868561.rlib" "C:\\Users\\kingc\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd_detect-e75d865d889e433e.rlib" "C:\\Users\\kingc\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libhashbrown-cd24a5810f58b720.rlib" "C:\\Users\\kingc\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-44b4ecbbc95939b2.rlib" "C:\\Users\\kingc\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-ff93d2b34eb6aecc.rlib" "C:\\Users\\kingc\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcfg_if-17346c417f0e9166.rlib" "C:\\Users\\kingc\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-ff5a06ebf4571d10.rlib" "C:\\Users\\kingc\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-cb2478631e21007b.rlib" "C:\\Users\\kingc\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-58d59322b34f2b51.rlib" "C:\\Users\\kingc\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-c192803e6895f627.rlib" "C:\\Users\\kingc\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-20106e86b5dab94f.rlib" "avdevice.lib" "avfilter.lib" "avformat.lib" "avcodec.lib" "swresample.lib" "swscale.lib" "avutil.lib" "libx264.lib" "vpx.lib" "legacy_stdio_definitions.lib" "kernel32.lib" "advapi32.lib" "bcrypt.lib" "kernel32.lib" "ntdll.lib" "userenv.lib" "ws2_32.lib" "kernel32.lib" "ws2_32.lib" "kernel32.lib" "ntdll.lib" "kernel32.lib" "msvcrt.lib" "/NXCOMPAT" "/LIBPATH:C:\\Users\\kingc\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "/OUT:C:\\code\\mpp\\target\\debug\\deps\\mpp.exe" "/OPT:REF,NOICF" "/DEBUG" "/NATVIS:C:\\Users\\kingc\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users\\kingc\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\kingc\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/NATVIS:C:\\Users\\kingc\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libstd.natvis"
  = note: avformat.lib(tls_schannel.o) : error LNK2019: 无法解析的外部符号 AcquireCredentialsHandleA,函数 tls_open 中引用了该符号
          avformat.lib(tls_schannel.o) : error LNK2019: 无法解析的外部符号 __imp_FreeCredentialsHandle,函数 tls_close 中引用了该符号
          avformat.lib(tls_schannel.o) : error LNK2019: 无法解析的外部符号 InitializeSecurityContextA,函数 tls_close 中引用了该符号
          avformat.lib(tls_schannel.o) : error LNK2019: 无法解析的外部符号 __imp_DeleteSecurityContext,函数 tls_close 中引用了该符号
          avformat.lib(tls_schannel.o) : error LNK2019: 无法解析的外部符号 __imp_ApplyControlToken,函数 tls_close 中引用了该符号
          avformat.lib(tls_schannel.o) : error LNK2019: 无法解析的外部符号 QueryContextAttributesA,函数 tls_write 中引用了该符号
          avformat.lib(tls_schannel.o) : error LNK2019: 无法解析的外部符号 FreeContextBuffer,函数 tls_close 中引用了该符号
          avformat.lib(tls_schannel.o) : error LNK2019: 无法解析的外部符号 EncryptMessage,函数 tls_write 中引用了该符号
          avformat.lib(tls_schannel.o) : error LNK2019: 无法解析的外部符号 DecryptMessage,函数 tls_read 中引用了该符号
          avcodec.lib(mfenc.o) : error LNK2001: 无法解析的外部符号 IID_ICodecAPI
          avcodec.lib(mfenc.o) : error LNK2001: 无法解析的外部符号 IID_IMFMediaEventGenerator
          avcodec.lib(mf_utils.o) : error LNK2019: 无法解析的外部符号 __imp_CoUninitialize,函数 ff_free_mf 中引用了该符号
          avcodec.lib(mf_utils.o) : error LNK2019: 无法解析的外部符号 __imp_CoInitializeEx,函数 ff_instantiate_mf 中引用了该符号
          avcodec.lib(mf_utils.o) : error LNK2019: 无法解析的外部符号 __imp_CoTaskMemFree,函数 ff_instantiate_mf 中引用了该符号
          avcodec.lib(dxva2.o) : error LNK2001: 无法解析的外部符号 __imp_CoTaskMemFree
          avcodec.lib(mf_utils.o) : error LNK2001: 无法解析的外部符号 IID_IMFTransform
          avutil.lib(hwcontext_dxva2.o) : error LNK2019: 无法解析的外部符号 __imp_GetDesktopWindow,函数 dxva2_device_create 中引用了该符号
          C:\code\mpp\target\debug\deps\mpp.exe : fatal error LNK1120: 16 个无法解析的外部命令

error: could not compile `mpp` (bin "mpp") due to 1 previous error
ldm0 commented 9 months ago

It can be noted that: warning: unused manifest key: target.x86_64-pc-windows-msvc.rustflags.

[target.x86_64-pc-windows-msvc]
rustflags = [
    "-C", "link-arg=Mfplat.lib",
    "-C", "link-arg=Strmiids.lib",
    "-C", "link-arg=Mfuuid.lib",
    "-C", "link-arg=Bcrypt.lib",
    "-C", "link-arg=Secur32.lib",
    "-C", "link-arg=Ole32.lib",
    "-C", "link-arg=User32.lib"
]

This shouldn't be placed in Cargo.toml, try move it into <your-project>/.cargo/config.toml.

Similar issue: https://users.rust-lang.org/t/statically-linking-to-crt-on-msvc/9755

yomiko451 commented 9 months ago

It can be noted that: warning: unused manifest key: target.x86_64-pc-windows-msvc.rustflags.

[target.x86_64-pc-windows-msvc]
rustflags = [
    "-C", "link-arg=Mfplat.lib",
    "-C", "link-arg=Strmiids.lib",
    "-C", "link-arg=Mfuuid.lib",
    "-C", "link-arg=Bcrypt.lib",
    "-C", "link-arg=Secur32.lib",
    "-C", "link-arg=Ole32.lib",
    "-C", "link-arg=User32.lib"
]

This shouldn't be placed in Cargo.toml, try move it into <your-project>/.cargo/config.toml.

Similar issue: https://users.rust-lang.org/t/statically-linking-to-crt-on-msvc/9755

原来如此,还是学的少了,多谢多谢!