PDA

View Full Version : c++ output file execution




macfreek57
Oct 13, 2003, 02:07 AM
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?



robbieduncan
Oct 13, 2003, 02:22 AM
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.

macfreek57
Oct 13, 2003, 02:31 AM
that's it!
the "./" thing
thanks!

but where do i change my PATH environment variable?

robbieduncan
Oct 13, 2003, 02:51 AM
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!