vcpkg icon indicating copy to clipboard operation
vcpkg copied to clipboard

[ffmpeg] Windows static build issues with psapi

Open Haeri opened this issue 3 years ago • 10 comments

Describe the bug Windows static version of ffmpeg fails with the following message:

CMake Error at build/vcpkg_installed/x64-windows-static/share/ffmpeg/FindFFMPEG.cmake:68 (find_library):
  Could not find FFMPEG_DEPENDENCY_psapi_RELEASE using the following names:
  psapi

Environment

To Reproduce Steps to reproduce the behavior:

  1. I use ffmpeg as a dependency in my manifest.
  2. I run cmake .. -DVCPKG_TARGET_TRIPLET="x64-windows-static" -DCMAKE_TOOLCHAIN_FILE="%root_path%\external\vcpkg\scripts\buildsystems\vcpkg.cmake" -DBUILD_SHARED_LIBS=OFF to create my solution files
  3. The cmake script fails with the error code mentioned above

Expected behavior The expected behavior would be for the cmake script to succeed in creating a solution file.

Failure logs

...
-- Looking for BZ2_bzCompressInit
-- Looking for BZ2_bzCompressInit - found
-- Found PNG: optimized;D:/a/ElementalDraw/ElementalDraw/build/vcpkg_installed/x64-windows-static/lib/libpng16.lib;debug;D:/a/ElementalDraw/ElementalDraw/build/vcpkg_installed/x64-windows-static/debug/lib/libpng16d.lib (found version "1.6.37") 
CMake Error at build/vcpkg_installed/x64-windows-static/share/ffmpeg/FindFFMPEG.cmake:68 (find_library):
  Could not find FFMPEG_DEPENDENCY_psapi_RELEASE using the following names:
  psapi
Call Stack (most recent call first):
  build/vcpkg_installed/x64-windows-static/share/ffmpeg/FindFFMPEG.cmake:148 (append_dependencies)
  build/vcpkg_installed/x64-windows-static/share/ffmpeg/vcpkg-cmake-wrapper.cmake:6 (_find_package)
  external/vcpkg/scripts/buildsystems/vcpkg.cmake:747 (include)
-- Configuring incomplete, errors occurred!
See also "D:/a/ElementalDraw/ElementalDraw/build/CMakeFiles/CMakeOutput.log".
  CMakeLists.txt:93 (find_package)

See the full logs here: https://github.com/Haeri/ElementalDraw/runs/5132276972?check_suite_focus=true#step:4:407

Additional context The non-static windows build works fine as well as macos.

Haeri avatar Feb 09 '22 23:02 Haeri

Your vcpkg maybe out-dated, can you please git pull and try again? Also, I can't repro this issue locally.

Thanks.

JackBoosY avatar Feb 10 '22 08:02 JackBoosY

I updated it to the latest commit (b71b444d5f2c81d2c642ac63bf230efac8a96dd3) as you can see here: https://github.com/Haeri/ElementalDraw/tree/071b800965b62e2bb2620358ad6d48d652b25719/external

But I still get the exact same issue https://github.com/Haeri/ElementalDraw/runs/5139763195?check_suite_focus=true#step:4:408

I also get the exact same issue on my local windows machine

Haeri avatar Feb 10 '22 12:02 Haeri

We haven't been able to repro this; if more information comes up, or this issue appears again, please reopen.

JackBoosY avatar Aug 05 '22 07:08 JackBoosY

@JackBoosY It's an issue with the FindFFmpeg.cmake module file, not the port itself. The port will successfully build, but when you try to use it in a CMake project according to the instructions provided after the build:

find_package(ffmpeg MODULE REQUIRED)

...it fails with the error as reported by @Haeri above.

As a workaround, I'm using find_path and find_library in my project instead of find_package:

  find_path(FFMPEG_INCLUDE_DIR "libavformat/avformat.h" REQUIRED)
  find_library(LIBAVFORMAT avformat REQUIRED)
  find_library(LIBAVCODEC avcodec REQUIRED)
  find_library(LIBAVUTIL avutil REQUIRED)
  find_library(LIBSWRESAMPLE swresample REQUIRED)

Then I can compile and link using target_include_directories and target_link_libraries using those set variables.

This issue should be reopened and the FindFFmpeg.cmake.in file should be investigated.

