lhmouse / mcfgthread

Cornerstone of the MOST efficient std::thread on Windows for mingw-w64
https://gcc-mcf.lhmouse.com/
Other
277 stars 28 forks source link

关于静态编译的问题 #67

Closed eko5624 closed 2 years ago

eko5624 commented 2 years ago

谢谢您的卓越贡献,我有个问题我想咨询下。我用gcc-mcf.lhmouse.com/mingw-w64-gcc-mcf_20220606_12.1.1_x64-ucrt_fe50eb9db7d0a4c4ba907456ca4c9b5b3403a0fb.7z您这个toolchain编译mpv。但编译生成的mpv.exe需要依赖libmcfgthread-1.dll这个动态库。有没有办法把libmcfgthread-1.dll静态编译进mpv呢。这样的话只需要一个mpv.exe单文件就可以运行了。

附仓库地址:https://github.com/eko5624/mpv-winbuild

lhmouse commented 2 years ago

静态链接需要给 GCC 指定 -static 参数。

eko5624 commented 2 years ago
pkgname=mpv
pkgver=0.34.1
pkgrel=1
pkgdesc='a free, open source, and cross-platform media player'
arch=('x86_64')
url='https://mpv.io/'
makedepends=("yasm"  
             "lame-dev" 
             "libjxl-dev" 
             "brotli-dev" 
             "highway-dev" 
             "dav1d-dev" 
             "libvorbis_aotuv-dev" 
             "opus-dev" 
             "ffnvcodec-dev"
             "ffmpeg-dev" 
             "luajit2-dev" 
             "ffnvcodec-dev" 
             "freetype2-dev" 
             "fribidi-dev" 
             "harfbuzz-dev" 
             "libass-dev" 
             "lcms2-dev"
             "libbluray-dev" 
             "libdvdcss-dev" 
             "libdvdread-dev" 
             "libdvdnav-dev" 
             "libepoxy-dev" 
             "libplacebo-dev"
             "shaderc-dev" 
             "spirv-cross-dev"
             "vapoursynth-dev" 
             "vulkan-dev")
license=('GPL3')
source=("git+https://github.com/mpv-player/mpv")
md5sums=('SKIP')

build() {
  cd $srcdir/mpv
  LDFLAGS="$LDFLAGS -lstdc++ -lssp"
  meson build --buildtype=release -Dprefix=/opt --prefer-static -Db_lto=true -Db_ndebug=true
  meson compile -C build 
}

package() {
  export PKGEXT='.pkg.tar.xz'
  mkdir -p $pkgdir/opt/bin  
  cd $srcdir/mpv/build
  mv mpv.exe $pkgdir/opt/bin
  mv generated/mpv.com $pkgdir/opt/bin
}

-static应该加到哪个地方呢?

lhmouse commented 2 years ago

通常应当是 @LDFLAGS@ 里。

eko5624 commented 2 years ago

非常棒,按照您说的修改了一下问题解决了,太感谢了~ 改成这样:LDFLAGS="$LDFLAGS -static -lstdc++ -lssp"

eko5624 commented 2 years ago

@lhmouse LDFLAGS="$LDFLAGS -static" doesn't work now. Any ideas?

