compile C under linux?

hi everyone,

i am a beginner of C and doing a subject which involved c programming under unix.
i tried compile the c program under linux. but i can only get the a.out file in /usr/bin, not in the current dir. can anyone know how to change the sys. configration. Please help. thanks

The C compiler does not know what to call your final executable, so it has defaulted the name to a.out.

It is unusual for the compiler to place the output in the /usr/bin directory, usually it is placed into your current directory.

Nearly all compiliers, including those on Unix and Linux will accept a number of command line switches and parameters. By using command line parameters you can change the behaviour of the compiler significantly. See for yourself by doing:

man cc

or

man gcc

This will give you a very lengthy description of what to expect from your compiler. Also read the man page on your linker.

man ld

Somewhere in that lot will be a way to change the output file name. If necessary you can give it an explicit path name.

Finally, if you did not realise it already, the a.out file is (or should be) a fully runnable executable. You can always rename it using the move or copy command!

Regards

MBB.

I'm not sure why your resulting "a.out" file is
ending up in /usr/bin BUT... normally you would
have to be a priviledged user (i.e. root) to
be able to write into that directory. I would
strongly recommend that you DO NOT experiment
with writing and compiling programs as root
(or any other priviledged user). Login to your
system as an ordinary user to do this sort of
thing.

On directing the compiler, try the "-o" option
to generate your executable...

gcc -o hello hello.c

...will compile the C program "hello.c" and will
create an executable file called "hello" in
the current working directory.