complexlogic avatar Sep 06 '22 07:09 complexlogic

In order to reproduce this issue you have to run cmake from non-developer terminal. It is strange though, because cmake still finds correct toolchain and proceeds to configure project to eventually fail. Developer prompt must be setting up some environment variable that helps find_library(FFMPEG_DEPENDENCY_${lib_name}_${config} NAMES "${lib_name}" REQUIRED) to find the library in one of default paths.

rokups avatar Mar 30 '23 06:03 rokups

This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 28 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.

github-actions[bot] avatar Jul 18 '23 02:07 github-actions[bot]

I also ran into this issue, after some digging I found that FindFFMPEG.cmake will call

find_library(FFMPEG_DEPENDENCY_${lib_name}_${config} NAMES "${lib_name}" REQUIRED

To find a set of required system libraries. those system libraries comes from the various pc files

If you link dynamically we will find psapi in libavdevice.pc

Libs: "-L${libdir}" -lavdevice
Libs.private: -lpsapi -lole32 -lstrmiids -luuid -loleaut32 -lshlwapi -lgdi32 -lvfw32

note there that the dependency is "private" so it will not be added to the find_library above. But if we link statically we have

Libs: "-L${libdir}" -lavdevice -lpsapi -lole32 -lstrmiids -luuid -loleaut32 -lshlwapi -lgdi32 -lvfw32

these are now public so they are added to the find_library call above

psapi is a windows system library that lives in for example, (version and so platforms my vary) C:/Program Files (x86)/Windows Kits/10/Lib/10.0.22621.0/um/x64/psapi.lib

When you run cmake from a developer terminal this path get automatically picked up by cmake (somwhow, not sure exactly which env variable that it will read) and then every thing work.

But if we run the cmake-gui directly we have not such luck and we can't find the needed libs.

Ideally we should be able to give the find_library some hint to look into the "right" WindowsSDK directory. But I have not found a good way to get the "right" path, with out a developer terminal

petersteneteg avatar Apr 24 '24 12:04 petersteneteg

I wonder if there should be a find_library at all, or if psapi shouldn't be simply used as is. find_library doesn't consider all locations searched by the linker.

dg0yt avatar Apr 25 '24 03:04 dg0yt

@LilyWangLL Consider to reopen this issue?

JackBoosY avatar May 11 '24 15:05 JackBoosY

This should be fixed in #39703

petersteneteg avatar Aug 23 '24 08:08 petersteneteg

Seeing this problem on AppVeyor again, possibly in reverse somehow: https://ci.appveyor.com/project/endrift/mgba/builds/51886661

CMake Error at C:/Tools/vcpkg/installed/x64-windows-release/share/ffmpeg/FindFFMPEG.cmake:73 (find_library):
  Could not find FFMPEG_DEPENDENCY_psapi.lib_RELEASE using the following
  names: psapi.lib

I didn't change anything and this just started happening 15 days ago.

endrift avatar Apr 15 '25 02:04 endrift

Maybe related: #44955.

dg0yt avatar Apr 15 '25 04:04 dg0yt

Looks right, thanks

endrift avatar Apr 15 '25 04:04 endrift

Apologies, my commit accidentally referenced this issue during my own troubleshooting. It does not contain a fix for this issue, the reference was unintentional.

Confirming that I am also encountering this exact error (Could not find FFMPEG_DEPENDENCY_psapi.lib_RELEASE) when building on GitHub Actions using the standard windows-latest runner.

The build works for Linux(no wonder). This occurs during the CMake configuration step when find_package(aubio) (which depends on ffmpeg) is called, even after ensuring vcpkg dependencies are installed beforehand using lukka/run-vcpkg with runInstall: true

KoshysDev avatar Apr 22 '25 11:04 KoshysDev

@KoshysDev At least you provide a GHA log to look at: https://github.com/KoshysDev/OpenChordix/actions/runs/14592811843/job/40931707360

dg0yt avatar Apr 22 '25 18:04 dg0yt

psapi.lib is located in the Windows Kit. Adding its path to CMAKE_LIBRARY_PATH resolves this issue.

set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH}
    "C:/Program Files (x86)/Windows Kits/10/Lib/10.0.26100.0/um/x64"
)

ryan-yuan-dev avatar Jul 08 '25 17:07 ryan-yuan-dev