[Top][All Lists]

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

automatic linking links too many files

From: Federico Poloni
Subject: automatic linking links too many files
Date: Fri, 22 May 2009 13:56:03 +0200
User-agent: Thunderbird (X11/20090318)

Hello everyone,
According to GNU Make documentation,

> Linking a single object file
n is made automatically from n.o by running the linker (usually
called ld) via the C compiler. The precise command used is `$(CC)

This rule does the right thing for a simple program with only one
source file. It will also do the right thing if there are multiple
object files (presumably coming from various other source files), one
of which has a name matching that of the executable file.
Each kind of file automatically made into `.o' object files will be
automatically linked by using the compiler (`$(CC)', `$(FC)' or
`$(PC)'; the C compiler `$(CC)' is used to assemble `.s' files)
without the `-c' option. This could be done by using the `.o' object
files as intermediates, but it is faster to do the compiling and
linking in one step, so that's how it's done.

But when I try to make this simple example with three files:

`Makefile' contains:
executable: textfile

`executable.cpp' contains:
int main(){
  return 0;

`textfile' contains:

the output of `make' is
g++     executable.cpp textfile   -o executable
/usr/bin/ld:textfile: file format not recognized; treating as linker script
/usr/bin/ld:textfile:1: Error: syntax error
collect2: Error: ld returned 1 exit status
make: *** [executable] Error 1

That is, make tries to pass textfile to the linker even if it is not a "kind of file automatically made into `.o' object files".

Is this a bug or am I missing something?

The command `make --version' on my machine returns
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A

This program built for x86_64-pc-linux-gnu

Federico Poloni

reply via email to

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