c++ output file execution

Discussion in 'Mac Apps and Mac App Store' started by macfreek57, Oct 13, 2003.

  1. macfreek57 macrumors 6502

    Joined:
    Jan 1, 2002
    Location:
    Baton Rouge, Louisiana
    #1
    i'm using command line gcc
    i forgot how to execute the "a.out" files in the terminal because i've been doing most of my programming on windows computers at school :rolleyes:
    i know it's simple but could someone help me out?
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Normally you'd have gcc output a file called something other than a.out using the -o switch:

    gcc -o my_great_program <all the files you need>

    Then to run it you would type ./my_great_program

    If you don't want to type the ./ every time (and don't mind a little risk) you can add the ./ to your PATH environment variable.
     
  3. macfreek57 thread starter macrumors 6502

    Joined:
    Jan 1, 2002
    Location:
    Baton Rouge, Louisiana
    #3
    that's it!
    the "./" thing
    thanks!

    but where do i change my PATH environment variable?
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    I thought it might be the ./ (which is simply the current directory).

    Unix looks through your PATH for programs when you type a name into the terminal. Normally you have things like /usr/bin in your path. You can add ./ to it, but be careful as you try and run anything in your current dir.

    You would normally do this in your ~/.profile file. If you add the following line to your .profile then ./ will be in your path (tested in Panther, should work in Jaguar)

    PATH=./:${PATH}

    Hope that helps!
     

Share This Page