• Lucid Dreaming - Dream Views




    Results 1 to 9 of 9
    1. #1
      What's up <span class='glow_006400'>[SomeGuy]</span>'s Avatar
      Join Date
      Nov 2007
      LD Count
      About 1
      Gender
      Location
      Tmux on Debian
      Posts
      2,862
      Likes
      130
      DJ Entries
      4

      Linux Program Extention?

      Hey, if I wanted to compile something for Linux with g++ and I used -o, what should I name the file?

      Just the name of the program?

      Basically, I want to have it so I don't have to type "./a.out" to run my program, and instead, type "program"

      Hey guys, I'm back. Feels good man
      ---------------------------------------------------
      WTF|Jesus lul
      spam removed

    2. #2
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      File extensions under *nix don't mean anything
      They are intended for humans only, and have no bearing on how the machine views the file

      binary executables usually don't have an extension

      Code:
      g++ -o my_program my_program.cpp
      Run the binary by typing
      Code:
      ./my_program
      (\_ _/)
      (='.'=)
      (")_(")

    3. #3
      Member
      Join Date
      May 2009
      Posts
      139
      Likes
      1
      For linux executables, I think the executable file needs to have it's executable "x" bits set in it's file permissions. You can find that out with a "ls -l", and set it (if it needs setting) using chmod. You also need to make sure the file's location is in your executable path.

    4. #4
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      Quote Originally Posted by starry eyes View Post
      For linux executables, I think the executable file needs to have it's executable "x" bits set in it's file permissions. You can find that out with a "ls -l", and set it (if it needs setting) using chmod. You also need to make sure the file's location is in your executable path.
      the compiler will do this automatically
      (\_ _/)
      (='.'=)
      (")_(")

    5. #5
      What's up <span class='glow_006400'>[SomeGuy]</span>'s Avatar
      Join Date
      Nov 2007
      LD Count
      About 1
      Gender
      Location
      Tmux on Debian
      Posts
      2,862
      Likes
      130
      DJ Entries
      4
      Quote Originally Posted by Ynot View Post
      File extensions under *nix don't mean anything
      They are intended for humans only, and have no bearing on how the machine views the file

      binary executables usually don't have an extension

      Code:
      g++ -o my_program my_program.cpp
      Run the binary by typing
      Code:
      ./my_program
      Well, ls is a program, and so is Firefox, but I only have to type "ls" or "firefox" for it to run...how does that work?

      Hey guys, I'm back. Feels good man
      ---------------------------------------------------
      WTF|Jesus lul
      spam removed

    6. #6
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      the location of these programs is in your path variable

      When asked to execute a program, the shell needs to know where the program is

      you can do this in 3 ways

      Give the absolute path to the binary
      /bin/ls
      /usr/bin/firefox
      /home/user/program

      Give a relative path (relative to the current directory)
      ./program - run "program" located in the current directory

      Most "installed" programs, however, are located in special locations
      When asked to execute a program with no location information, the shell will look through these special locations in order to find the program

      These special locations are stored in the PATH variable

      do
      Code:
      echo $PATH
      If you want to be able to execute locally build programs without specifying their location, you need to add an additional directory to the path

      Code:
      mkdir ~/bin
      compile all your programs into ~/bin, and you can just type the program name
      (\_ _/)
      (='.'=)
      (")_(")

    7. #7
      What's up <span class='glow_006400'>[SomeGuy]</span>'s Avatar
      Join Date
      Nov 2007
      LD Count
      About 1
      Gender
      Location
      Tmux on Debian
      Posts
      2,862
      Likes
      130
      DJ Entries
      4
      Oh, okay.

      Noob question, how do you add to the PATH variable?

      Hey guys, I'm back. Feels good man
      ---------------------------------------------------
      WTF|Jesus lul
      spam removed

    8. #8
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      If you make a bin directory in your home directory, you don't actually need to do anything

      One thing Debian (and it's derivatives) do is look for a bin directory in your home directory, and add it to the path automatically

      see ~/.profile
      Code:
      # set PATH so it includes user's private bin if it exists
      if [ -d "$HOME/bin" ] ; then
          PATH="$HOME/bin:$PATH"
      fi

      Btw,
      when looking through the path variable for a program's location, the shell will take the first one it comes across

      So, your path variable will look like

      /home/user/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

      The search goes in order, left to right
      so if you had a program called "foo" in /home/user/bin, and another (different) program called "foo" in /usr/local/bin
      typing "foo" would execute the one in /home/user/bin

      This means you can easily override programs with altered local versions, if you wish

      make a program called "ls" in your ~/bin dir, and it'll always override the system installed ls command, unless you specify the absolute path of ls
      (\_ _/)
      (='.'=)
      (")_(")

    9. #9
      dsr
      dsr is offline
      我是老外,可是我會說一點中文。
      Join Date
      Nov 2006
      Gender
      Location
      my mind
      Posts
      374
      Likes
      1
      Just to add to what Ynot said, you can check your current PATH variable by typing `echo $PATH' (without the quotes) at a shell prompt, and you can create your own PATH by adding something like
      Code:
      export PATH='/bin:/usr/local/bin:$HOME/bin:/usr/sbin:/usr/local/sbin'
      to your ~/.bashrc if you use bash. You could also add it to ~/.bash_profile or ~/.profile (they function identically) if you use a login shell. Or just add it to ~/.bashrc and then source ~/.bashrc in ~/.bash_profile like so:
      Code:
      # contents of ~/.bash_profile
      . $HOME/.bashrc
      If you don't use bash, the syntax of exporting the PATH variable might be slightly different and the file names will be different.

    Bookmarks

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •