nyfair / mpv-win64

MPV Player Win64 Auto Build Bot
18 stars 3 forks source link

求助:关于编译libjxl的问题~ #14

Closed eko5624 closed 2 years ago

eko5624 commented 2 years ago

不好意思又来麻烦您了,您对我的帮助真的很大了,谢谢~

我参考shinchiro的代码试着自己编译libjxl,也成功了。不过运行mpv时会提示缺少libwinpthread-1.dll和libgcc_s_seh-1.dll这两个文件。我把toolchain里的这2个文件复制到mpv.exe所在的目录就能成功运行了。

怎么才能解决对这2个dll文件的依赖呢。我在csdn上搜索得到一个答案是这样,加一句:

 $libs = '-Wl,-Bstatic -lstdc++  -lgcc_eh -lpthread -Wl,-Bdynamic'

关键是这一句要加在何处呢?怎么才能验证这一句是否起作用呢?我不懂编程,就是想通过编译mpv来学一些东西,以点带面。

这个问题困扰我好几天了,因为确实不知道怎么解决,所以特来求助,先谢谢了!

附仓库地址: https://github.com/eko5624/mpv-win64/tree/test-libjxl

nyfair commented 2 years ago

https://github.com/libjxl/libjxl/issues/995 原则上,我们使用mcf的thread模型就是为了避免windows上pthread的坑,让std::thread不去使用winpthread,从根本上避免链接这些lib shinchiro的工具链里自己编译了静态的winpthread,把这些问题隐藏了,但msys2原生的工具链里可没有

libjxl本身只使用std::thread并不依赖pthread,但是它的cmake编译脚本里有些hack会强制链接pthread https://github.com/libjxl/libjxl/blob/e43c7192e51cd884168010cc5b20e7a3140fd1eb/CMakeLists.txt#L191-L222 你可以先试试把191行和222行的-lpthread删掉,或者把-lpthread改成-lmcfgthread

eko5624 commented 2 years ago

按照您说的方法,加上下面这2句,不过还是不行,运行mpv.exe报错信息和之前一样,缺少libwinpthread-1.dll和libgcc_s_seh-1.dll。

  sed -i 's/THREADS_PREFER_PTHREAD_FLAG/THREADS_PREFER_MCFGTHREAD_FLAG/' CMakeLists.txt
  sed -i 's/-Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic/-Wl,-Bstatic -lstdc++ -lmcfgthread -Wl,-Bdynamic/' CMakeLists.txt
nyfair commented 2 years ago

先别管mpv,编译下libjxl那些cjxl djxl之类的工具看看会不会依赖winpthread

eko5624 commented 2 years ago

编译libjxl时的log

-- The C compiler identification is GNU 12.1.1
-- The CXX compiler identification is GNU 12.1.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: D:/ucrt64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: D:/ucrt64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- CMAKE_SYSTEM_PROCESSOR is AMD64
-- Performing Test CXX_FUZZERS_SUPPORTED
-- Performing Test CXX_FUZZERS_SUPPORTED - Failed
-- Performing Test CXX_CONSTRUCTOR_ALIASES_SUPPORTED
-- Performing Test CXX_CONSTRUCTOR_ALIASES_SUPPORTED - Failed
-- Performing Test CXX_MACRO_PREFIX_MAP
-- Performing Test CXX_MACRO_PREFIX_MAP - Success
-- Performing Test CXX_NO_RTTI_SUPPORTED
-- Performing Test CXX_NO_RTTI_SUPPORTED - Success
-- Found PkgConfig: D:/msys64/usr/bin/pkg-config.exe (found version "1.8.0") 
-- Compiled IDs C:GNU, C++:GNU
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Performing Test ATOMICS_LOCK_FREE_INSTRUCTIONS
-- Performing Test ATOMICS_LOCK_FREE_INSTRUCTIONS - Success
-- Found HWY: D:/msys64/opt/lib/libhwy.a (found suitable version "0.16.0", minimum required is "0.15.0") 
-- Checking for module 'libbrotlicommon'
--   Package 'libbrotlicommon', required by 'virtual:world', not found
-- Checking for module 'libbrotlienc'
--   Package 'libbrotlienc', required by 'virtual:world', not found
-- Checking for module 'libbrotlidec'
--   Package 'libbrotlidec', required by 'virtual:world', not found
-- Found Brotli: D:/msys64/opt/include  
-- Found LCMS2: D:/msys64/opt/lib/liblcms2.a (found suitable version "2.13", minimum required is "2.13") 
-- Found ZLIB: D:/msys64/opt/lib/libz.a (found version "1.2.12") 
-- Found PNG: D:/msys64/opt/lib/libpng.a (found version "1.6.38.git") 
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
-- Could NOT find GIF (missing: GIF_LIBRARY GIF_INCLUDE_DIR) (Required is at least version "5.1")
-- Found JPEG: D:/msys64/opt/lib/libjpeg.a (found version "62") 
-- Checking for module 'OpenEXR'
--   Package 'OpenEXR', required by 'virtual:world', not found
-- Building with JPEGXL_VERSION=ff65c387 (auto-updated)
-- Building tools: 
-- Configuring done
-- Generating done
nyfair commented 2 years ago

