【问题标题】:gcc not working on macgcc 不能在 mac 上运行
【发布时间】:2012-06-01 13:42:08
【问题描述】:

我已将 Xcode 从 v3 更新到 v4.2.1,它运行良好,但作为 C 新手,我想在 Text Wrangler 中编写代码并在 CLI 中使用 gcc 进行编译。

gcc 现在由于某种原因返回 'command not found'(之前运行良好)

经过一番谷歌搜索后,我发现 gcc 已从 /usr/bin 移至 /Developer/usr/bin(我可以在那里看到)。 现在 gcc 在我使用确切路径时运行,但它找不到任何头文件。

my-MacBook-Pro:Desktop user$ /Developer/usr/bin/gcc -o program  program.c 
program.c:15:19: error: stdio.h: No such file or directory
program.c:16:18: error: math.h: No such file or directory
program.c:17:20: error: stdlib.h: No such file or directory
program.c: In function ‘main’:
program.c:33: warning: incompatible implicit declaration of built-in function ‘malloc’
program.c:35: warning: incompatible implicit declaration of built-in function ‘sqrt’
program.c:44: warning: incompatible implicit declaration of built-in function ‘printf’
program.c:65: warning: incompatible implicit declaration of built-in function ‘printf’

非常感谢任何帮助。

【问题讨论】:

    标签: c macos gcc


    【解决方案1】:

    在 Xcode 4.3+ 中,默认情况下不安装“命令行工具”包。您可以在首选项 -> 下载中下载它。请注意,您需要 Lion。

    编辑:

    在 Xcode

    但是,请尝试使用 xcode-select:http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/xcode-select.1.html

    编辑 2: 从Apple dev site. 的下载部分安装 Xcode 命令行工具

    【讨论】:

    • 这不完全正确@Butaca...Xcode 4.3 移除了 /Developer 目录并引入了“命令行工具”安装程序包。
    • 好的。没有设置 Xcode 文件夹。我将其设置为 /Developer/Applications/Xcode.app。现在,:user$ xcode-select -print-path && xcodebuild -version /Developer/Applications/Xcode.app Error: Can't run /Developer/Applications/Xcode.app/usr/bin/xcodebuild(没有这样的文件)。'
    • 在我装有 Snow Leopard 和 Xcode 4.2 的计算机中,xcodebuild 位于 /Developer/usr/bin。也许你应该指向 /Developer/ 而不是 /Developer/Applications/Xcode.app
    • 它的工作,谢谢!从开发站点安装了 Xcode 的命令行工具。 gcc 现在在 /usr/bin 中。虽然现在我在 /Developer/usr/bin 中有另一个副本
    猜你喜欢
    • 1970-01-01
    • 2017-02-20
    • 2012-09-13
    • 1970-01-01
    • 1970-01-01
    • 2021-04-27
    • 1970-01-01
    • 1970-01-01
    • 2015-03-07
    相关资源
    最近更新 更多