microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
22.69k stars 6.27k forks source link

[ffmpeg] Windows static build issues with psapi #23021

Open Haeri opened 2 years ago

Haeri commented 2 years ago

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.

JackBoosY commented 2 years ago

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

Thanks.

Haeri commented 2 years ago

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

JackBoosY commented 2 years ago

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

complexlogic commented 1 year ago

@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.

rokups commented 1 year ago

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.

github-actions[bot] commented 1 year ago

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.

petersteneteg commented 4 months ago

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

dg0yt commented 4 months ago

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.

JackBoosY commented 3 months ago

@LilyWangLL Consider to reopen this issue?

petersteneteg commented 6 days ago

This should be fixed in #39703