我正在尝试做一个任务,程序在我的家里编译得很好 PC(Netbeans)但是当我尝试在Uni Sun盒子上编译时,我得到以下错误
编译标志:g ++ -lm -ansi -Wall -pedantic skyhigh.cpp -o skyhigh
Undefined first referenced
symbol in file
Flight::GetSeats() /var/tmp//cc49OAwj.o
Flight::GetCost() /var/tmp//cc49OAwj.o
Flight::GetAircraft() /var/tmp//cc49OAwj.o
ld: fatal: Symbol referencing errors. No output written to skyhigh
collect2: ld returned 1 exit status
我非常感谢任何帮助,因为我花了好几个小时梳理互联网 解决方案
FLIGHT.H文件
//
// flight.h
//
// Parent Flight class
//
#ifndef __FLIGHT_H__
#define __FLIGHT_H__
#include<iostream>
#include<string>
using namespace std;
/*TO DO REQUIRED HEADER FILES AND NAMESPACES*/
class Flight
{
protected:
string aircraft;
string category;
int seats;
double cost;
public:
virtual ~Flight(){};
// virtual void Display() =0;
void SetAircraftType(string air);
string GetAircraft();
int GetSeats();
double GetCost();
void SetSeats(int seat);
//TO DO
// Prototypes of all the Item functions
};
#endif
FLIGHT.CPP FILE
#include "flight.h"
string Flight::GetAircraft(){
return aircraft;
}
int Flight::GetSeats(){
return seats;
}
double Flight::GetCost(){
return cost;
}
void Flight::SetSeats(int seat){
seats=seat;
}
void Flight::SetAircraftType(string category){
aircraft = category;
}
MAIN FILE
// skyhigh.cpp for CPT 323 Assignment 1 SP3 2013
//
//
// CPT323 2013 assignment 1
#include "skyhigh.h"
/////////////////////////////////////////////////////
int main()
{
Flight newflight ;
cout<< "Plane Name:" <<newflight.GetAircraft()<< " Seats: "<< newflight.GetSeats()<<"Cost: "<<newflight.GetCost()<< endl;
Scenic newflight2 ;
//cout<< "Plane Name:" <<newflight2.GetAircraft()<< " Seats: "<< newflight2.GetSeats()<<"Cost: "<<newflight2.GetCost()<< endl;
//Scenic* sptr=&newflight2;
//BookingSheet booking;
//cout<< booking.GetDay()<<booking.GetTime()<<booking.GetPassengerName()<<booking.GetPaymentStatus()<<endl;
int finished = 0;
do {
/*Create array for use in menu options*/
cout << "Main Menu : " <<endl;
cout << "1) Add a flight booking "<<endl;
cout << "2) Remove a flight booking "<<endl;
cout << "3) View current booking sheet " <<endl;
cout << "0) Exit \n" <<endl;
cout<< "Please make a selection (0-3) ";
int selection;
cin>> selection;
/*Capture user selection default in switch statement validates 1-9*/
// fgets(option,sizeof(option),stdin);
//
//
switch (selection) {
case 0:
cout << "Thanks for using the SkyHigh Booking System"<<endl;
finished=1;
break;
case 1:
cout << "1) Add a flight booking "<<endl;
break;
case 2:
cout << "2) Add Customer "<<endl;
break;
case 3:
cout << "3) Display Stock " <<endl;
break;
default:
printf("Valid input is 0-3 \n");
}
}
while(!finished);
return 0;
}
生成文件
skyhigh: skyhigh.o utility1.o flight.o scenic.o aerobatic.o
g++ skyhigh.o utility1.o flight.o scenic.o aerobatic.o -o skyhigh
skyhigh.o: skyhigh.cpp skyhigh.h flight.h aerobatic.h scenic.h
g++ -ansi -Wall -pedantic -gstabs -c skyhigh.cpp
utility1.o: utility1.cpp utility1.h
g++ -ansi -Wall -pedantic -gstabs -c utility1.cpp
flight.o: flight.cpp flight.h aerobatic.h scenic.h
g++ -ansi -Wall -pedantic -gstabs -c flight.cpp
scenic.o: scenic.cpp scenic.h
g++ -ansi -Wall -pedantic -gstabs -c scenic.cpp
aerobatic.o: aerobatic.cpp aerobatic.h
g++ -ansi -Wall -pedantic -gstabs -c aerobatic.cpp
clean:
rm -f *.o core *.report *.errs
答案 0 :(得分:0)
找不到定义缺失函数的目标文件。确保添加生成的目标文件以进行链接。类似的东西(主要是exec名称和main.o是具有main函数的对象,根据需要更改它们):
g++ -o main main.o skyhigh.o utility1.o flight.o scenic.o aerobatic.o