Results 1 to 7 of 7

Thread: Help with gcc

  1. #1
    Help with gcc

    Member Since
    Jun 11, 2008
    Posts
    5
    Help with gcc
    Hi, so I've used gcc on Unix before and had no problems but on my mac (10.4) I can't get it to work. I've installed xcode and the developer tools. The thing is that gcc compiles the code perfectly fine, but I can't run it. So on unix for example I would do something like this:

    gcc -o test test.c

    and then to run it:

    test <inputs>

    but on the mac it give me an error "test: command not found" but it creates the executable "test" when I compile it. I'm sure there is something obvious I'm missing here, can someone help me out?

    Thanks.

  2. #2
    Help with gcc

    Member Since
    Mar 15, 2007
    Posts
    161
    Specs:
    17" MacBook Pro, 2.33GHz C2D, 2GB RAM
    My bet is that the current directory is not a part of your PATH environment variable. If so, one workaround is to run the program this way:

    ./test <inputs>

    You can check what your default executable search path is set to with the following command:

    env | grep "^PATH="

  3. #3
    Help with gcc
    Dysfunction's Avatar
    Member Since
    Mar 17, 2008
    Location
    Tucson, AZ
    Posts
    6,821
    Specs:
    Way... way too many specs to list.
    echo $PATH

    also works
    mike
    This machine kills fascists
    Got # ? phear the command line!

  4. #4
    Help with gcc

    Member Since
    Jun 11, 2008
    Posts
    5
    Yep, that was it, thanks guys.

  5. #5
    Help with gcc

    Member Since
    Jun 11, 2008
    Posts
    5
    Actually guys can you tell me what to add to my PATH to fix this, I've been messing around with my .profile but I still can't manage to fix it.

    Thanks

  6. #6
    Help with gcc

    Member Since
    Mar 15, 2007
    Posts
    161
    Specs:
    17" MacBook Pro, 2.33GHz C2D, 2GB RAM
    Assuming that you are using the default bash shell, if you are creating the ".profile" file you mentioned in your home directory (i.e., "echo $HOME") and adding the following single line to it:

    PATH=$PATH:.

    ... that ought to do it.

    One other note about specifically using the name "test": you probably have an executable file named "test" that is part of your OS (in the /bin directory). This file is used for checking various conditions inside shell scripts. Adding the current directory to your PATH as shown above won't help with this specific name because the /bin directory will be searched first. This is exactly why I suggested using the explicit path ./test, since specifying a path preempts any such searching. Alternatively, you could put the current directory at the front of the PATH instead of at the tail end to force the current directory to be searched before all system directories, but I don't think that's a good idea.

  7. #7
    Help with gcc

    Member Since
    Jun 11, 2008
    Posts
    5
    Ok that did it, thanks a lot. And I'm not actually using test as the file name, I just used it as an example, but thanks for letting me know that, I probably would have made that mistake at some point and not been able to figure it out.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. gcc?
    By Stemcell in forum OS X - Development and Darwin
    Replies: 1
    Last Post: 11-08-2010, 12:50 PM
  2. using gcc
    By mayflyTR in forum OS X - Development and Darwin
    Replies: 2
    Last Post: 08-28-2010, 09:06 PM
  3. How to upgrade gcc 3 to gcc 4 intel mac
    By jonnyd in forum OS X - Development and Darwin
    Replies: 2
    Last Post: 12-29-2007, 04:34 PM
  4. Gcc
    By Destructive in forum OS X - Apps and Games
    Replies: 2
    Last Post: 12-17-2007, 11:40 PM
  5. GCC on 10.4.10
    By pokamonster in forum OS X - Operating System
    Replies: 1
    Last Post: 08-02-2007, 10:27 PM

Posting Permissions

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