Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?
like image 818
Todd Ditchendorf Avatar asked Feb 16 '26 03:02

Todd Ditchendorf


2 Answers

To get TextMate 2 building and running C programs on OS X 10.8, you must udpate several environment variables in TextMate.


STEPS

  1. Launch TextMate2
  2. Go to Preferences (⌘,) > Variables
  3. Enter the following name/value pairs in the table below and make sure all three pairs are "checked"

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/

enter image description here

like image 54
Todd Ditchendorf Avatar answered Feb 18 '26 18:02

Todd Ditchendorf


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.

like image 21
dajobe Avatar answered Feb 18 '26 20:02

dajobe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!