Help with gcc

Joined
Jun 11, 2008
Messages
5
Reaction score
0
Points
1
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.
 
Joined
Mar 15, 2007
Messages
161
Reaction score
4
Points
18
Your Mac's 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="
 
Joined
Mar 17, 2008
Messages
6,879
Reaction score
191
Points
63
Location
Tucson, AZ
Your Mac's Specs
Way... way too many specs to list.
echo $PATH

also works
 
OP
A
Joined
Jun 11, 2008
Messages
5
Reaction score
0
Points
1
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
 
Joined
Mar 15, 2007
Messages
161
Reaction score
4
Points
18
Your Mac's 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.
 
OP
A
Joined
Jun 11, 2008
Messages
5
Reaction score
0
Points
1
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.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top