Distribute a program compiled with MinGW g++

前端 未结 5 875
夕颜
夕颜 2021-01-05 08:31

Let\'s say I have created and compiled a simple program using the MinGW 64 (g++ compiler). Running this program on my computer and looking in Process Explorer for what DLL f

5条回答
  •  走了就别回头了
    2021-01-05 09:16

    For complicated projects where you're not exactly sure which DLL files need to be included to distribute your application, I made a handy dandy Bash script (for MSYS2 shells) that can tell you exactly what DLL files you need to include. It relies on the Dependency Walker binary.

    #!/usr/bin/sh
    
    depends_bin="depends.exe"
    target="./build/main.exe" # Or wherever your binary is
    temp_file=$(mktemp)
    output="dll_list.txt"
    
    MSYS2_ARG_CONV_EXCL="*" `cygpath -w $depends_bin` /c /oc:`cygpath -w $temp_file` `cygpath -w $target`
    cat $temp_file | cut -d , -f 2 | grep mingw32 > $output
    
    rm $temp_file
    

    Note that this script would need to be modified slightly for use in regular MSYS (the MSYS2_ARG_CONV_EXCL and cygpath directives in particular). This script also assumes your MinGW DLL files are located in a path which contains MinGW.

    You could potentially even use this script to automatically copy the DLL files in question into your build directory as part of an automatic deploy system.

提交回复
热议问题