Running an executable in Mac Terminal

后端 未结 2 1709
孤街浪徒
孤街浪徒 2020-12-13 08:35

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 and that was fi

相关标签:
2条回答
  • 2020-12-13 09:13

    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.

    0 讨论(0)
  • 2020-12-13 09:16

    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.

    0 讨论(0)
提交回复
热议问题