把pthread.h删了行不行?或者干脆就像vapoursynth那样用msvc编译得了

eko5624 @.***> 于 2022年5月9日周一 18:42写道:

编译libjxl时的log

-- The C compiler identification is GNU 12.1.1

-- The CXX compiler identification is GNU 12.1.1

-- Detecting C compiler ABI info

-- Detecting C compiler ABI info - done

-- Check for working C compiler: D:/ucrt64/bin/gcc.exe - skipped

-- Detecting C compile features

-- Detecting C compile features - done

-- Detecting CXX compiler ABI info

-- Detecting CXX compiler ABI info - done

-- Check for working CXX compiler: D:/ucrt64/bin/g++.exe - skipped

-- Detecting CXX compile features

-- Detecting CXX compile features - done

-- CMAKE_SYSTEM_PROCESSOR is AMD64

-- Performing Test CXX_FUZZERS_SUPPORTED

-- Performing Test CXX_FUZZERS_SUPPORTED - Failed

-- Performing Test CXX_CONSTRUCTOR_ALIASES_SUPPORTED

-- Performing Test CXX_CONSTRUCTOR_ALIASES_SUPPORTED - Failed

-- Performing Test CXX_MACRO_PREFIX_MAP

-- Performing Test CXX_MACRO_PREFIX_MAP - Success

-- Performing Test CXX_NO_RTTI_SUPPORTED

-- Performing Test CXX_NO_RTTI_SUPPORTED - Success

-- Found PkgConfig: D:/msys64/usr/bin/pkg-config.exe (found version "1.8.0")

-- Compiled IDs C:GNU, C++:GNU

-- Looking for pthread.h

-- Looking for pthread.h - found

-- Performing Test CMAKE_HAVE_LIBC_PTHREAD

-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed

-- Looking for pthread_create in pthreads

-- Looking for pthread_create in pthreads - not found

-- Looking for pthread_create in pthread

-- Looking for pthread_create in pthread - found

-- Found Threads: TRUE

-- Performing Test ATOMICS_LOCK_FREE_INSTRUCTIONS

-- Performing Test ATOMICS_LOCK_FREE_INSTRUCTIONS - Success

-- Found HWY: D:/msys64/opt/lib/libhwy.a (found suitable version "0.16.0", minimum required is "0.15.0")

-- Checking for module 'libbrotlicommon'

-- Package 'libbrotlicommon', required by 'virtual:world', not found

-- Checking for module 'libbrotlienc'

-- Package 'libbrotlienc', required by 'virtual:world', not found

-- Checking for module 'libbrotlidec'

-- Package 'libbrotlidec', required by 'virtual:world', not found

-- Found Brotli: D:/msys64/opt/include

-- Found LCMS2: D:/msys64/opt/lib/liblcms2.a (found suitable version "2.13", minimum required is "2.13")

-- Found ZLIB: D:/msys64/opt/lib/libz.a (found version "1.2.12")

-- Found PNG: D:/msys64/opt/lib/libpng.a (found version "1.6.38.git")

-- Performing Test COMPILER_HAS_DEPRECATED_ATTR

-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success

-- Could NOT find GIF (missing: GIF_LIBRARY GIF_INCLUDE_DIR) (Required is at least version "5.1")

-- Found JPEG: D:/msys64/opt/lib/libjpeg.a (found version "62")

-- Checking for module 'OpenEXR'

-- Package 'OpenEXR', required by 'virtual:world', not found

-- Building with JPEGXL_VERSION=ff65c387 (auto-updated)

-- Building tools:

-- Configuring done

-- Generating done

— Reply to this email directly, view it on GitHub https://github.com/nyfair/mpv-win64/issues/14#issuecomment-1120937981, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKH7M7JCE7KAQLJCIEDDLLVJDTXXANCNFSM5VKQ6SBQ . You are receiving this because you commented.Message ID: @.***>

eko5624 commented 2 years ago

删了toolchain里的pthread.h后还不行,log如下,只能尝试别的法子了。

-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: D:/ucrt64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: D:/ucrt64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- CMAKE_SYSTEM_PROCESSOR is AMD64
-- Performing Test CXX_FUZZERS_SUPPORTED
-- Performing Test CXX_FUZZERS_SUPPORTED - Failed
-- Performing Test CXX_CONSTRUCTOR_ALIASES_SUPPORTED
-- Performing Test CXX_CONSTRUCTOR_ALIASES_SUPPORTED - Failed
-- Performing Test CXX_MACRO_PREFIX_MAP
-- Performing Test CXX_MACRO_PREFIX_MAP - Success
-- Performing Test CXX_NO_RTTI_SUPPORTED
-- Performing Test CXX_NO_RTTI_SUPPORTED - Success
-- Found PkgConfig: D:/msys64/usr/bin/pkg-config.exe (found version "1.8.0") 
-- Compiled IDs C:GNU, C++:GNU
-- Looking for pthread.h
-- Looking for pthread.h - not found
-- Found Threads: TRUE  
-- Performing Test ATOMICS_LOCK_FREE_INSTRUCTIONS
-- Performing Test ATOMICS_LOCK_FREE_INSTRUCTIONS - Success
-- Found HWY: D:/msys64/opt/lib/libhwy.a (found suitable version "0.16.0", minimum required is "0.15.0") 
-- Checking for module 'libbrotlicommon'
--   Package 'libbrotlicommon', required by 'virtual:world', not found
-- Checking for module 'libbrotlienc'
--   Package 'libbrotlienc', required by 'virtual:world', not found
-- Checking for module 'libbrotlidec'
--   Package 'libbrotlidec', required by 'virtual:world', not found
-- Found Brotli: D:/msys64/opt/include  
-- Found LCMS2: D:/msys64/opt/lib/liblcms2.a (found suitable version "2.13", minimum required is "2.13") 
-- Found ZLIB: D:/msys64/opt/lib/libz.a (found version "1.2.12") 
-- Found PNG: D:/msys64/opt/lib/libpng.a (found version "1.6.38.git") 
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
-- Could NOT find GIF (missing: GIF_LIBRARY GIF_INCLUDE_DIR) (Required is at least version "5.1")
-- Found JPEG: D:/msys64/opt/lib/libjpeg.a (found version "62") 
-- Checking for module 'OpenEXR'
--   Package 'OpenEXR', required by 'virtual:world', not found
-- Building with JPEGXL_VERSION=ff65c387 (auto-updated)
-- Building tools: 
-- Configuring done
-- Generating done
nyfair commented 2 years ago

等等,如果是这样那你得先确认问题的确出在libjxl上,看这log它确实没使用pthread 另外libpng和libjpeg是cjxl用来转换编码时使用的,你根本不需要加入吧

eko5624 commented 2 years ago

你帮我看一下我写的libjxl那个PKGBUILD是不是写的不对。因为加入了好几件组件的编译。比如brotli highway lcms libjpeg libpng zlib这些。

因为不知道哪些组件是libjxl必须的,所以我按照shinchiro的代码把以上几个都加进去了,也极有可能是以上几个组件的依赖问题。

eko5624 commented 2 years ago

