Getting program to run on command

This question already has an answer here:

  • How does the compilation/linking process work? 5 answers

  • Compiles the program and link it as an executable to a.out

    gcc helloworld.c
    

    Execute the file

    ./a.out
    

    Assuming the helloworld executable is in newDir directory in the home folder.

    Then the absolute path for helloworld is /home/user_name/newDir/helloworld

    Now add the below line your ~/.bashrc file.

    export PATH=$PATH:/home/user_name/newDir/
    

    Now open any new terminal (any directory), you will be able to run the command helloworld

    Adding the path of the executable in the PATH environment variable will allow the user to run the executable available in the mentioned directory any where in the system. Check the value of your $PATH with echo $PATH . It probably contains the system directories /usr/bin and /bin where most system executables sit. But don't mess these directories by adding your own programs there (leave them to be handled by your package manager).

    You might want to avoid having a too long PATH environment variable; then, assuming you do have a $HOME/bin/ directory mentioned in that $PATH , you could just add a symbolic link there, eg

    ln -sv /home/user_name/newDir/helloworld $HOME/bin/helloworld
    

    那么你会使用./(outputfilename)来运行它。所以要分配一个名称,我们使用注释gcc -o desiredOPname filename.c然后运行它为./desiredOPname

    链接地址: http://www.djcxy.com/p/73310.html

    上一篇: 为什么调试器不知道#define'd常量?

    下一篇: 让程序在命令上运行