0

this is the error i'm getting.
g++ main.cpp
g++ universityperson.cpp
/usr/lib/gcc/i386-redhat-linux/3.4.6/../../../crt1.o(.text+0x18): In function `_start':
: undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [universityperson.o] Error 1

I'm not going to post all the code i have but here is my makefile main file and universityperson files

//makefile

UniversityPerson : main.o universityperson.o employee.o academic.o faculty.o   \
teacher.o administration.o support.o student.o
        g++ -o UniversityPerson main.o universityperson.o employee.o academic.o\
 faculty.o teacher.o administration.o support.o student.o

main.o : main.cpp universityperson.h
        g++ main.cpp

universityperson.o : universityperson.cpp universityperson.h
        g++ universityperson.cpp

employee.o : employee.cpp employee.h
        g++ employee.cpp

academic.o : academic.cpp academic.h
        g++ academic.cpp

faculty.o : faculty.cpp faculty.h
        g++ faculty.cpp
teacher.o : teacher.cpp teacher.h
        g++ teacher.cpp

administration.o : administration.cpp administration.h
        g++ administration.cpp

support.o : support.cpp support.h
        g++ support.cpp

student.o : student.cpp student.h
        g++ student.cpp

//main.cpp (obviously havent started yet, just a test to compile)
// the include statements include the lowest of the class hierarchy, therefor each of these will 
// include all the way up to universityperson.h which includes lib.h
#include "teacher.h"
#include "administration.h"
#include "support.h"
#include "student.h"

int main( int argc, char *argv[] ){
  return 0;
}

//universityperson.cpp


#include "universityperson.h"

string UNIVERSITYPERSON::getFullName(){
  return fullname;
}

string UNIVERSITYPERSON::getID(){
  return id;
}

string UNIVERSITYPERSON::getPosition(){
  return position;
}

//universityperson.h

#ifndef UNIVERSITYPERSON_H
#define UNIVERSITYPERSON_H

#include "lib.h"

class UNIVERSITYPERSON{

  string fullname, id, position;
 public:
  UNIVERSITYPERSON(){
    fullname = "No Name";
    id = "00000000";
    position = "University Person";
  };

  string getFullName();
  string getID();
  string getPosition();
};
#endif

Edited by Dewey1040: n/a

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by nezachem
0

this is the error i'm getting.
g++ main.cpp
g++ universityperson.cpp

When you invoke g++ with no options, it will try to make an executable. What you need is an object file.
In all your %.o rules (that is, everywhere except UniversityPerson) change g++ to g++ -c . A -c option stands for "compile only", that is produce an object file, to be linked later.

//makefile

UniversityPerson : main.o universityperson.o employee.o academic.o faculty.o   \
teacher.o administration.o support.o student.o
        g++ -o UniversityPerson main.o universityperson.o employee.o academic.o\
 faculty.o teacher.o administration.o support.o student.o

main.o : main.cpp universityperson.h
        g++ [B]-c[/B] main.cpp

universityperson.o : universityperson.cpp universityperson.h
        g++ [B]-c[/B] universityperson.cpp

employee.o : employee.cpp employee.h
        g++ [B]-c[/B] employee.cpp

academic.o : academic.cpp academic.h
        g++ [B]-c[/B] academic.cpp

faculty.o : faculty.cpp faculty.h
        g++ [B]-c[/B] faculty.cpp
teacher.o : teacher.cpp teacher.h
        g++ [B]-c[/B] teacher.cpp

administration.o : administration.cpp administration.h
        g++ [B]-c[/B] administration.cpp

support.o : support.cpp support.h
        g++ [B]-c[/B] support.cpp

student.o : student.cpp student.h
        g++ [B]-c[/B] student.cpp

Edited by nezachem: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.