我尝试用msvc静态编译了libjxl。不过在编译ffmpeg中-enable-libjxl默认链接的是动态链接库(链接的是jxl.lib和jxl_threads.lib。这2个文件貌似是动态lib库文件),brotli也默认是动态链接。所以最终编译成的mpv需要依赖jxl_threads.dll jxl.dll libbrotlicommon.dll libbrotlidec.dll libbrotlienc.dll这5个动态库。 可是我想在ffmpeg中静态链接libjxl和brotli. 我该做哪些修改呢。我把静态编译成的libjxl的lib目录文件贴出来,您看一下。

QQ20220514-211645@2x
nyfair commented 2 years ago

visual studio打开cmake生成的工程文件后不是可以自己指定编译啥的麽,还有图形化的cmake-gui 另外ffmpeg不关心什么动态静态,它只认pkgconfig找到的链接参数

nyfair commented 2 years ago

自己用gcc-mcf编译了下libjxl,没改过一行代码,没发现有你提到的问题 image cmake设置,其中lcms2用的我自己这个项目里的,brotli和highway自己下载放到third_pary目录下 enable_tools和gflags是给cjxl djxl命令行用的,编译lib不需要 image

eko5624 commented 2 years ago

@nyfair 我发现只是依赖libgcc_s_seh-1.dll这个文件,并不依赖libwinpthread-1.dll。是avcodec-59.dll这个文件依赖libgcc_s_seh-1.dll。 39B51BE6E3AD1FBFFBC057B2E339B18B

nyfair commented 2 years ago

如果这是这个,建议检查下使用的各种三方补丁里有没有什么奇奇怪怪的cflags和ldflags

eko5624 commented 2 years ago

@nyfair 我贴出libjxl的编译代码,您帮我看一下是哪里的问题。

pkgname=libjxl-dev
pkgver=0.6.1
pkgrel=1
pkgdesc='JPEG XL image format reference implementation'
arch=('x86_64')
url="https://github.com/libjxl/libjxl/"
makedepends=('brotli-dev')
license=('BSD')
source=("git+https://github.com/libjxl/libjxl")
md5sums=('SKIP')

build() {
  # Fix AVX2 related crash due to unaligned stack memory
  # export CXXFLAGS="$CXXFLAGS -Wa,-muse-unaligned-vector-move"
  # export CFLAGS="$CFLAGS -Wa,-muse-unaligned-vector-move"

  cd $srcdir/libjxl
  git submodule update --init --recursive --depth 1 --recommend-shallow third_party/{highway,skcms}  
  rm -rf build && mkdir build && cd build
  $CMAKE .. -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=/opt -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_SHARED_LIBS=OFF \
    -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
    -DJPEGXL_STATIC=OFF \
    -DBUILD_TESTING=OFF \
    -DJPEGXL_EMSCRIPTEN=OFF \
    -DJPEGXL_BUNDLE_LIBPNG=OFF \
    -DJPEGXL_ENABLE_TOOLS=OFF \
    -DJPEGXL_ENABLE_VIEWERS=OFF \
    -DJPEGXL_ENABLE_DOXYGEN=OFF \
    -DJPEGXL_ENABLE_EXAMPLES=OFF \
    -DJPEGXL_ENABLE_MANPAGES=OFF \
    -DJPEGXL_ENABLE_JNI=OFF \
    -DJPEGXL_ENABLE_PLUGINS=OFF \
    -DJPEGXL_ENABLE_DEVTOOLS=OFF \
    -DJPEGXL_ENABLE_BENCHMARK=OFF \
    -DJPEGXL_ENABLE_SJPEG=OFF \
    -DJPEGXL_FORCE_SYSTEM_BROTLI=ON 
  $CMAKE --build .
}

package() {
  cd $srcdir/libjxl/build
  $CMAKE --install . --prefix=$pkgdir/opt
  sed -i 's/Libs.private: -lm/Libs.private: -lm -lstdc++/' $pkgdir/opt/lib/pkgconfig/libjxl.pc  
  sed -i 's/Libs.private: -lm/Libs.private: -lm -lstdc++/' $pkgdir/opt/lib/pkgconfig/libjxl_threads.pc 
}

下面是ffmpeg的编译代码

