TextMate 2:尝试编译和运行简单的C程序时出错

Tod*_*orf 3 c xcode textmate gcc

建立

OS X 10.8
Xcode 4.4.1安装了
TextMate 2 -r9283


摘要

在安装了Xcode 4.4的10.8上的TextMate2中编译并运行一个简单的C程序会给出路径错误,然后是编译器错误,然后是链接器错误.


再现的步骤

  1. 创建一个test.c在TextMate2中调用的文件并保存到桌面
  2. 将此程序粘贴到test.c文件中:

    #include <stdio.h>

    int main(int argc, char const *argv[]) { printf("Hello World\n"); return 0; }

  3. 类型command-R运行


预期结果

stdout运行程序的输出


实际结果

TextMate输出面板显示此PATH错误:

Can't find “gcc” on PATH.

The current PATH is:

    /usr/bin
    /bin
    /usr/sbin
    /sbin
    /Users/itod/Library/Application Support/TextMate/Managed/Bundles/Bundle Support.tmbundle/Support/shared/bin
Please add the directory containing “gcc” to PATH in TextMate's Shell Variables preferences.
Run Code Online (Sandbox Code Playgroud)

然后这个编译错误:

cc1: error: stdio.h: No such file or directory
Run Code Online (Sandbox Code Playgroud)

然后这个链接器错误:

ld: library not found for -lcrt1.10.6.o
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)


如何修复这些错误并在OS X 10.8中的TextMate 2中成功编译和运行C程序?

Tod*_*orf 6

要在OS X 10.8上构建和运行C程序的TextMate 2,您必须在TextMate中使用几个环境变量.


脚步

  1. 启动TextMate2
  2. 转到首选项(?,)>变量
  3. 在下表中输入以下名称/值对,并确保所有三对都"已选中"

PATH - $PATH:/Applications/Xcode.app/Contents/Developer/usr/bin/

C_INCLUDE_PATH - /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include/

LIBRARY_PATH - /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/lib/

在此输入图像描述