C++ 获取未定义的符号错误
C++ Getting undefined symbol error
>我正在尝试做作业,程序在我的家编译得很好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
任何帮助将不胜感激,因为我花了几个小时梳理互联网对于解决方案
飞行。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
它找不到定义这些缺失函数的对象文件。请确保添加生成的对象文件以进行链接。类似的东西(main 是 exec 名称,main.o 是带有 main 函数的对象,根据需要更改它们):
g++ -o main main.o skyhigh.o utility1.o flight.o scenic.o aerobatic.o
相关文章:
- 在C++中使用内联方法时出现未定义的符号错误
- 当 lib 已添加到其他依赖项时,如何在 VS 中调试未解析的外部符号错误
- 函数指针给我"重新声明为不同类型的符号"错误
- "byte":使用Crypto++和Windows SDK时出现不明确的符号错误
- 函数路径追加上未解决的外部符号错误
- 作为成员的静态类模板实例会导致未解析的外部符号错误
- C++ XCODE ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -
- 共享库中使用"使用命名空间"定义的符号错误
- 在FreesWitch中使用AWS C SDK加载模块时未定义的符号错误
- 在 Mac 上C++编译代码时处理“dyld:惰性符号绑定失败:找不到符号”错误
- C++编译错误LNK2019:未解决的外部符号错误
- VTK / ITK/ QT - 未解决的外部符号错误 (LNK2001)
- QT创建者:简单程序未解决的外部符号和外部符号错误
- C++编译错误:ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v
- 标准::字符串::空的未定义符号错误;Mac OS High Sierra 上的 c++ 标准方法链接错误
- ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- 由于使用未签名的INT,因此在Variadic模板C 上未解决的外部符号错误
- OSX MOJAVE -LD:架构X86_64 clang找不到符号:错误:链接器命令失败,出口代码1
- 使用从WINRT网格类派生的抽象类时,Casttobase未解决的外部符号错误
- LD:架构x86_64 clang找不到符号:错误:链接器命令失败,出口代码1(使用-v to See