To create a file for example 'hello.c'
$ edit hello.c(The Linux Pico Editor will be opened. Type the following in the editor.) To compile the file 'hello.c'
$ c hello.cor use gcc with -o option
$ gcc hello.c -o helloTo execute the file 'hello'
$ run hello
This will output Hello World!...
Infact, there are two modes of program execution; these are interactive (the commands nice and run), and background (the & symbol and the command submit). Note that there are no cpu time limits or batch queues. To run an executable program you can simple type its name or use the run command. For example, you have compiled a C program into an executable program called myprog. The program can be executed with one of the following commands:$ myprog $ ./myprog(if myprog exists elsewhere in the user's PATH then './' specifies that the file to be executed is in the present working directory)
$ nice myprog (please use this one or the next to be nice to other users)For our c program 'hello.c'
$ helloor
$ ./helloNotes:
Using Library by C
Before starting, create the following files to be an example:sub1.c , sub2.c , sub3.c and main.c
$ c main.c sub1.c sub2.c sub3.cor
$ gcc main.c sub1.c sub2.c sub3.c -o mainThen, the command
$ run mainwill output
Sum is 5 Mul is 6 The biggest is 3
$ gcc sub1.c -c gives object file of sub1.c (that is sub1.o) $ gcc sub2.c -c gives object file of sub2.c (that is sub2.o) $ gcc sub3.c -c gives object file of sub3.c (that is sub3.o)
$ ar rcvf libtest.a sub1.o sub2.o sub3.o (see man ar)You can add objects to the library with:
$ ar rcvf libtest.a sub4.oTo list the contents of the library:
$ ar tv libtest.aTo list functions in a library:
$ nm libtest.a (see man nm)To delete an object from the library:
$ ar dv libtest.a sub3.o
$ gcc main.c -o main -L. -ltestNote that lib and .a are dropped.The -L. options tells the linker that the library can be found in the current directory. If the library is not in the current directory then you should give the path:
$ gcc main.c -o main -L/home/yilmaz/C/lib -ltestor
$ gcc main.c -o main -L$MYLIB -ltestwith
MYLIB=/home/yilmaz/C/lib
gcc_2.htmlsystem@gantep.edu.tr
gcc.ps
gcc.ps.zip
http://www.gnu.org/software/gcc/gcc.html
http://gcc.gnu.org/onlinedocs/gcc-3.0/gcc.html
http://www.gnu.org/software/gcc/faq.html