The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
What's The Easiest Route To Creating A Unix Executable File for Terminal? unimachead OS X (Apple) 9 04-30-2008 07:02 AM
Executable file tonet Shell Programming and Scripting 3 01-17-2008 08:03 AM
How can i read a non text file in unix - ELF-64 executable object file - IA64 alexcol UNIX for Advanced & Expert Users 4 07-20-2007 02:05 PM
problem in creating executable for a client program konas High Level Programming 2 11-17-2006 10:09 AM
Newbie question about difference between executable file and ordinary file Balaji UNIX for Dummies Questions & Answers 1 11-29-2000 02:49 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-28-2007
Registered User
 

Join Date: Mar 2006
Posts: 26
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
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!
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 09-29-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
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.
Reply With Quote
  #3 (permalink)  
Old 09-29-2007
Registered User
 

Join Date: Mar 2006
Posts: 26
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
how could I do that?

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!
Reply With Quote
  #4 (permalink)  
Old 09-29-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
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.
Reply With Quote
  #5 (permalink)  
Old 09-29-2007
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,252
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Quote:
Originally Posted by compbug View Post
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!
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.
Reply With Quote
  #6 (permalink)  
Old 09-30-2007
Registered User
 

Join Date: Mar 2006
Posts: 26
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
got it!

Thanks,

I understood what to be done!!
Reply With Quote
  #7 (permalink)  
Old 09-30-2007
Registered User
 

Join Date: Mar 2006
Posts: 26
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
@porter

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!
Reply With Quote
  #8 (permalink)  
Old 09-30-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
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 $@"
Reply With Quote
Google UNIX.COM
Reply

Tags
linux

Thread Tools
Display Modes


The 50 most popular UNIX and Linux searches.
Google Search Cloud for The UNIX and Linux Forums
421 service not available, remote server has closed connection ^m automate ftp autosys awk trim bash eval bash for loop boot: cannot open kernel/sparcv9/unix command copy/move folder in unix couldn't set locale correctly curses.h cut command in unix find grep find mtime find null character in a unix file grep multiple lines grep or grep recursive hp-ux ifconfig inaddr_any inappropriate ioctl for device lynx javascript mailx attachment mget mtime perl array length ping port remove first character from string in k shell replace space by comma , perl script rsync ftp scp recursive segmentation fault(coredump) sftp script snoop unix solaris change ip address stale nfs file handle syn_sent tar exclude tar extract to folder test: argument expected unix unix .profile unix forum unix forums unix internals unix interview questions unix mtime unix simulator unix.com while loop within while loop shell script


All times are GMT -7. The time now is 01:40 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101