The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Compile gcc on AIX 5.2 untamed AIX 7 01-31-2008 02:21 AM
How do I compile source undfer Suse Linux? Mark Ward Linux 3 05-26-2006 10:28 AM
¿compile .ksh? DebianJ Shell Programming and Scripting 1 05-09-2005 01:33 PM
Compile freeBSD binaries in Linux shalmoo High Level Programming 0 10-01-2003 12:38 AM
How to compile using gcc... lilprogrammer High Level Programming 4 08-21-2002 09:48 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 09-20-2001
Registered User
 

Join Date: Sep 2001
Location: Australia
Posts: 1
Question 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
Reply With Quote
Forum Sponsor
  #2  
Old 09-20-2001
mbb mbb is offline
Registered User
 

Join Date: Aug 2001
Location: UK
Posts: 103
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.
__________________
Senior Analyst/Programmer
Reply With Quote
  #3  
Old 09-20-2001
rwb1959's Avatar
Registered User
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
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.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:13 AM.


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

Content Relevant URLs by vBSEO 3.2.0