Article View: news.software.nntp
Article #24146Re: compiling problem.
From: Kai Ruottu
Date: Mon, 08 Dec 1997 00:00
Date: Mon, 08 Dec 1997 00:00
248 lines
12006 bytes
12006 bytes
On 4 Dec 1997 10:34:02 -0800, Ron Echeverri
<rone+usenet@bofh.noc.best.net> wrote:
>In article <34861B45.4ACB8384@inow.com>,
>Jesse Rivera <jrivera@riscorian.com> wrote:
>>I'm not sure if this is a unix, news, or gcc problem but hopefully
>>someone has seen this:
>
>>Building subst...
>>cc -o subst subst.c
>>collect2: cannot find `ld'
>>collect2: ld returned 1 exit status
>>*** Error code 1
>>make: Fatal error: Command failed for target `c'
>
>>I can't seem to get past this. What is 'ld' and 'collect2'? Any
>>assistance would be greatly appreciated.
>
>This is clearly not a unix, news, or gcc problem, but a compiler
>problem. Meaning, the guy who's compiling the software needs to find
>someone who actually knows what he's doing.
I think this is a educational problem. I have met a lot of students
who have passed their C course without knowing afterwards why they put
the '#inlude' rows into a program and what the hell happens during the
compile process...
Looking e.g. the Borland C/C++ bin-directory we'll find 'cpp.exe',
'brcc.exe' and 'tlink.exe' which seem to be the compiler passes. But
the compiler passes aren't handled during a C course -- It doesn't
seem to matter at all how the compiler works, just only how to use
its IDE controls...
When learning to drive a car, it normally doesn't matter how the car
works, but when it doesn't work any more, one must be able to check if
there aren't any gasoline or the accumulator is empty... So, one must
know a little how a car works. A compiler user must know a little how
a compiler works in order to solve the possible simple problems...
Perhaps this is a 'when everybody already knows this, why put it
here' - like syndrom the gcc manual writers have... It's possible that
an author writing about Borland or MS compilers doesn't know the
compile process him/herself, so don't expect to find a compile process
chart from those "Teach Yourself C in 1 hour" - like books...but I
expect a gcc manual writer to know this and also to tell it to the
readers...
When we look at the GCC based compilers from some commercial
providers, e.g. from Motorola, we'll surely find a figure about the
compile & develope process in the first pages of the User's Manual.
(Look e.g. at the DSP563CCC User's Manual). These writers know how
stupid and ignorant the reader can be...
But when we look at the "Using and Porting GNU CC" from RMS, or "The
Linux Programmer's Guide", there aren't any chart or figure about the
compile process. I don't remember DJGPP docs have anything about this,
neither emx nor cygwin32 docs...
So, where all these poor askers will find info about why and where
'cpp', 'cc1', 'as', 'ld' etc will be needed? The only way seems to be
to ask someone who knows, but I'm really tired to see these simple
questions in all the news groups...
Let's send mail to RMS, DJ, Eberhard & Co. and ask them to put a
chart about the compile process into their 'User's Manual's every time
we see these "cannot find cpp, what is cpp anyway?" - like questions.
I have seen hundred or so of these only in the cygwin32 mailing list.
And let's ask them to teach to use the 'gcc -print-search-dirs',
'gcc -v' etc. commands to solve problems after just installing gcc...
An example about "How to compile the famous 'hello_world.c'" would
also be nice because a lot seem not to know how to compile with gcc...
Here's a prototype, a sample from the "Embed with the GNU Development
Tools" that I'm preparing, borrowing stuff from the Cygnus "Embed with
GNU" docs and using my non-native bad English... (This will be
available as a texinfo src and converted to dvi, ps and WinHelp
documents, if I find a ftp-site to hold it...). Perhaps if I had
written this using english, not bad English, this weren't so bad...;-)
The good thing is that I mustn't speak, otherwise it would happen just
like it happened to one of our previous foreigng ministers, whose
words were written in paper as: "I hope that we should live in peace",
but he spoke "I hope that we should leave in piss"...
---------------
Introduction
The free GNU C/C++ compiler, gcc is not anyhow different from a normal
commercial C/C++ compiler working under UNIX or DOS. What makes the
difference nowadays, is the lack of a common IDE, (Integrated
Development Environment) for the common GUI's like Windows and X
Window, where to edit programs and from where to use all the compiler
tools. Instead of an IDE, GCC uses still the 'old method' and is
normally used from the command line. Furthermore, the building of a
project, which consists from many source files and dependencies
between them, is organized with using makefiles and the make utility
to handle them.
That said, there are some IDE's available, however. One of these is
Fred Kruse's xwpe X Window Programming Environment, which can be
compiled as a Borland like IDE for DOS/DJGPP or UNIX (using the ANSI
etc. terminal controls), or as a X Window application. Another well
known IDE is RHIDE, which works only with DJGPP. But there is no
approved standard for the GCC-IDE yet.
Most of the current commercial C/C++ compilers can also be used from
the command line and have the make utility, but it is more common to
use the included IDE interface, when teaching C/C++ for beginners.
So, the lack of a standard IDE for GCC seems to be a big problem for
those used to work under MS Windows, Macintosh or OS/2. However, for
the old C/C++ veterans there is nothing weird in using GCC from the
command line.
The next sections will describe the GNU C/C++ compiler structure, its
options, and the environment variables that can be used to control its
functionality. Furthermore the GNU assembler, as, the GNU linker, ld,
and the GNU debugger, gdb, will be handled too. We will use the name
GNU development tools to mean these all. Although the options for the
various GNU development tools are covered in more detail elsewhere,
the amount of options can be an overwhelming amount of stuff, so the
options most suited to embedded systems are summarized here in this
document.
Tool names How to call the tools.
Invoking GCC Using GCC and its common options.
GCC structure What programs are needed for a compile.
<clipping tool names>
Invoking GNU C/C++
GCC by itself only compiles the C or C++ code into assembler.
Typically GCC invokes all the passes required for you. The following
figure shows the developing process.
Figure 1. Developing with GNU C/C++
If we would want to compile the following C language "Hello world"
program, saved as the file hello.c :
#include <stdio.h>
int
main (void)
{
printf("Hello World\n");
return 0;
}
and make an executable program, as the file hello, this could be done
using the following command line:
gcc -o hello hello.c
The user could take the command gcc as the GNU C/C++ compiler, but it
is only the compiler driver, which starts all the programs needed for
the compiling as subprocesses and gives them all the needed options
and filenames.
The previous example is only a simply case, and in real work it is not
common to compile a program just in one big slump into an executable.
Normally it is divided into separately compiled source modules, which
after compiling will be linked together (with the already compiled
library objects in the C Standard Library and other libraries) to form
the final executable.
The structure of GNU C/C++
As we saw in the Figure 1, the GNU C/C++ compiler consists of three
programs:
� The compiler driver, gcc, is a program that parses and interprets
the command line, and then calls each of the other needed programs in
sequence, depending on its input programs and the command line
options. The usual gcc command line will cause ld to link in the
startup code and additional libraries by default.
� The macro preprocessor, cpp, is the C preprocessor. Its input is a
program file optionally containing preprocessing commands. It will
merge in the include files, expand all macros definitions, and process
all the #ifdef sections. To see the output of ccp, invoke gcc with the
-E option, and the preprocessed file will be printed on the stdout.
� The C or C++ language processor, cc1 or cc1plus, parses and
optimizes its input C or C++ program, and generates an machine
specific assembly (symbolic machine code) program.
The program's output must be assembled by the GNU Assembler, as, to
produce an object code program. as is automatically called by the gcc
driver (unless you use the -S option).
GNU assembler started it's life to only function as a compiler pass,
but these days it can also be used as a source level assembler. When
used as a source level assembler, it has a companion assembler
preprocessor called gasp. This has a syntax similar to most other
assembler macros packages. gas emits a relocatable object file from
the assembler source. The object file contains the executable part of
the application, and debug symbols.
You produce an executable program by using the GNU linker, ld, to link
one or more object files and, optionally, run-time libraries. ld is
also automatically called by the gcc driver (unless you use the -c
option).
ld is responsible for resolving the addresses and symbols to something
that will be fully self-contained. Some RTOS's use relocatable object
file formats like a.out, coff or elf but more commonly the final image
will only use absolute addresses for symbols. This enables code to be
burned into PROMS as well.
Although ld can produce an executable image, there is usually a hidden
object file named crt0.o that is required as startup code. With this
startup code and a memory map, the executable image will actually run
on the target environment. The startup code usually defines a special
symbol like _start that is the default base address for the
application, and the first symbol in the executable image. See
Porting libgloss.
If you plan to use any routines from the Standard C library, you'll
also need to implement the functions that this library is dependent
on. See Porting newlib.
The executable image can be loaded into the target system through a
serial communications line or sometimes even using ftp (with TCP/IP)
on a LAN. Or the program can be converted into a Intel hex file and
burned into a EPROM, which will then put into the target system, or it
must also be converted into a Intel hex or Motorola srec or some other
format before loading into the target system. One of the GNU binutils
programs, objcopy, is aimed at these conversion tasks. See What to do
now.
Debugging the program is possible with GDB (configured as a remote
debugger) talking with the target system through a serial
communications line or even using telnet on a LAN. See Porting GDB.
Many targets can have also a simulator program, run, available. This
can execute the compiled and linked program on the host system and
tries to simulate the target processor and the target system as well
as possible. A connection with GDB is possible with the gdb command
target sim. So, a lot of debugging can perhaps be done without needing
the target system.
-----------
Technical Details
Message-ID:
<348c784e.20396398@news.freenet.hut.fi>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-comp.unix.admin.mbox.zip!not-for-mailReferences:
<34861B45.4ACB8384@inow.com> <666t2q$jj0$1@bofh.noc.best.net>Show Full Headers
Complete Article Headers
Message-ID: <348c784e.20396398@news.freenet.hut.fi> Subject: Re: compiling problem. Date: Mon, 08 Dec 1997 00:00:00 +0000 From: karuottu@freenet.hut.fi (Kai Ruottu) References: <34861B45.4ACB8384@inow.com> <666t2q$jj0$1@bofh.noc.best.net> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-comp.unix.admin.mbox.zip!not-for-mail X-Deja-AN: 296419532 Organization: Freenet Finland Newsgroups: comp.unix.admin,gnu.gcc.help,news.software.nntp