Solved

Term Check

Posted on 2004-09-17
5
281 Views
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

?????????????????
0
Comment
Question by:edelossantos
  • 2
  • 2
5 Comments
 
LVL 11

Assisted Solution

by:avizit
avizit earned 250 total points
ID: 12082131
http://en.wikipedia.org/wiki/Linker  

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

Assisted Solution

by:avizit
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

 
0
 
LVL 4

Accepted Solution

by:
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.
0
 
LVL 4

Assisted Solution

by:pankajtiwary
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.

Cheers!!!
0
 

Author Comment

by:edelossantos
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.o:
      ${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

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

//util.h

#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);              

#endif

//util.cpp
   

#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...");
   cin.get(ch);
   clearScreen();
}

void flushInput ()
{
   char buff[81];
   if (cin)
      cin.getline(buff,80);    
}

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

void Error(char *message)
{
   cout << message;
   //exit(1);
}
/*
void EatWhiteSpace()
{
    char ch;
    do {
      cin.get(ch);
    }
   while(isspace(ch));

    if(ch != EOF)
      cin.putback(ch);
}*/

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

//life.h
   
#ifndef LIFE_H
#define LIFE_H

static const int maxrow = 20, maxcol = 60;  

class Life {

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

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

};

#endif

//life.cpp

#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;
         else
            cout << "Column " << col << " is out of range." << endl;
      else
         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.
            break;
         case 3:
            new_grid[row][col] = 1;                //  Cell is now alive.
            break;
         default:
            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;
   clearScreen();
   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()
{
   clearScreen();
   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;
}

//main.cpp

#include<iostream>

//using namespace std;

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

int main()  {
   Life configuration;
   configuration.instructions();
   configuration.initialize();
   
   char continue_flag = 'n' ;
   cout << "Viewing new generations? " << endl;
   cin>>continue_flag;
   while (  (continue_flag == 'y' ) ||  (continue_flag =='Y')  ) {
             configuration.update();
             cout << "Continue viewing new generations? " << endl;
             cin>>continue_flag;
   }
}

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



0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now