Results 1 to 6 of 6

Thread: Mac Terminal

  1. #1
    Mac Terminal

    Member Since
    Nov 01, 2005
    Location
    texas
    Posts
    46
    Specs:
    powerbook g4
    Mac Terminal
    How do I compile a program on terminal. I wrote a program and saved it but I tried to compile using the g++ or gcc command but its not working.(Command not found). I saved the file as *.cpp.

    Need help.
    Thank you.

  2. #2
    Mac Terminal
    surfwax95's Avatar
    Member Since
    Aug 27, 2005
    Location
    Fayetteville, AR
    Posts
    2,406
    Specs:
    15" Powerbook G4 24" iMac iPhone 3Gs
    Is gcc installed?

    If not, you can get it off of the Apple's Developer site, I believe. I think it may be on your install disk, too.
    I try to Command+Shift+/ when I can.
    They're - Their - There | Two - Too - To | You're - Your | MAC - Mac
    I was on the M-F honor roll for October, 2006.

  3. #3
    Mac Terminal
    mac57's Avatar
    Member Since
    Apr 29, 2006
    Location
    St. Somewhere
    Posts
    4,560
    Specs:
    iMac 27" 3.4 GHz, 256 GB SSD, 2 TB HDD, 8 GB RAM
    Assuming gcc is installed, the simplest way may be to compose a make file and use the make utility.

    Here is an example. Assume you have file program.c that you want to compile and link so that the result is the executable "program".

    In the same directory as program.c, place a file called Makefile - the "M" should be uppercase. Create this file with your favorite editor and put the following lines in it:

    Code:
    # Make file to create the "program" executable
    
    program : program.c
    	cc -o program program.c
    Now, to compile and link in one step, just issue the command:

    Code:
    make
    That's it! Much simpler than manually typing in the whole "cc" command.

    BTW, cc is normally aliased to gcc, hence the use of the "cc" command vs. the "gcc" command. Using "cc" instead makes the Makefile more portable, since many *nix systems have a native "cc" and don't need gcc.
    My Macs: iMac 27" 3.4 GHz, Mac Pro 3.2 GHz, PowerMac G5 Quad 2.5 GHz, G4 Cube with 1.2 GHz Upgrade
    My iStuff: 64GB iPhone 5, 64GB iPad4, 30GB iPod Video, 16GB iPod Touch
    My OS': Mac OS X Lion, Mac OS X Snow Leopard, Mac OS X Tiger, Mac OS 9.2.2, openSUSE 10.3
    I was on the Mac-Forums honor roll for September 2007

  4. #4
    Mac Terminal
    DoubleCap's Avatar
    Member Since
    Feb 12, 2007
    Location
    Northeast US
    Posts
    552
    Specs:
    MacBook 2GHz/2GB/CD
    Install gcc. Navigate to your folder where the .cpp or .h files are stored.

    To compile a prog.cpp, for example:

    make prog

    ... That should make an executable.. then type:

    ./prog

    The ./ denotes current directory

  5. #5
    Mac Terminal
    novicew's Avatar
    Member Since
    Jan 04, 2006
    Location
    Hamburg, Germany
    Posts
    1,385
    Specs:
    MacBook Pro | iMac(2.1 G5) | MacBook(2.16 C2D) | MacMini (1.67 CD) | iPhone 4 | iPad (3rd Gen)
    Download and install xcode(It comes with loads of developer tools including gcc). Assume your app. is called hello.cpp

    In terminal,
    $ g++ hello.cpp -o hello -----> this will create an executable file called hello
    $ ./hello -----> this will execute the newly created executable file.

  6. #6
    Mac Terminal
    mac57's Avatar
    Member Since
    Apr 29, 2006
    Location
    St. Somewhere
    Posts
    4,560
    Specs:
    iMac 27" 3.4 GHz, 256 GB SSD, 2 TB HDD, 8 GB RAM
    stonecold, will "make prog" work if you don't define a Makefile file? I thought that at least a rudimentary Makefile, per my post above, was needed?
    My Macs: iMac 27" 3.4 GHz, Mac Pro 3.2 GHz, PowerMac G5 Quad 2.5 GHz, G4 Cube with 1.2 GHz Upgrade
    My iStuff: 64GB iPhone 5, 64GB iPad4, 30GB iPod Video, 16GB iPod Touch
    My OS': Mac OS X Lion, Mac OS X Snow Leopard, Mac OS X Tiger, Mac OS 9.2.2, openSUSE 10.3
    I was on the Mac-Forums honor roll for September 2007

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. I affraid my mac is terminal... HELP?
    By ShelleyFur in forum Switcher Hangout
    Replies: 5
    Last Post: 06-17-2013, 05:18 PM
  2. Mac Terminal
    By Rugess in forum OS X - Operating System
    Replies: 4
    Last Post: 01-10-2013, 08:57 PM
  3. Month in Terminal is in Russian - only in Terminal!
    By yoandrew in forum OS X - Operating System
    Replies: 4
    Last Post: 12-29-2012, 09:20 AM
  4. How to configure the Terminal in Mac
    By yinglcs in forum OS X - Operating System
    Replies: 4
    Last Post: 02-02-2009, 03:06 PM
  5. terminal fonts in mac
    By diffuser78 in forum OS X - Development and Darwin
    Replies: 3
    Last Post: 01-08-2009, 01:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •