Term Check

Posted on 2004-09-17
Last Modified: 2012-05-05
I gave it a shot,...but I am not sure of my anwers.  Please advise.  Del

What is a linker and what tasks does it perform? (try 'man ld')

The ld command invokes the DIGITAL UNIX link editor ("linker") which links
extended COFF object files.

Explain each line of the following output from the make utility.
cxx -c -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall  life.cpp

life.cpp compiled.

cxx -c -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall  util.cpp

util.cpp compile.

cxx -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall  -lm -ltask main.o life.o util.o
 -o main

compilation unit object files.

ld (prelink):

load option.

util.o compressed: x: multiply defined

Question by:edelossantos
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 11

Assisted Solution

avizit earned 250 total points
ID: 12082131  

will explain clearly what a linker is  , you can write your answer in short after you read it and understand it :)
LVL 11

Assisted Solution

avizit earned 250 total points
ID: 12082178
for the other part , e.g

cxx -c -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall  life.cpp

I think you can also explain the options

as in  what does    -L ,  -D . -w etc denote

I know for gcc/g++ but you should do a

"man cxx" and see what they mean on a Digital UNIX machine

e.g -L  directory

would be the additional directory you specify , so that the linker searches for the libraries there in addition to the standard system directories etc etc


Accepted Solution

pankajtiwary earned 250 total points
ID: 12082258
Hi edelossantos,

Hang on, First you need to know what a makefile is. Read the following lines carefully. And then you will find all your answers.

You can work without makefiles. But makefiles are used to ease your work. Lets say you have various .cpp and .h files that are all interrelated. May be there are some dependencies between the files. And you got to change a piece of code in one of the cpp files and relink it with the executable. One thing you can do is you can only compile that cpp file and just link it with the other objects which are already existing due to previous compilation. For all the cpp files you need to prepare commands to compile that particular file and then link it with the esisting ones. To solve this complexity, you create a make file. Remember, it has nothing to do with the C or C++ language. In the makefile you specify what is the target to make and how to buid those targets from the scratch. For example the final binary a.out may need a.o and b.o as input files. a.o in turn need a.c and a.h files for compilation. The beauty of makefile is only the files which have been changed will be re treated. That means all the modules which are dependent of the file (that is being changed) will be reproduced and only linking will be done at the last. Now your answers:

1. What is a linker and what tasks does it perform?

Ans: A linker is a utility which links various object files (also called modules) and produces the final executable or binary. Remember input to linker is object files not the source files (c/cpp).

2. cxx -c -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall  life.cpp (what does it do)

Ans: When you make a code, depending on what modules need to be regenerated, the make utility fires the appropriate command. The above written line is actually a command that the make utility is executing as a result of change in the file life.cpp. The cxx is the c++ compiler. -c switch tells the cxx aommand to just produce the object and not to link it. In the ebsence of -c switch, the compiler compiles as well as try to link if possible. The switch -L/usr/lib/cmplrs/cxx tells the cxx command to use the specified directory to find other system defined object files if al all necessary. -DPOSIX_4D9 defines a macro which may be checked inside the source code at the time of preprocessing and the object will be generated accordingly. Similarly other switch solve other purpose. The final input given to the cxx  command is the file name life.cpp. After the successful ececution of the command, you should be having a file named life.o.

3. cxx -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall  -lm -ltask main.o life.o util.o -o main

Ans: From the previous explaination, you can make out that this command takes input main.o, life.o and util.o (which have already been made due to ececution of previous commands), links those files (because they are already compiled) and the output file should be named as main (default name is a.out).

Actually from the source to binary translation, there are three entities involved.

a. cpp: this is the preprocessor
b. cxx: This is the compiler which converts a translation unit to object code.
c. ld: This is the linker which combines or links various object files to produce the executable.

When you fire cxx command without any arguments, cxx command executes all the three services in the order they are defined above.

Hope this helps.

Assisted Solution

pankajtiwary earned 250 total points
ID: 12082296
If you want to know the problem first chech whether you have util.o, life.o and main.o already made. If not made you can make them using command

cxx -c -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall  <filename>.cpp

where filename should be replaced with life, util and main in different commands. If this is done then command:

cxx -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall  -lm -ltask main.o life.o util.o -o main

In case you are having problems executing the above commands, please post the errors and we will try to resolve them.


Author Comment

ID: 12083537
# Makefile:
#        It uses the C++ Compiler with all warnings and
#        full debugging; will create a single executable called 'main'
# ---------------------------------------------------------------
# Note: If you want to use the g++ compiler on pegasus or helios
# uncomment the g++ lines and comment the Digital Unix lines

# the Digital Unix C++ compiler needs these lines:
CPP = cxx
CFLAGS = -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall

# the g++ compiler on pegasus and helios needs these lines:
# CPP = g++
# CFLAGS = -DPOSIX_4D9 -w -g

# link in the math library
LFLAGS = -lm

RM = rm -f
# ----------------------------------------------------------------
# Explanation of macros:
#     $< is any dependent file which is out of file1
#     $* is the target's basename (without extension)
#     $@ is the target's fullname
# add suffix .cpp since it is not a default with make util
.SUFFIXES:      .cpp .o
# implicit rule for compilation only:
      ${CPP} -c ${CFLAGS} $<

OFILES=            main.o life.o util.o

HFILES=            life.h  util.h

# dependencies
default:      main      
main:           $(OFILES)
      ${CPP} ${CFLAGS} ${LFLAGS} $(OFILES) -o $@

main.o:            main.cpp life.h util.h
life.o:            life.cpp life.h util.h
util.o:            util.cpp util.h

      ${RM} *.o
      ${RM} core
veryclean:      clean
      ${RM}  main  


#ifndef UTIL_H  
#define UTIL_H  

#define NULL 0L

#define STDSCREEN 80        
#define DOWN 0                        
#define UP   1
#define END   0
#define START 1
#define FAIL    0
#define SUCCESS 1
#define MISS -1
#define HIT   1

   enum Error_code { success, fail, range_error, underflow, overflow, fatal,
                  not_present, duplicate_error, entry_inserted, entry_found,
                  internal_error };

   void clearScreen ();                    
   void clearTop();                        
   void clearBelowTop();                  
   void goTop();                              
   void topLine(const char * text = " "  );    
   void bottomLine (char * text = " ");  

   void hitAnyKey ();                    
   void flushInput ();                    
   void Warning(char *);                  
   void Error(char *);                    
   bool promptYesNo(char * prompt="");      
   void EatWhiteSpace(void);              



#include <iostream>
//#include <cstdlib>
//using namespace std;

#include "util.h"

void clearScreen (void)
  cout << "\033[2J";              cout << "\033[;f";          

void clearTop()
  {cout << "\033[0;0f" << "\033[0K";}

void clearBelowTop()
  {cout << "\033[1;0f" << "\033[1B" << "\033[J";}

void goTop ()
  {cout << "\033[0;0f";}

void topLine(const char str[])
  {cout << "\033[0;0f" << "\033[0K" << str;}

void bottomLine (char * str)
  {cout << "\033[23;0Hf" << "\033[2K" << str;}

void hitAnyKey ()
   char ch;
   bottomLine ("Hit any key to continue...");

void flushInput ()
   char buff[81];
   if (cin)

void Warning(char *message)
   cout << message;

void Error(char *message)
   cout << message;
void EatWhiteSpace()
    char ch;
    do {

    if(ch != EOF)

bool promptYesNo(char * c)
   char ch;
   cout << c << " [y|n]?";
   do {
      } while (ch != 'y' && ch != 'n');
   return (ch == 'y');

#ifndef LIFE_H
#define LIFE_H

static const int maxrow = 20, maxcol = 60;  

class Life {

   void initialize();
   void initializeRandom();
   void print();
   void update();
   void instructions();

   int grid[maxrow+2][maxcol+2];  
   int neighbor_count(int row, int col);




#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>

#include <time.h>

using namespace std;

#include "util.h"
#include "life.h"

void Life::initialize()
   int row, col;
   for (row = 0; row <= maxrow+1; row++)
      for (col = 0; col <= maxcol+1; col++)
         grid[row][col] = 0;
   cout << "\nList coordinate pair for living cells (e.g. 4 5)"
        << " or -1 -1 to end:" << endl;
   cin >> row >> col;

   while (row != -1 || col != -1) {
      if (row >= 1 && row <= maxrow)
         if (col >= 1 && col <= maxcol)
            grid[row][col] = 1;
            cout << "Column " << col << " is out of range." << endl;
         cout << "Row " << row << " is out of range." << endl;
      cin >> row >> col;

int Life::neighbor_count(int row, int col)
   int i, j;
   int count = 0;
   for (i = row - 1; i <= row + 1; i++)
      for (j = col - 1; j <= col + 1; j++)
          count += grid[i][j];    //  Increase the count if neighbor is alive.
         count -= grid[row][col];  //  Reduce count, since cell is not its own neighbor.
   return count;

void Life::update()
   int row, col;
   int new_grid[maxrow + 2][maxcol + 2];

   for (row = 1; row <= maxrow; row++)
       for (col = 1; col <= maxcol; col++)
         switch (neighbor_count(row, col)) {
         case 2:
            new_grid[row][col] = grid[row][col];   //  Status stays the same.
         case 3:
            new_grid[row][col] = 1;                //  Cell is now alive.
            new_grid[row][col] = 0;                //  Cell is now dead.

   for (row = 1; row <= maxrow; row++)
      for (col = 1; col <= maxcol; col++)
         grid[row][col] = new_grid[row][col];

void Life::print()
   int row, col;
   cout << "The current Life configuration is:" <<endl;
   for (row = 1; row <= maxrow; row++) {
      for (col = 1; col <= maxcol; col++)
         if (grid[row][col] == 1) cout << '*';
         else cout << ' ';
      cout << endl;
   cout << endl;

void Life::instructions()
   cout << "Welcome to Conway's game of Life." << endl;
   cout << "The grid contains "
        << maxrow << " by " << maxcol;
   cout << " cells, each occupied by an organism or not." << endl;
   cout << "The occupied cells change from generation to generation" << endl;
   cout << "according to the number of neighboring cells which are alive."
        << endl;



//using namespace std;

#include "util.h"
#include "life.h"

int main()  {
   Life configuration;
   char continue_flag = 'n' ;
   cout << "Viewing new generations? " << endl;
   while (  (continue_flag == 'y' ) ||  (continue_flag =='Y')  ) {
             cout << "Continue viewing new generations? " << endl;

please check...program is hanging up and doesn't run.


Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question