[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Baffled by cc -o in Make manual

From: Paul Smith
Subject: Re: Baffled by cc -o in Make manual
Date: Tue, 01 Aug 2017 14:02:21 -0400

On Tue, 2017-08-01 at 18:32 +0200, Ray Foulkes wrote:
> I am totally baffled as to what cc -o is doing there. Surely it
> should be ld?? and then the -o is for "output" i.e. create "edit" as
> an executable.

It's generally not recommended that you ever run the linker directly
unless you have special advanced requirements.

The "cc" program is a front-end that manages the invocation of the
preprocessor, C compiler, assembler, and linker.

The -o flag controls the name of the output, and other flags control
how much of the preprocess/compile/assemble/link chain is invoked. 
When you run "cc" with the "-c" option for example, it will stop after
the assembler and will not run the linker.  That's why a normal
"compile .c into .o" command will be:

  cc -c -o foo.o foo.c

Without the "-c" option the linker will be invoked, so:

  cc -o foo foo.o

will call the linker.

If you run "ld" directly then it's up to you to ensure that you've
added all the special compiler libraries such as -lgcc, -lc, etc.  In
contrast, if you allow the "cc" front-end to run the linker it will add
in all these libraries for you automatically, so you only need to add
any non-standard libraries yourself.

This is (or should be) all described in the documentation for your
compiler; it's not really related to make itself.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]