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
Problem in HP-UX compiling vasanthan HP-UX 1 04-20-2008 04:34 AM
help on compiling a C program on Tiger cleansing_flame High Level Programming 4 01-29-2008 11:59 AM
Problem compiling program rochitsharma High Level Programming 28 07-23-2006 05:56 PM
Problem in PowerDNS compiling secret4all SUN Solaris 0 10-12-2005 08:47 PM
Compiling problem iandunn SUN Solaris 1 09-21-2005 04:41 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-26-2008
cleansing_flame's Avatar
Registered User
 

Join Date: Nov 2007
Location: NYC
Posts: 37
Stumble this Post!
Problem with Compiling C on Tiger

I've downloaded Xcode and i've done :
which "gcc"
which "ggc-4.0"
and which "c99"

all were found in /usr/bin/

however with the script

#include <stdio.h>

main()
{
printf("hello, world\n");
}

and when I, in command line use the command while in my home dir:

gcc cprog.c -o cprog

i have no output
just another line prompt

any help appreciated and i'm sorry if this is a terribly simple question
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-26-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/florida
Posts: 951
Stumble this Post!
That means your code compiled into an executable without an error.

Type ./cprog to invoke the resulting executable.
Reply With Quote
  #3 (permalink)  
Old 02-26-2008
cleansing_flame's Avatar
Registered User
 

Join Date: Nov 2007
Location: NYC
Posts: 37
Stumble this Post!
i tried :

`gcc ./cprog.c`

and

`gcc ./cprog.c -o ./cprog`

nothing worked, thanks though
Reply With Quote
  #4 (permalink)  
Old 03-04-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,846
Stumble this Post!
No.

fp means: to see what your code does when you run the compiled code: ie., get "hello world" on the screen.

./cprog <-- this is what you type, no "gcc" anywhere, then press return.
Reply With Quote
  #5 (permalink)  
Old 03-04-2008
Registered User
 

Join Date: Feb 2007
Posts: 67
Stumble this Post!
To explain this better:
You write the program into a file called "cprog.c".
Then after you execute "gcc cprog.c -o cprog", use the command "ls" to list the current files in the directory ("man ls" for more info).
You should see a file called "cprog". This file cprog was created when you did the "gcc cprog.c -o cprog", and this command means that you use the program gcc (gnu c compiler) on the c source file "cprog.c". Then the "-o" means to output the binary file to "cprog". If you hadn't used "-o", gcc would have generated a file called "a.out". ("man gcc" for more info)
Lastly, you can execute the file "cprog" by typing "./cprog" into the terminal. This means to check the directory "./" (which means the current directory that you are in) for the file "cprog". If you didn't specify that "cprog" was in "./", then the operating system would have assumed "cprog" was in "/usr/bin" or another directory (if you want to know type "$PATH" into your terminal).

Does that explain things clearly?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:51 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