# Maintainer: nyfair <nyfair2012@gmail.com>
pkgname=(ffmpeg-dev ffmpeg)
pkgver=5.0.1
pkgrel=1
pkgdesc='Complete and free Internet live audio and video solution'
arch=('x86_64')
url="http://ffmpeg.org/"
makedepends=('nasm' 'brotli-dev' 'lame-dev' 'libjxl-dev' 'dav1d-dev' 'libvorbis_aotuv-dev' 'opus-dev' 'ffnvcodec-dev' 'vapoursynth-dev')
license=('LGPL')
source=("git+https://github.com/FFmpeg/FFmpeg")
md5sums=('SKIP')

build() {
  CARGS="--target-os=mingw32 --arch=x86_64 --disable-debug --disable-doc \
         --enable-gpl --enable-version3 --enable-nonfree --enable-zlib --pkg-config-flags=--static \
         --disable-ffplay --disable-ffprobe --disable-avdevice --enable-shared \
         --disable-pthreads --enable-w32threads"
}

package_ffmpeg-dev() {
  cd $srcdir/FFmpeg
  ./configure prefix=/opt $CARGS --extra-libs="-lssp" \
    --disable-mediafoundation --enable-libdav1d --enable-libjxl --enable-libmp3lame --enable-libvorbis --enable-libopus \
    --disable-decoder=libvorbis --disable-decoder=libopus \
    --disable-encoder=opus --disable-encoder=vorbis --enable-vapoursynth
  make DESTDIR=$pkgdir install
  rm -rf $pkgdir/opt/bin $pkgdir/opt/share $pkgdir/opt/lib/*.def
}

package_ffmpeg() {
  depends=('vapoursynth' 'mcfgthread')
  export PKGEXT='.pkg.tar.xz'
  cd $srcdir/FFmpeg
  make DESTDIR=$pkgdir install
  rm -rf $pkgdir/opt/bin/*.lib $pkgdir/opt/share $pkgdir/opt/include $pkgdir/opt/lib
  strip $pkgdir/opt/bin/*
}
nyfair commented 2 years ago

其实看不太懂,单纯给点建议

  1. -lstdc++ -lgcc_eh 这些额外的lib是干嘛用的?
  2. skcms我不了解,lcms2没啥问题,一个项目同时使用两个相同作用的库很奇怪
  3. brotli自带的编译脚本很啰嗦,而直接用libjxl编译没发现问题,既然你的最终目的是静态库,那就不要简单问题复杂化
  4. 建议先使用cmake自带的gui看下默认参数,去掉各种不了解的参数

brotli早就不是什么数据压缩业界的版本答案了,明年又会有新的一波人拿h.266/zstd或者其他什么新玩具搞新格式

eko5624 commented 2 years ago

@nyfair 1.这里加Libs.private: -lm -lstdc++是因为不加的话编译ffmpeg时pkgconfig会提示这个错误:ffmpeg configure failed because libjxl >= 0.7.0 not found using pkg-config。shinchiro在这里提交一次pr,不过未被采纳。https://github.com/libjxl/libjxl/pull/1444。 至于-lgcc_eh是我测试时胡乱加的,没卵用。 2.skcms貌似和lcms2功能差不多,我觉得可以二选一的。启用skcms的话就可以不启用lcms2了,反之启用lcms2就禁用skcms。无论启用二者哪一个测试下来结果也都一样。 3.直接用libjxl编译brotli我也试过。但生成的libjxl.pc是这样的:

prefix=D:/msys64/opt
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: libjxl
Description: Loads and saves JPEG XL files
Version: 0.7.0
Requires.private: libhwy libbrotlicommon libbrotlienc libbrotlidec
Libs: -L${libdir} -ljxl
Libs.private: -lm -lstdc++
Cflags: -I${includedir}
Cflags.private: -DJXL_STATIC_DEFINE

需要用到 libbrotlicommon libbrotlienc libbrotlidec这三个文件。可是编译libjxl时产生的lib文件夹里并没有这3个文件的影子。所以单独把brotli摘出来编译的。

eko5624 commented 2 years ago

@nyfair 问题解决了,只需在编译ffmpeg的PKGBUILD里加一句--extra-ldflags="-static -static-libgcc -static-libstdc++"就行了。

参考来源:https://www.cnblogs.com/Bob-wei/p/8435000.html