MINGW64中找不到GCC的解决方法

MINGW64中找不到GCC的解决方法

一、问题描述

我在MINGW64下运行了下面的命令,想要配置ffmpeg以便后续进行编译:

./configure --prefix=../lib --disable-static --enable-shared

不幸的是返回了这样一条提示

33132@Midsummer MINGW64 /d/ToolChainlib/FFmpeg/ffmpeg-4.4.4
$ ./configure --prefix=../lib --disable-static --enable-shared
gcc is unable to create an executable file.
If gcc is a cross-compiler, use the --enable-cross-compile option.
Only do this if you know what cross compiling means.
C compiler test failed.

If you think configure made a mistake, make sure you are using the latest
version from Git.  If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.libera.chat.
Include the log file "ffbuild/config.log" produced by configure as this will help
solve the problem.

导致上述提示出现的直接原因是MSYS2 MINGW64环境没找到GCC编译器,但是很奇怪,我在windows自带的控制台中运行能找到GCC编译器:

C:\Users\33132>gcc --version
gcc (Rev3, Built by MSYS2 project) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

二、解决方案

查阅了一些资料发现MSYS2 MINGW64环境和windows本身的环境变量不通用,那么我们需要手动指定该环境的环境变量,以下是操作步骤:

  1. 寻找GCC编译器位置
    C:\Users\33132>where gcc
    D:\Software\Compiler\ucrt64\bin\gcc.exe
    
  2. 添加环境变量

    上面得到了GCC编译器的位置是:

    D:\Software\Compiler\ucrt64\bin\gcc.exe
    

    那么我们将整个工具链的目录设置为环境变量,其工具链目录转换到MSYS2 MINGW64环境中,是下面这样的:

    /d/Software/Compiler/ucrt64/bin
    

    MSYS2 MINGW64环境其实是提供了一个类 linux 的 shell 环境,因此我们各种操作和linux是差不多的,那么我们用记事本打开配置文件

    notepad.exe ~/.bashrc
    

    在文档的最后面添加一行,表示添加工具链的目录为环境变量:

    export PATH="/d/Software/Compiler/ucrt64/bin:$PATH"
    

    然后Ctrl+S快捷键保存,然后关闭记事本(不关闭记事本,命令行没法继续执行)。之后使用以下命令让配置文件立即生效:

    source ~/.bashrc
    
  3. 测试效果
    33132@Midsummer MINGW64 /d/ToolChainlib/FFmpeg/ffmpeg-4.4.4
    $ gcc --version
    gcc.exe (Rev3, Built by MSYS2 project) 13.2.0
    Copyright (C) 2023 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    

    出现以上类似的结果,则表示gcc编译器找到了,至此,over。

三、心灵的救赎

在这里插入图片描述

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值