gcc questions
Berna Massingill
bmassing at cs.trinity.edu
Sun Nov 27 19:40:49 UTC 2005
On Sun, Nov 27, 2005 at 10:33:36AM -0500, Matthew Miller wrote:
>> On Sat, Nov 26, 2005 at 01:16:25PM +0200, Dotan Cohen wrote:
>> > Also, all files that gcc outputs are of the name a.out. I want it to
>> > give the .out file the original name of the file, with a .out. I have
>> > manned and discovered the -o option, whereby I can specify a filename,
>> > but I would prefer that it would read the original filename and use
>> > that. For instance:
>> > $gcc mycode.c
>> > $ls
>> > mycode.c mycode.out
>> > How can I encourage this behaviour? Thank you.
>>
>>
>> Oh, hey, I missed this part of the question. There's a neat trick if you
>> have GNU Make, which you do on Fedora (and just about any Linux distro).
>> If you have a simple C program with just one source file and no special
>> linking needs, you can do this:
>>
>> make mycode
>>
>> Note not mycode.c -- it'll automatically figure out that it can make the
>> executable mycode from mycode.c. And you don't even have to have a Makefile!
This does produce an executable called "mycode" rather than
"mycode.out" -- which more Unix-ish, but *might* not be what the
OP wants.
Another neat trick:
The above use of "make" works because "make" has a built-in rule for
compiling "mycode.c" to give "mycode". You can change / add to the
parameters it uses by providing a makefile (text file called "makefile"
or "Makefile") with a definition of variable CFLAGS. E.g., if this
file contains the line
CFLAGS= -Wall -pedantic
then "make mycode" will compile mycode.c with the -Wall and -pedantic
flags. Read about these flags in the "man" page, of course ....
Oh, and if the executable really needs to be called mycode.out?
that can be done with a "pattern rule" in a makefile, or with a little
shell script. Someone here can probably help with either approach.
--
-- blm
More information about the fedora-list
mailing list