Running an executable in Mac Terminal
MacosTerminalMacos Problem Overview
I just made a .c file and compiled it with gcc in the terminal on OS X 10.8.2.
My syntax was gcc -o <filename> <sourcefile>
and that was fine. Now I see I have an executable and file <filename>
tells me as such, but I'm not sure how to actually run it beside double clicking the icon, /lame. When I try running the executable by just typing
Thank you.
EDIT: I"m so stupid, it was just open <filename>
Macos Solutions
Solution 1 - Macos
Unix will only run commands if they are available on the system path, as you can view by the $PATH variable
echo $PATH
Executables located in directories that are not on the path cannot be run unless you specify their full location. So in your case, assuming the executable is in the current directory you are working with, then you can execute it as such
./my-exec
Where my-exec
is the name of your program.
Solution 2 - Macos
To run an executable in mac
1). Move to the path of the file:
cd/PATH_OF_THE_FILE
2). Run the following command to set the file's executable bit using the chmod command:
chmod +x ./NAME_OF_THE_FILE
3). Run the following command to execute the file:
./NAME_OF_THE_FILE
Once you have run these commands, going ahead you just have to run command 3, while in the files path.