My Training Period: xx hours
|
| Note: The information start with the command and a list of options (including the sub-processes). Then examples given how to use those commands and some of the options followed by the sample outputs. Some of the outputs have been trimmed. It is compiled from the man page. Run on Linux / Fedora Core 3.
The following is a list of file extensions. Typically, the executable doesn’t have extension.
The gcc - A GNU Compiler CollectionThe following is a list of gcc compiler commands and options.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The following are some of the gcc commands and options examples.
[bodo@bakawali testbed5]$ ls -l
total 8
-rw-rw-r-- 1 bodo bodo 179 Feb 19 11:35 testbuff.c
[bodo@bakawali testbed5]$ gcc -S testbuff.c
[bodo@bakawali testbed5]$ ls -l
total 16
-rw-rw-r-- 1 bodo bodo 179 Feb 19 11:35 testbuff.c
-rw-rw-r-- 1 bodo bodo 753 Mar 15 14:35 testbuff.s
[bodo@bakawali testbed5]$ gcc -c testbuff.c
[bodo@bakawali testbed5]$ ls -l
total 24
-rw-rw-r-- 1 bodo bodo 179 Feb 19 11:35 testbuff.c
-rw-rw-r-- 1 bodo bodo 1020 Mar 15 14:35 testbuff.o
-rw-rw-r-- 1 bodo bodo 753 Mar 15 14:35 testbuff.s
[bodo@bakawali testbed5]$ gcc -g -o testbuff testbuff.c
/tmp/cc2wdV8i.o(.text+0x1e): In function `Test':
/home/bodo/testbed5/testbuff.c:8: warning: the `gets' function is dangerous and should not be used.
[bodo@bakawali testbed5]$ ls -l
total 36
-rwxrwxr-x 1 bodo bodo 6403 Mar 15 14:38 testbuff
-rw-rw-r-- 1 bodo bodo 179 Feb 19 11:35 testbuff.c
-rw-rw-r-- 1 bodo bodo 1020 Mar 15 14:35 testbuff.o
-rw-rw-r-- 1 bodo bodo 753 Mar 15 14:35 testbuff.s
[bodo@bakawali testbed5]$ gcc -g -dumpversion -o testbuff testbuff.c
3.4.2
[bodo@bakawali testbed5]$ gcc -g -v -o testbuff testbuff.c
Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=i386-redhat-linux
Thread model: posix
gcc version 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)
/usr/libexec/gcc/i386-redhat-linux/3.4.2/cc1 -quiet -v testbuff.c -quiet -dumpbase testbuff.c -auxbase testbuff -g -version -o /tmp/cc4hwP5a.s
ignoring nonexistent directory "/usr/lib/gcc/i386-redhat-linux/3.4.2/../../../../i386-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib/gcc/i386-redhat-linux/3.4.2/include
/usr/include
End of search list.
GNU C version 3.4.2 20041017 (Red Hat 3.4.2-6.fc3) (i386-redhat-linux)
compiled by GNU C version 3.4.2 20041017 (Red Hat 3.4.2-6.fc3).
GGC heuristics: --param ggc-min-expand=38 --param ggc-min-heapsize=15786
as -V -Qy -o /tmp/ccWUyukf.o /tmp/cc4hwP5a.s
GNU assembler version 2.15.92.0.2 (i386-redhat-linux) using BFD version 2.15.92.0.2 20040927
/usr/libexec/gcc/i386-redhat-linux/3.4.2/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o testbuff /usr/lib/gcc/i386-redhat-linux/3.4.2/../../../crt1.o /usr/lib/gcc/i386-redhat-linux/3.4.2/../../../crti.o /usr/lib/gcc/i386-redhat-linux/3.4.2/crtbegin.o -L/usr/lib/gcc/i386-redhat-linux/3.4.2 -L/usr/lib/gcc/i386-redhat-linux/3.4.2 -L/usr/lib/gcc/i386-redhat-linux/3.4.2/../../.. /tmp/ccWUyukf.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/i386-redhat-linux/3.4.2/crtend.o /usr/lib/gcc/i386-redhat-linux/3.4.2/../../../crtn.o
/tmp/ccWUyukf.o(.text+0x1e): In function `Test':
/home/bodo/testbed5/testbuff.c:8: warning: the `gets' function is dangerous and should not be used.
If you have more object files to be linked together during the linking process, it is better to create the makefile. Notice that the assembler options can be passed to gcc such as –g (debug information) etc. Get some idea at the following links:
To compile C++ codes you may use the g++. g++ accepts mostly the same options as gcc. The following is a program example.
[bodo@bakawali ~]$ cat gccarray.C
//**********gccarray.C or gccarray.cpp************
// program to find the total values of an
// array y by passing an array to a function using pointer
#include <iostream>
#define n 7
using namespace std;
// a function prototype
int get_total(int*, int);
int main()
{
int total, y[n]={6,9,2,4,5,23,12};
cout<<"\nCalling function get_total(y, n),";
cout<<"\nBy bringing along the value of y, an array";
cout<<"\nfirst address and n = 7, an array size.";
cout<<"\nAn array name, is the pointer to the";
cout<<"\n1st element of an array\n\n";
// function call, pass along the pointer to the first
// array element and the array size, and the
// return result assign to variable total
total = get_total(y, n);
cout<<"\nSum of the 7 array elements is "<<total<<endl;
return 0;
}
// a function definition
int get_total(int *ptr, int x)
{
int i, total = 0;
// do the looping for array elements...
for(i=0; i<x; i++)
{
// displays the array content, pointed by pointer...
cout<<*(ptr+i)<<" ";
// do the summing up of the array elements...
total += *(ptr+i); //total=total + *(ptr+i);
}
// return the result to the calling program...
return total;
}
[bodo@bakawali ~]$ g++ gccarray.C -o gccarray
[bodo@bakawali ~]$ ./gccarray
Calling function get_total(y, n),
By bringing along the value of y, an array
first address and n = 7, an array size.
An array name, is the pointer to the
1st element of an array
6 9 2 4 5 23 12
Sum of the 7 array elements is 61
[bodo@bakawali ~]$
Check the best selling C / C++, Networking, Linux and Open Source books at Amazon.com.
Linux Socket programming tutorial.
C, Buffer overflow and stack frame (construction and destruction).