Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Schraiber

macrumors member
Original poster
Jun 25, 2009
31
0
Hey all,

I have some C code that I wrote on an Ubuntu machine, which I figured I could just directly port over... it's pretty simple; I'm mostly trying to recompile for laughs, since I'm not a serious programmer.

Nonetheless, when I try to compile the unaltered code from the command line with gcc, it creates an a.out file but if I try to run it it just says "command not found". I assume that there's something I gotta do to port the code, but I don't know what it is...

*feels kinda stupid*
 
It sounds like you're missing (possibly among other things) something very basic... you're referencing the a.out file by path, right? (i.e. ./a.out) Maybe post a terminal capture.
 
Don't you need to link the a.out file to libraries to generate an exe? :confused:

Edit: I'm probably thinking something totally off. Never mind me. :p
 
Nonetheless, when I try to compile the unaltered code from the command line with gcc, it creates an a.out file but if I try to run it it just says "command not found". I assume that there's something I gotta do to port the code, but I don't know what it is...

Just to further explain here. The a.out file created is the program executable. a.out is the default executable name when you don't supply one to gcc. Why you got command not found when you tried to run it was already explained. If you want to name your program executable something meaningful, then add a "-o <program_name>" to your gcc command line.

Another way to compile it is to use make. If it's a very basic program that is all contained in a single source file, doesn't need any special compile flags set, doesn't need any include paths passed to the compiler etc, then the following will work even if you didn't create any makefiles:

If your source file was named 'foo.c' then ...

Code:
make foo

This will create an executable called 'foo'. Run it by doing:

Code:
./foo
 
Thank you guys so much! For some reason, in the Ubuntu shell all I needed to type was "a.out" and it would work.
 
Thank you guys so much! For some reason, in the Ubuntu shell all I needed to type was "a.out" and it would work.

That just means your current directory (on Ubuntu) was in your PATH, which negated the requirement of the dot and slash characters. It can sometimes be considered a security risk depending on ordering of directories in your PATH environment variable (because a downloaded executable file could take precedence over a system-installed file with the same name).
 
Yeah, sorry, I was assuming that no one would do this. :eek:

My school shell account does it. It's annoying, because people get used to it and then get really confused if they use another *nix machine. UC Davis does the same thing, actually. It's dumb :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.