Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Gcc

  1. #1
    Junior Member
    Join Date
    Jun 2002
    Posts
    14

    Gcc

    Hi, noobie here.

    I'm trying to gcc a helloworld in RedHat Linux 6.1, so I

    gcc helloworld.c

    which comiles successfully, and I end up with a.out.

    But I can't get it to run, despite entering

    a.out <Enter>

    Can anyone help me out here? I'm following a book 'Teach Yourself Linux' by Steve Oualline and Eric Foster Johnson. The book's examples don't look like what comes up on screen.

    sincerely,
    cow.
    sincerely,
    cow.

  2. #2
    Just a Virtualized Geek MrLinus's Avatar
    Join Date
    Sep 2001
    Location
    Redondo Beach, CA
    Posts
    7,323
    Hey there,

    Give a try to ./a.out .. You're path is what is determining whether it finds it locally or not. You can find out what your path is by entering echo $PATH.

    Hope this helps.
    Goodbye, Mittens (1992-2008). My pillow will be cold without your purring beside my head
    Extra! Extra! Get your FREE copy of Insight Newsletter||MsMittens' HomePage

  3. #3
    Junior Member
    Join Date
    Jun 2002
    Posts
    14
    That did the trick, thanks.

    So, this is what I understand, when I type the ./ it points to my local directory, but when I don't it points to the /bin. Is this right?

    Is there away for it to point directly to the right folders... where do I edit to do that?

    sincerely,
    cow.
    sincerely,
    cow.

  4. #4
    Junior Member
    Join Date
    Dec 2001
    Posts
    3
    You might also want to try using the -o option on GCC to give your ouput file a more logical name.
    e.g.
    gcc -o helloworld helloworld.c

    Then you can execute it with ./helloworld

    (I suppose it doesn't matter for now if you're just starting out, but having all your executable's called a.out will get annoying quite quickly I'd imagine)

  5. #5
    Junior Member
    Join Date
    Feb 2002
    Posts
    18
    try "gcc -o hello hello.c"
    with the parameter -o you can specify the file name of the compiled file
    Love your country, but
    never trust its government. -- Robert A. Heinlein

  6. #6
    Just a Virtualized Geek MrLinus's Avatar
    Join Date
    Sep 2001
    Location
    Redondo Beach, CA
    Posts
    7,323
    Edit you .bash_profile file using whatever tool you are comfortable with. I personally use vi. You can find it by type
    ls -l .bash_profile in your home directory.

    At the end of the PATH statement.

    Here's the one I created for my root user on my machine:

    # User specific environment and startup programs

    PATH=/usr/local/sbin:/usr/sbin:/sbin:$PATH:$HOME/bin:/usr/local/mysql/bin:.
    BASH_ENV=$HOME/.bashrc
    USERNAME="root"

    export USERNAME BASH_ENV PATH


    ALWAYS have current working directory (identified by the single . ) at the end of the PATH statement. That will mean that no matter where you are it will attempt there last. Additionally, each path location is deliniated by the colon : .

    Hope this helps
    Goodbye, Mittens (1992-2008). My pillow will be cold without your purring beside my head
    Extra! Extra! Get your FREE copy of Insight Newsletter||MsMittens' HomePage

  7. #7
    Senior Member
    Join Date
    Apr 2002
    Posts
    711
    Look at your $PATH variable... it will tell it where it's searching. In Bourne Shell, just type "set" - in csh, try using "setenv." Between those two commands (and csh uses both for different items), you should be able to find it... the shell will search the path in the order listed, stopping when it finds a match or a hit on the hash (not to confuse you or anything, but it doesn't actually search the drive each and every time, but keeps a hash in memory).
    \"Windows has detected that a gnat has farted in the general vicinity. You must reboot for changes to take affect. Reboot now?\"

  8. #8
    Senior Member
    Join Date
    Apr 2002
    Posts
    711
    Originally posted here by MsMittens
    ALWAYS have current working directory (identified by the single . ) at the end of the PATH statement. That will mean that no matter where you are it will attempt there last.
    ...though, with the added caveat, adding "current directory" to your search path is considered by some to be a fairly significant security risk.
    \"Windows has detected that a gnat has farted in the general vicinity. You must reboot for changes to take affect. Reboot now?\"

  9. #9
    Junior Member
    Join Date
    May 2002
    Posts
    8
    BTW, if there are programs that you're going to use really frequently, just put them in the /usr/bin directory, and then you can execute them like any other program (ls,cat,less,more,etc). Have fun!

    -phly

  10. #10
    PHP/PostgreSQL guy
    Join Date
    Dec 2001
    Posts
    1,164
    Putting . in your PATH, anywhere, is a significant security risk albeit it's a lot less of one at the very end. What I would do is this:

    1: make a script (we'll use foo for example) that looks like this:

    Code:
    #!/bin/sh
    
    if [ "x"$1 = "x" ]; then
      echo "Argument: $0 directory_to_add_to_path"
    elif [ ! -d $1 ]; then
      echo "Invalid directory : $1"
    else
      echo "Adding to current path as \$PATH:$1"
      PATH=$PATH:$1
    fi
    2: add an alias into your $HOME/.bashrc file as follows:

    alias addpath='$HOME/foo' (or whatever it's called, wherever it's stored)
    3: log out and log back in, or re-source your .bashrc by doing . $HOME/.bashrc and you're good to go!

    Note: this is a semi-gimpy way of using current directories, but notice, the script does not EXPORT the PATH, which means all child scripts/processes kicked off by that shell will not have any added paths in their inherited PATH.
    We the willing, led by the unknowing, have been doing the impossible for the ungrateful. We have done so much with so little for so long that we are now qualified to do just about anything with almost nothing.

Posting Permissions

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