How do I compile a .c file on my Mac?

后端 未结 7 1252
忘掉有多难
忘掉有多难 2020-12-08 03:52

How do I compile a .c file on my Mac?

相关标签:
7条回答
  • 2020-12-08 04:07

    You'll need to get a compiler. The easiest way is probably to install XCode development environment from the CDs/DVDs you got with your Mac, which will give you gcc. Then you should be able compile it like

    gcc -o mybinaryfile mysourcefile.c
    
    0 讨论(0)
  • 2020-12-08 04:11

    Ondrasej is the "most right" here, IMO.
    There are also gui-er ways to do it, without resorting to Xcode. I like TryC.

    Mac OS X includes Developer Tools, a developing environment for making Macintosh applications. However, if someone wants to study programming using C, Xcode is too big and too complicated for beginners, to write a small sample program. TryC is very suitable for beginners.

    enter image description here

    You don't need to launch a huge Xcode application, or type unfamiliar commands in Terminal. Using TryC, you can write, compile and run a C, C++ and Ruby program just like TextEdit. It's only available to compile one source code file but it's enough for trying sample programs.

    0 讨论(0)
  • 2020-12-08 04:14

    Use the gcc compiler. This assumes that you have the developer tools installed.

    0 讨论(0)
  • 2020-12-08 04:18

    You can use gcc, in Terminal, by doing gcc -c tat.c -o tst

    however, it doesn't come installed by default. You have to install the XCode package from tour install disc or download from http://developer.apple.com

    Here is where to download past developer tools from, which includes XCode 3.1, 3.0, 2.5 ...

    http://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wo/5.1.17.2.1.3.3.1.0.1.1.0.3.3.3.3.1

    0 讨论(0)
  • 2020-12-08 04:20

    You will need to install the Apple Developer Tools. Once you have done that, the easiest thing is to either use the Xcode IDE or use gcc, or nowadays better cc (the clang LLVM compiler), from the command line.

    According to Apple's site, the latest version of Xcode (3.2.1) only runs on Snow Leopard (10.6) so if you have an earlier version of OS X you will need to use an older version of Xcode. Your Mac should have come with a Developer Tools DVD which will contain a version that should run on your system. Also, the Apple Developer Tools site still has older versions available for download. Xcode 3.1.4 should run on Leopard (10.5).

    0 讨论(0)
  • 2020-12-08 04:20

    In 2017, this will do it:

    cc myfile.c
    
    0 讨论(0)
提交回复
热议问题