Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #60656

Re: Fist steps in compiling, gcc commands confusion

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.lang.c
Subject Re: Fist steps in compiling, gcc commands confusion
Date 2015-04-21 12:01 -0400
Organization Self
Message-ID <55367443.1000308@verizon.net> (permalink)
References <9f1b89ff-cf47-4e01-b137-ba263e9e75f1@googlegroups.com>

Show all headers | View raw


On 04/21/2015 11:18 AM, Alla _ wrote:
> Hello!
> 
> Different resources advice different commands to compile a file:
> 
> 1) gcc sample.c sample
> 
> 2) gcc sample.c -o sample
> 
> 3) gcc -o sample.c
> 
> What are the difference in the meaning? What does -o stand for?

"-o filename" tells gcc to give the output file the specified file name.
By default, it uses a.out.

Command 1 tells gcc to compile two files, one named sample.c and the
other named sample, and to create a program named a.out from them. Since
sample has no extension, gcc can't tell what kind of file it is - my
experiments suggest that it defaults to assuming that "sample" contains
a linker script. I don't know anything about linker scripts.

Unless the resource that recommended command 1 went on to explain how to
construct and use linker scripts, ignore all advice from that resource
about using gcc.

Command 2 tells gcc to compile and link sample.c and to name the
resulting program "sample".

Command 3 tells gcc to name the output file "sample.c", but it doesn't
identify any input files. gcc understandably complains about this.
Ignore all advice you get from this resource about using gcc.

> The only command that produced results for me was gcc sample.c -o sample
> Although the book suggests simple gcc sample.c

That works, but it names the output file a.out. You'll generally want to
rename the your program to something else, so it's simpler instruct gcc
to give it the right name from the beginning.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Fist steps in compiling, gcc commands confusion Alla _ <modelling.data@gmail.com> - 2015-04-21 08:18 -0700
  Re: Fist steps in compiling, gcc commands confusion Alla _ <modelling.data@gmail.com> - 2015-04-21 08:25 -0700
    Re: Fist steps in compiling, gcc commands confusion Morris Dovey <mrdovey@iedu.com> - 2015-04-21 10:56 -0500
      Re: Fist steps in compiling, gcc commands confusion David Brown <david.brown@hesbynett.no> - 2015-04-22 09:35 +0200
        Re: Fist steps in compiling, gcc commands confusion James Kuyper <jameskuyper@verizon.net> - 2015-04-22 11:15 -0400
          Re: Fist steps in compiling, gcc commands confusion David Brown <david.brown@hesbynett.no> - 2015-04-23 01:31 +0200
        Re: Fist steps in compiling, gcc commands confusion Keith Thompson <kst-u@mib.org> - 2015-04-22 08:43 -0700
          Re: Fist steps in compiling, gcc commands confusion Bartc <bc@freeuk.com> - 2015-04-22 18:57 +0100
            Re: Fist steps in compiling, gcc commands confusion Keith Thompson <kst-u@mib.org> - 2015-04-22 11:35 -0700
  Re: Fist steps in compiling, gcc commands confusion James Kuyper <jameskuyper@verizon.net> - 2015-04-21 12:01 -0400
  Re: Fist steps in compiling, gcc commands confusion John Gordon <gordon@panix.com> - 2015-04-21 16:01 +0000
    Re: Fist steps in compiling, gcc commands confusion Tim Prince <tprince@computer.org> - 2015-04-21 13:11 -0400
    Re: Fist steps in compiling, gcc commands confusion Keith Thompson <kst-u@mib.org> - 2015-04-21 12:09 -0700
  Re: Fist steps in compiling, gcc commands confusion Bartc <bc@freeuk.com> - 2015-04-21 18:25 +0100
    Re: Fist steps in compiling, gcc commands confusion Keith Thompson <kst-u@mib.org> - 2015-04-21 12:11 -0700
  Re: Fist steps in compiling, gcc commands confusion Keith Thompson <kst-u@mib.org> - 2015-04-21 11:16 -0700

csiph-web