[Courses] Some gcc options
Dave Killion
Dkillion at netscreen.com
Mon Jul 15 07:56:58 EST 2002
Mary,
I'm brand new to the LinuxChix lists, but have a question on your post.
I'm also relatively new to *nix programming/compiling. I've seen -Wall
added when I compile stuff I've downloaded. What specifically does -Wall
do?
Thanks for your patience. I'll post a who-am-I soon. ;)
-Dave
-----Original Message-----
From: Mary [mailto:mary-linuxchix at puzzling.org]
Sent: Monday, July 15, 2002 7:26 AM
To: Courses
Subject: [Courses] Some gcc options
The GNU Compiler Collection (gcc) is the most common C compiler found on
Linux systems. It is a command line compiler. These examples assume that you
are in the directory where your source file (I have called it source.c here,
just name them something.c)
The simplest gcc command:
gcc source.c
This produces a file in the current directory called a.out, which is
executable. You can run it with the command "./a.out" (./ means look in the
current directory rather than $PATH)
Some flags you should use:
gcc -Wall -pedantic source.c
These turn on extra warnings.
These warnings are things that gcc considers compilable, but abnormal. For
example, a memory address[1], which you store in a pointer, is just an
integer. But if you try and set an integer equal to the memory address
stored in a pointer, gcc picks up that you probably aren't storing a *value*
in the int, but an *address of a value*, or the address where the value is
kept, and will warn you.
Now, supposing you want to produce a file that is not called "a.out", you
would do something like
gcc -Wall -pedantic -o myProgram source.c
and then you can execute "./myProgram"
Quick Warning: There is often already a executable on your system called
"test". By default it prints no output. While you could still call your
output file "test" and execute it with "./test", many people have wondered
why their test file produces no output when run!
Quick Warning #2: The name directly after the -o is where gcc will write to.
I once destroyed several hours work by typing "gcc -Wall -pedantic -o
source.c myProgram" - which compiled over the top of source.c !
If you want to compile several C files into one program:
gcc -Wall -pedantic [-o myProgram] source1.c source2.c source3.c
etc...
-Mary.
[1] Each location in memory has a unique address, which is just a number.
_______________________________________________
Courses mailing list
Courses at linuxchix.org http://mailman.linuxchix.org/mailman/listinfo/courses
More information about the Courses
mailing list