Search code examples
cxcodegcctextmate

TextMate 2: errors when trying to compile and run a simple C program


SETUP

OS X 10.8
Xcode 4.4.1 installed
TextMate 2 -r9283


SUMMARY

Compiling and running a simple C program in TextMate2 on 10.8 with Xcode 4.4 installed gives me a path error, then a compiler error, then a linker error.


STEPS TO REPRO

  1. Create a file called test.c in TextMate2 and save to Desktop
  2. Paste this program in the test.c file:

    #include <stdio.h>

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

  3. Type command-R for Run


EXPECTED RESULT

Output from stdout from running the program


ACTUAL RESULT

The TextMate output panel shows me this PATH error:

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.

then this compiler error:

cc1: error: stdio.h: No such file or directory

then this linker error:

ld: library not found for -lcrt1.10.6.o
collect2: ld returned 1 exit status


How do I fix these errors and successfully compile and run a C program in TextMate 2 in OS X 10.8?


Solution

  • If you want /usr/bin/gcc etc. properly installed, get the "Command Line Tools for Xcode" from the apple developer site http://developer.apple.com/downloads (free download with free ADC account). It will install /usr/bin binaries for all the commandline tools - gcc, ld, etc.