【问题标题】:C code won't compile in mac Terminal.C 代码不会在 mac Terminal 中编译。
【发布时间】:2013-01-05 06:21:43
【问题描述】:

每当我在终端中运行 $ /developer/usr/bin/gcc -v main.c -o main 时,我都会收到以下错误:stdio.h: No such file or directory。

这里是main.c文件

#include <stdio.h>

int main(void){
    int i;
    for(i = 0; i<10;i++){
        puts("Hello World!\n");
    }
    return 0;
}

我很擅长 C,但是我通常使用 xcode 来编译任何 C 命令行程序。相同的代码在 Xcode 中运行良好,我做错了什么?

【问题讨论】:

  • 找不到头文件,你可能需要指定你的SDK
  • 如何在终端中做到这一点?我已经找到了我的计算机上 stdio.h 所在的包含文件夹的位置,但我不知道如何让终端在那里查看。
  • 看起来像 isysroot 选项。来自 clang 手册:“例如,-isysroot /Developer/SDKs/MacOSX10.4u.sdk 将在 /Developer/SDKs/MacOSX10.4u.sdk/usr/include/mylib.h 中查找 mylib.h。”跨度>
  • 嗯,这行得通,谢谢,我怎样才能不用每次都输入呢?
  • 另外,如果它已经从 Xcode 构建,您可以在命令行中使用 xcodebuild

标签: c macos gcc terminal


【解决方案1】:

我遇到了同样的问题并修复了它。只需安装 xCode 的命令行工具就可以了!

希望对您有所帮助! :)

【讨论】:

    【解决方案2】:

    你可以使用命令安装xcode工具-

    xcode-select --install
    

    全新安装 xcode 命令行工具将需要 130MB 空间,并且确实需要 sudo 访问权限。

    【讨论】:

      猜你喜欢
      • 2020-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多