How to build the environment of MSYS for the crossing compiler?

本文档详细介绍了如何为交叉编译构建MSYS环境,包括创建必要的文件夹、下载并安装各种工具包如msys CORE、coreutils、bash等,以及设置MINGW子目录所需的步骤。

How to build the environment of MSYS for the crossing compiler?

 

[Build MSYS root folder]

 

[1. Create cross-compiler folder in your proper path]

[2. Download msysCORE-1.0.11-20080826.tar.gz and extract it into cross-compiler folder]

[3. Download coreutils-5.97-MSYS-1.0.11-snapshot.tar.bz2  and extract it into cross-compiler folder]

[4. Download bash-3.1-MSYS-1.0.11-1.tar.bz2 and extract it into cross-compiler folder]

[5. Download perl-5.6.1-MSYS-1.0.11-1.tar.bz2   and extract into to cross-compiler folder]

[6. Downloadcrypt-1.1-1-MSYS-1.0.11-1.tar.bz2 and extract into cross-compiler folder

[7. Create mingw sub-folder]

[8. Copy /etc/fstab.sample into /etc/fstab and map XXX/cross-compiler/mingw to /mingw ]

[9. Edit /msys.bat and add call "XXX/VC/bin/vcvars32.bat" in the beginning position]

[10. Download m4-1.4.13.tar.gz and install it into "/"]


[Build MINGW sub-folder]

 

[1. Download mingwrt-3.15.2-mingw32-dev.tar.gz and extract it into mingw folder]

[2. Download w32api-3.13-mingw32-dev.tar.gz  and extract it into mingw folder]

[3. Download gcc-4.3.0-20080502-mingw32-alpha-bin.tar.gz and extract it into mingw folder]

[4. Download flex-2.5.33-MSYS-1.0.11-1.tar.bz2 and extract it into mingw folder]

[5. Download zlib-1.2.3-MSYS-1.0.11-1.tar.bz2 and extract it into mingw folder]. If readers don't like depending on msy-z.dll, msys-1.0.dll for programs using zlib, please download source codes of zlib to 'make install' in the http://www.zlib.net/ website.

[6. Download autoconf-2.61-MSYS-1.0.11-1.tar.bz2 and extract it into mingw folder ]

[7. Download mingw-install-20060210.tar.gz and extract automake-1.9.6-20050907-1.tar.gz into mingw folder ]

[8. Download bison-2.3-MSYS-1.0.11-1.tar.bz2 and extract it into mingw folder]

 

[9. Download gettext-0.16.1-1-bin.tar.bz2 and extract it into mingw folder]

[10. Download libiconv-1.11-MSYS-1.0.11-1.tar.bz2 and extract it into mingw folder]

[11. Download libtool1.5-1.5.25a-20070701-MSYS-1.0.11-1.tar.bz2 and extract it into mingw folder]

[12. Download regex-0.12-MSYS-1.0.11-1.tar.bz2 and extract it into mingw folder]

[13. Download pthread and copy pthread.h, sched.h, semaphore.h into /mingw/include; copy pthreadGC2.dll into /mingw/bin; copy libpthreadGC2.a into /mingw/lib/libpthread.a]

[14. Download binutils-2.19.1-mingw32-bin.tar.gz  and extract it into mingw folder]

[15. Download pkg-config_0.23-3_win32.zip and extract it into mingw folder ]

[16. Download glib_2.20.4-1_win32.zip and extract bin/libglib-2.0-0.dll into mingw/bin folder ]

[17. Download moztools-static.zip , and extract moztools/bin/nsinstall.exe into mingw/bin folder ]

 

[Build GMP and MPFR sub-folders]

 

[1. Download gmp-4.2.4.tar.gz and extract it into cross-compiler folder]

[2. Download mpfr-2.4.1.tar.bz2 and extract it into cross-compiler folder]

 

If readers do not like compiling them by themselves, please download them

mingw32-gmp-4.2.4-2 and mingw32-mpfr-2.3.2-2 .

Moreover, the related updates can be found in the webpage: http://sourceforge.net/project/showfiles.php?group_id=204414

 

[Build YASM sub-folder]

 

[1. Download yasm-0.8.0.tar.gz and extract it into cross-compiler folder]

 

[Build NASM sub-folder]

 

[1. Download nasm-2.06rc1.tar.bz2 and extract it into cross-compiler folder]

 

[Summarization]

 

1. It only focuses on how to build the environment. Please refer to “How to build the GCC-4.3.3 in MinGW?

2. Some packages of MSYS and MinGW are not the latest version. If readers make full use of them, please update the related tool-chains at the same time, otherwise the environment maybe has risks.

 

[Appendix: Troubleshoot]

1. How to compile SDL in MINGW?

2. How to update YASM from 0.7.2 to 0.8.0 in MinGW?

3. How to compile and install external libs of FFMPEG?



<think> 我们之前讨论过在MSYS2中为Android编译FFmpeg的配置,但现在用户遇到了一个特定的错误提示:“Native MSYS builds are discouraged, please use the MINGW environment”。这个提示表明用户可能错误地在MSYS2的MSYS环境中进行编译,而推荐的做法是使用MINGW64(或MINGW32)环境。 根据引用[1]:“Building for the MSYS environment is discouraged, MSYS2 provides a full MinGW-w64 environment”。因此,我们需要在MSYS2中启动MINGW64环境(或MINGW32,根据你的系统架构)来执行编译。 解决方案: 1. 确保你已经正确安装了所需的MinGW工具链(在MSYS2中)。 2. 运行MSYS2时,不要使用“MSYS”(如msys2_shell.cmd),而应该使用“MinGW x64”(即mingw64.exe)或“MinGW x86”(mingw32.exe)环境。通常,我们使用64位的环境,即“MinGW x64”。 具体步骤: a) 打开MSYS2安装目录,找到并运行`mingw64.exe`(64位)或`mingw32.exe`(32位)。或者,如果你已经将MSYS2的bin目录添加到系统PATH中,你也可以通过命令行启动: ```bash msys2_shell.cmd -mingw64 # 启动MinGW 64位环境 ``` b) 在该环境中,检查gcc的版本,确认是MinGW版本: ```bash gcc --version ``` 应该显示类似这样的信息:`gcc.exe (Rev10, Built by MSYS2 project) ...`,并且注意不是msys-gcc。 c) 然后,在这个MinGW环境中重新执行你的FFmpeg编译配置和编译命令。 此外,请确保你的环境变量(尤其是NDK的路径)在这个MinGW环境中也是正确设置的。因为MinGW环境可能不会自动继承你在MSYS环境中设置的环境变量,所以你可能需要重新设置。 总结:这个错误信息是因为你在MSYS环境下进行编译,而FFmpeg的编译应该使用MinGW环境(即mingw64.exe或mingw32.exe启动的环境)以避免与MSYS环境的POSIX模拟层产生不必要的交互。 因此,请切换到MinGW64环境,重新设置环境变量(如ANDROID_NDK等),然后重新配置和编译。 注意:在MinGW环境中,路径的表示方式与MSYS环境不同。在MinGW环境中,你可以直接使用Windows风格的路径(如C:/Android/ndk),或者使用Unix风格但要注意根目录的映射(在MinGW环境中,通常根目录`/`对应MSYS2的安装目录,而Windows的盘符可以通过`/c/`来访问,例如`/c/Android/ndk`)。因此,在设置环境变量时,建议使用Windows风格的路径(带盘符)或者使用Unix风格但使用`/c/`这样的形式。 例如,设置NDK路径(假设NDK在C:\Android\ndk): ```bash export ANDROID_NDK=C:/Android/ndk # 或者 /c/Android/ndk ``` 重新运行之前的配置和编译命令。 这样,错误提示应该不会再出现。 如果问题仍然存在,请检查你的配置脚本中是否有任何与构建环境相关的选项(比如`--target-os`是否设置为`android`),并确保交叉编译工具链的PATH设置正确。 生成相关问题: §§相关问题§§ 1. 如何切换MSYS2中的不同编译环境(如MSYS、MinGW32、MinGW64)? 2. 在MinGW环境中如何正确设置Windows路径的环境变量? 3. 为什么FFmpeg不建议在MSYS环境下编译? 4. 如何验证当前MSYS2 shell是运行在MinGW64环境下? </think> ### 解决 MSYS2 中编译 FFmpeg 的 "Native MSYS builds are discouraged" 问题 这个错误提示表明你正在错误的 MSYS 环境下编译,而非推荐的 MinGW-w64 环境。以下是完整的解决方案: #### 1. **切换到 MinGW-w64 环境** 在 MSYS2 安装目录中执行: ```bash # 启动 MinGW-w64 64位环境 msys2_shell.cmd -mingw64 # 或启动 32位环境 msys2_shell.cmd -mingw32 ``` > 确保终端标题显示 **MINGW64** 或 **MINGW32**,而非 MSYS[^1] #### 2. **验证 MinGW 环境** ```bash # 检查编译器类型 gcc --version # 正确输出应包含 "Target: x86_64-w64-mingw32" 或类似信息 # 错误输出会显示 "Target: x86_64-pc-msys" ``` #### 3. **修正环境变量** 在 MinGW-w64 环境中设置 NDK 路径: ```bash # 使用 Windows 格式路径(推荐) export ANDROID_NDK="C:/Android/ndk" # 或 Unix 格式 export ANDROID_NDK=/c/Android/ndk ``` #### 4. **更新编译配置** 修改 FFmpeg 配置命令: ```diff ./configure \ --target-os=android \ --arch=aarch64 \ --enable-cross-compile \ --cross-prefix=aarch64-linux-android- \ --cc=aarch64-linux-android21-clang \ + --nm=llvm-nm \ # 强制使用 LLVM 工具链 + --ar=llvm-ar \ # 避免 MinGW 工具冲突 + --extra-cflags="-D__USE_MINGW_ANSI_STDIO" \ # 修复标准库冲突 ...其他参数保持不变... ``` #### 5. **关键原理说明** 1. **环境隔离** MSYS 环境使用 POSIX 模拟层,而 MinGW-w64 直接调用 Windows API[^1],更符合 NDK 工具链需求 $$ \text{MinGW-w64} \supset \text{Windows API} \quad \text{vs} \quad \text{MSYS} \supset \text{Cygwin} \supset \text{POSIX} $$ 2. **路径映射** MinGW-w64 使用特殊路径解析规则: | 路径格式 | 示例 | 对应位置 | |---------|------|---------| | `/c/` | `/c/Android/ndk` | `C:\Android\ndk` | | `/mingw64` | `/mingw64/bin` | MSYS2 安装目录 | 3. **工具链冲突** 错误环境会导致: - MSYS 工具链 → 编译主机程序 - MinGW 工具链 → 编译 Windows 程序 - NDK 工具链 → 编译 Android 程序 必须确保 **仅 NDK 工具链** 生效[^4] #### 6. **验证解决方案** 成功编译后的特征: ```bash file libavcodec.so # 应显示 "ELF 64-bit LSB shared object, ARM aarch64" ``` > **注意**:若仍有警告,添加 `--disable-msys2` 配置项可强制禁用 MSYS 兼容层[^4]
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值