If the name of the output file is not specified,
gcc names the output file a.out by default. Not all steps need to be handled by the gcc program
itself, as gcc can hand off processing tasks such as linking to ld, the GNU linker.
The following example uses gcc to create the hello program from the source file hello.c. First,
the source code:
/*
* hello.c - canonical hello world program
*/
#include
int main(int argc, char *argv[])
{
printf("Hello, Linux programming world!\n");
return 0;
}
Now, to compile and run this program, type the following:
$ gcc hello.c -o hello
If all goes well, gcc does its job silently and returns to the shell prompt. It compiles and links the
source file hello.c (gcc hello.c), creating a binary named hello, as specified using the -o
hello argument.
If you run the program, here??™s the output you get:
$ ./hello
Hello, Linux programming world!
The command that executed the hello program specifically included the current directory,
denoted with a . because having the current directory in your path is a security risk. That
is, instead of a $PATH environment variable that resembles /bin:/usr/bin:/usr/local/bin:.,
it should be /bin:/usr/bin:/usr/local/bin so that a cracker cannot put a dangerous command
in your current directory that happens to match the name of the more benign command you really
want to execute.
Pages:
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416