How to Fix no acceptable C compiler found in $PATH on Mac OS X Lion

本文介绍如何解决在MacOSX Lion上编译Memcache或wget时遇到的'no acceptable C compiler found in $PATH'错误。通过安装Xcode及额外组件可以轻松解决该问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

How to Fix no acceptable C compiler found in $PATH on Mac OS X Lion

Posted on May 16th, 2012  phpguru  30 comments

If you have a need to compile Memcache or wget on Mac OS X Lion and are wondering why you are getting the error

no acceptable C compiler found in $PATH

on Mac OS X Lion, you’re not alone.

Thanks to this post, I was able to fix my problem. Here are the steps.

  1. Run App Store
  2. Search for Xcode – it’s a free install from Apple
  3. Wait for awhile. Took 30min to download for me on a 20mbps connection
  4. Authenticate and let Xcode install. Once Xcode is installed you may be thinking you’re done. You would be wrong!
  5. Launch Xcode and run the mobile toolkit update (you can’t skip it, deal with it)
  6. Go to Xcode Preferences or press ⌘, (Command-comma)
  7. Click the Downloads tab -> Components list as shown below
    How To Fix C compiler error on Mac OS X Lion
  8. On the last row of the available downloads are the Command Line tools. Install them.
### 解决方案 当遇到 `configure: error: no acceptable C compiler found in $PATH` 的错误时,通常是因为系统缺少必要的C编译器或者其路径未被正确配置到环境变量 `$PATH` 中。以下是详细的解决方法: #### 1. 安装 GCC 编译器 如果系统中尚未安装GCC编译器,则可以通过包管理工具进行安装。 对于基于RPM的Linux发行版(如CentOS, RHEL),可以使用以下命令来安装GCC: ```bash yum install -y gcc ``` 对于Debian及其衍生版本(如Ubuntu),则应执行以下命令: ```bash apt-get update && apt-get install -y build-essential ``` 上述命令会自动安装GCC以及其他开发所需的工具链[^2]。 #### 2. 验证 GCC 是否已正确安装 通过运行以下命令验证GCC是否已经成功安装以及当前版本号: ```bash gcc --version ``` 如果没有返回任何有效信息或显示未知命令,则说明GCC可能并未完全安装好或者是环境变量设置有问题[^3]。 #### 3. 检查并更新 PATH 变量 即使GCC已被安装,但如果它的二进制文件所在的目录不在系统的默认搜索路径里,也会引发此问题。因此需要确认 `/usr/bin` 或者其他实际存放gcc的位置已经被加入到了用户的PATH当中。可以在终端输入下面这条指令查看现有定义: ```bash echo $PATH ``` 假如发现缺失对应项,那么就需要手动将其添加进去。临时修改可通过直接追加方式实现;而永久性的调整建议编辑个人shell profile脚本比如`.bashrc` 文件,在其中增加类似这样的行: ```bash export PATH=$PATH:/path/to/gcc/directory ``` 记得保存更改后再重新加载该配置文档以便生效: ```bash source ~/.bashrc ``` #### 4. 卸载旧版本再重试 (仅适用于特定情况) 有时可能是由于先前存在不兼容的老版本干扰所致,此时先尝试移除它们然后再按照前述步骤操作可能会有所帮助。例如针对某些RedHat系平台上的实例描述过的方法就是如此处理的。 --- ### 总结 综上所述,“no acceptable C compiler found in $PATH”的根本原因是缺乏合适的C语言编译程序或是访问权限受限于不当设定的环境参数。遵循本文给出的具体指导方针——即确保有最新稳定发布的GNU Compiler Collection可用,并且让操作系统能够识别它所在位置即可顺利解决问题[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值