Find the answer to your Linux question:
Results 1 to 9 of 9
Hello everyone, Thank you for taking the time to read this. I am pretty new at Linux so I apologize for the stupid question. Recently, I just installed the g95 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2010
    Posts
    11

    Symbolic Link


    Hello everyone,

    Thank you for taking the time to read this. I am pretty new at Linux so I apologize for the stupid question.

    Recently, I just installed the g95 FORTRAN compiler and want to create a link to it so I can use it anywhere (ie: in the same way typing "firefox" will open a window no matter what directory you type it in). For example, I just want to able to call the compiler from the directory that includes the source code files like so:

    ~/research/fortran_code> g95 hello_world.f90

    I tried a few different combinations using "ln -s" but the link would never work. I can run the code by moving into the install/bin file of the compiler, but it's really inconvenient. Anyone have any suggestions?

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,411
    Where (what directory and name) was it installed to?
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Aug 2010
    Posts
    11
    The compiler is installed in this directory:

    g95-install/bin/i686-pc-linux-gnu-g95

  4. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,411
    This is only a relative directory/path. Where, exactly, is it installed? In your home directory?
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  5. #5
    Just Joined!
    Join Date
    Aug 2010
    Posts
    11
    Yes, sorry, its:

    /home/peter/g95-install/bin/i686-pc-linux-gnu-g95

  6. #6
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,411
    Assuming it also put a lib directory there, you would need to do the following:

    1. Create a link to the executable in either /bin or /usr/local/bin: sudo ln -s /home/peter/g95-install/bin/i686-pc-linux-gnu-g95 /usr/bin/g95
    and: export LD_LIBRARY_PATH=/home/peter/g95-install/lib:${LD_LIBRARY_PATH}

    The second command is to make the shared libraries available to the compiler and built executables.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  7. #7
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    So I think you're a bit confused on what you're trying to do.

    In order to run a program without giving the whole path to it, you need to put the directory of that program into your PATH. You can see your current path by running:
    Code:
    echo $PATH
    from the commandline.

    So now, I think you have two options.

    1) Add ~/g95-install/bin/ to your path:
    Code:
    PATH=~/g95-install/bin:$PATH
    2) Create a dedicated local bin directory, add it to your path, and add a symlink to your program from that:
    Code:
    mkdir ~/bin
    PATH=~/bin:$PATH
    ln -s ~/g95-install/bin/i686-pc-linux-gnu-g95 ~/bin/g95
    In both of these cases, you will probably want to add the PATH variable modification to your bashrc.

    Does this make sense?

  8. #8
    Just Joined!
    Join Date
    Aug 2010
    Posts
    11
    Quote Originally Posted by Rubberman View Post
    Assuming it also put a lib directory there, you would need to do the following:

    1. Create a link to the executable in either /bin or /usr/local/bin: sudo ln -s /home/peter/g95-install/bin/i686-pc-linux-gnu-g95 /usr/bin/g95
    and: export LD_LIBRARY_PATH=/home/peter/g95-install/lib:${LD_LIBRARY_PATH}

    The second command is to make the shared libraries available to the compiler and built executables.
    Thanks, I got it to work! I'm definitely printing this out for reference.

  9. #9
    Just Joined!
    Join Date
    Aug 2010
    Posts
    11
    Quote Originally Posted by Cabhan View Post
    So I think you're a bit confused on what you're trying to do.

    In order to run a program without giving the whole path to it, you need to put the directory of that program into your PATH. You can see your current path by running:
    Code:
    echo $PATH
    from the commandline.

    So now, I think you have two options.

    1) Add ~/g95-install/bin/ to your path:
    Code:
    PATH=~/g95-install/bin:$PATH
    2) Create a dedicated local bin directory, add it to your path, and add a symlink to your program from that:
    Code:
    mkdir ~/bin
    PATH=~/bin:$PATH
    ln -s ~/g95-install/bin/i686-pc-linux-gnu-g95 ~/bin/g95
    In both of these cases, you will probably want to add the PATH variable modification to your bashrc.

    Does this make sense?
    So I tried the previous poster's solution and got it to work, but (again, my linux understanding is low), isn't a symbolic link used so you don't have to keep typing in the whole path for an executable (much like a Windows shortcut)? Thanks for the response.

Posting Permissions

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