Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ffmpeg] Windows static build issues with psapi #23021

Open
Haeri opened this issue Feb 9, 2022 · 9 comments · May be fixed by #38401
Open

[ffmpeg] Windows static build issues with psapi #23021

Haeri opened this issue Feb 9, 2022 · 9 comments · May be fixed by #38401
Assignees
Labels
requires:repro The issue is not currently repro-able Stale

Comments

@Haeri
Copy link
Contributor

Haeri commented Feb 9, 2022

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 JackBoosY added the requires:repro The issue is not currently repro-able label Feb 10, 2022
@JackBoosY
Copy link
Contributor

JackBoosY commented Feb 10, 2022

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

Thanks.

@JackBoosY JackBoosY added the requires:more-information This Issue requires more information to solve label Feb 10, 2022
@Haeri
Copy link
Contributor Author

Haeri commented Feb 10, 2022

I updated it to the latest commit (b71b444)
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 JackBoosY removed the requires:more-information This Issue requires more information to solve label Feb 11, 2022
@JackBoosY
Copy link
Contributor

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

@JackBoosY JackBoosY closed this as not planned Won't fix, can't repro, duplicate, stale Aug 5, 2022
@complexlogic
Copy link
Contributor

@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
Copy link

rokups commented Mar 30, 2023

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
Copy link

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 github-actions bot added the Stale label Jul 18, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 2, 2023
@petersteneteg
Copy link
Contributor

petersteneteg commented Apr 24, 2024

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
Copy link
Contributor

dg0yt commented Apr 25, 2024

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
Copy link
Contributor

@LilyWangLL Consider to reopen this issue?

@LilyWangLL LilyWangLL reopened this May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
requires:repro The issue is not currently repro-able Stale
Projects
None yet
7 participants