Operating System - HP-UX
1843938 Members
2246 Online
110226 Solutions
New Discussion

Compiling C program in UNIX

 
SOLVED
Go to solution

Compiling C program in UNIX

Dear all,

I want to Compile a C Program in UNIX, please let me know the procedure.

Regards,

Yajuvendra Singh
5 REPLIES 5
Arunvijai_4
Honored Contributor
Solution

Re: Compiling C program in UNIX

Hello, You can use either CC (Default C Compiler) or GCC to compile a C program.

1) Save your C program. Say test.c

2) # cc -o test test.c will generate executable of your program in the name of test

3) ./test to execute your program

4) # gcc -o test test.c if you like GCC.

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Arunvijai_4
Honored Contributor

Re: Compiling C program in UNIX

Hello, Here is a very good tutorial about "Compiling "C" And "C++" Programs On Unix Systems - gcc/g++"

http://users.actcom.co.il/~choo/lupg/tutorials/c-on-unix/c-on-unix.html

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Peter Godron
Honored Contributor

Re: Compiling C program in UNIX

Yajuvendra,
please also note that the default C compiler(cc) installed with the OS is normally only used to compile the OS kernel, so may not be as feature-rich as you want it to be.

For full C compilers, HP produced a ANSI C compiler, which is a licensed/chargeable product.
Al Langen_1
Advisor

Re: Compiling C program in UNIX

Caution when using test.c to compile a program and move it to test: you may not be running your program. If you insist on using test, execute it using ./test

Alfons
A. Clay Stephenson
Acclaimed Contributor

Re: Compiling C program in UNIX

Unless you purchase the ANSI C compiler or aCC (the C++ compiler) or have installed the Gnu C compiler (gcc) then you will only be able to use K & R syntax. The Bundled C compiler only speaks K & R and is really intened for kernel compiles although limited development can be done.
If it ain't broke, I can fix that.