creating executable for every C file

hello Folks,

once we compile any C code on Linux, we run the code using "./a.out"..

but can we have an executable for every program so that we can run the code directly without compiling the code every time.
just run the executable and get the output!

Thanks!

You could do. Except that normally non-trival C programs are more than one source file.

You could write a C interpretor, but there is no real demand for them. The advantages you get from using C are mainly because it's a compiled language.

I rarely call my programs a.out, it would get far too confusing trying to remember which one did what.

well, how could I do that?
could you please explain?

I think it is better way to have an executable for all C codes.... atleast for the trial codes we run to understand the concepts!!

Thanks!

I may be missing the point on your question but C is a compiled language.

To run it you have to:

(a) compile the C source into object files
(b) link the object files with libraries to produce the executable

once you have done that you can run the executable as many times as you like, and you can call it whatever name you like.

It is also compiled specific to the computer's architecture, so you can't expect 386 code to run natively on an UltraSparc. Similarly it is operating system dependent.

Most compilers let you do something like:
gcc myprogram.c -o myprogram

And anyway there is a mv command that can rename a file. So you could do:
gcc myprogram.c
mv a.out myprogram

But bear in mind that as porter mentioned, a file like xyz.c may not be a program. It could just be a function.

Thanks,

I understood what to be done!!

sorry, I was not specific in asking the question... my question was to renaming the executable to the C code name which can be done by "mv" ....

so , you missed a point about this..

Thanks Man!

I would recommend using "-o" option to specify the name of the executable,
so for example,

(a) if you have a makefile that only completed half of it's tasks, you could continue where you left off without wondering what a.out referred to

(b) if you are creating a shared library, the library often carries and internal representation of it's name, in ELF terms, the SO_NAME field, if the -soname field is not specified it is derived from the output file name, so the shared library may think it's supposed to be "a.out".

(c) in a Makefile, this can be standardised as "-o $@"