leduo@DESKTOP-PUS34U7 MINGW64 ~
$ ldd /c/Users/leduo/Downloads/git-mpv-20220914-e302c9b/mpv.exe
        ntdll.dll => /c/Windows/SYSTEM32/ntdll.dll (0x7ffe19590000)
        KERNEL32.DLL => /c/Windows/System32/KERNEL32.DLL (0x7ffe19290000)
        KERNELBASE.dll => /c/Windows/System32/KERNELBASE.dll (0x7ffe16ef0000)
        ADVAPI32.dll => /c/Windows/System32/ADVAPI32.dll (0x7ffe194a0000)
        msvcrt.dll => /c/Windows/System32/msvcrt.dll (0x7ffe181a0000)
        sechost.dll => /c/Windows/System32/sechost.dll (0x7ffe18c10000)
        RPCRT4.dll => /c/Windows/System32/RPCRT4.dll (0x7ffe18070000)
        bcrypt.dll => /c/Windows/System32/bcrypt.dll (0x7ffe16ec0000)
        CFGMGR32.dll => /c/Windows/System32/CFGMGR32.dll (0x7ffe17450000)
        ucrtbase.dll => /c/Windows/System32/ucrtbase.dll (0x7ffe171f0000)
        AVRT.dll => /c/Windows/SYSTEM32/AVRT.dll (0x7ffe10ee0000)
        GDI32.dll => /c/Windows/System32/GDI32.dll (0x7ffe18cb0000)
        win32u.dll => /c/Windows/System32/win32u.dll (0x7ffe171c0000)
        gdi32full.dll => /c/Windows/System32/gdi32full.dll (0x7ffe16db0000)
        msvcp_win.dll => /c/Windows/System32/msvcp_win.dll (0x7ffe174a0000)
        USER32.dll => /c/Windows/System32/USER32.dll (0x7ffe17680000)
        IMM32.dll => /c/Windows/System32/IMM32.dll (0x7ffe18d90000)
        ole32.dll => /c/Windows/System32/ole32.dll (0x7ffe17db0000)
        dwmapi.dll => /c/Windows/SYSTEM32/dwmapi.dll (0x7ffe14870000)
        combase.dll => /c/Windows/System32/combase.dll (0x7ffe17a50000)
        OLEAUT32.dll => /c/Windows/System32/OLEAUT32.dll (0x7ffe18240000)
        SETUPAPI.dll => /c/Windows/System32/SETUPAPI.dll (0x7ffe18dc0000)
        SHELL32.dll => /c/Windows/System32/SHELL32.dll (0x7ffe184c0000)
        WS2_32.dll => /c/Windows/System32/WS2_32.dll (0x7ffe18000000)
        OPENGL32.dll => /c/Windows/SYSTEM32/OPENGL32.dll (0x7ffdf8c60000)
        VERSION.dll => /c/Windows/SYSTEM32/VERSION.dll (0x7ffe16320000)
        GLU32.dll => /c/Windows/SYSTEM32/GLU32.dll (0x7ffe127b0000)
        WSOCK32.dll => /c/Windows/SYSTEM32/WSOCK32.dll (0x7ffe127e0000)
        WINMM.dll => /c/Windows/SYSTEM32/WINMM.dll (0x7ffe12b50000)
        libgcc_s_seh-1.dll => /mingw64/bin/libgcc_s_seh-1.dll (0x7ffe08ea0000)
        libwinpthread-1.dll => /mingw64/bin/libwinpthread-1.dll (0x7ffe12790000)

把libgcc_s_seh-1.dll和libmcfgthread-1.dll都复制到mpv文件夹里才解决问题。怎么才能去掉对libgcc_s_seh-1.dll和libmcfgthread-1.dll的依赖呢?

搜到别人遇到的同类问题,他们加LDFLAGS="-static"就解决问题了。可是对于我们这个toolchain不管用。 https://github.com/mpv-player/mpv-build/issues/195#issuecomment-1242899286

lhmouse commented 2 years ago

LDFLAGS is a variable specific to GNU make. You should examine the actual command line which invokes the linker (typically g++) to ensure -static actually exists there.

eko5624 commented 2 years ago

==> Starting build()...
576
The Meson build system
577
Version: 0.63.99
578
Source dir: D:\a\mpv-win64\mpv-win64\mpv\src\mpv
579
Build dir: D:\a\mpv-win64\mpv-win64\mpv\src\mpv\build
580
Build type: native build
581
Project name: mpv
582
Project version: 0.34.0-UNKNOWN
583
C compiler for the host machine: gcc (gcc 12.1.1 "gcc (GCC with MCF thread model, built by LH_Mouse) 12.1.1 20220809")
584
C linker for the host machine: gcc ld.bfd 2.38
585
Host machine cpu family: x86_64
586
Host machine cpu: x86_64
587
Program python3 found: YES (C:\hostedtoolcache\windows\Python\3.10.7\x64\python3.EXE)
588
Found pkg-config: D:\ucrt64\bin\pkg-config.EXE (1.8.0)

Please take a look, thanks. https://github.com/eko5624/mpv-win64/actions/runs/3052634482/jobs/4922367736

lhmouse commented 2 years ago

I know nothing about meson. You should try making meson print the full command line, with which it invokes the linker.

eko5624 commented 2 years ago

问题解决了,是最新版vulkan的问题,和工具链无关。