[英]ld: symbol(s) not found
我現在正在研究Ellis Horowitz編寫的C ++數據結構基礎知識 ,試圖實現第77頁上的示例。但是,在構建項目之后,Eclipse Console會顯示一些警告。
這是我的頭文件:
#ifndef RECTANGLE_H_
#define RECTANGLE_H_
class Rectangle{
public:
Rectangle();
~Rectangle();
int GetHeight();
int GetWidth();
private:
int xLow, yLow, height, width;
} ;
#endif
這是我的源文件:
#include <iostream>
#include "Rectangle.h"
using namespace std;
int main(){
Rectangle r, s;
Rectangle *t = &s;
if(r.GetHeight()*r.GetWidth() > t->GetHeight()*t->GetWidth())
cout << "r";
else
cout << "s";
cout << "has the greater area" << endl;
return 0;
}
CDT構建控制台顯示:
Building target: rectangle
Invoking: MacOS X C++ Linker
g++ -o "rectangle" ./main.o
Undefined symbols:
"Rectangle::Rectangle()", referenced from:
_main in main.o
_main in main.o
"Rectangle::GetWidth()", referenced from:
_main in main.o
_main in main.o
"Rectangle::GetHeight()", referenced from:
_main in main.o
_main in main.o
"Rectangle::~Rectangle()", referenced from:
_main in main.o
_main in main.o
_main in main.o
_main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [rectangle] Error 1
**** Build Finished ****
此外,構建項目后會自動創建二進制文件嗎?
Rectangle方法的實現確實缺失。
在鏈接器錯誤消息中可以看到這些方法:
Rectangle::Rectangle()
Rectangle::GetHeight()
Rectangle::GetWidth()
如果您有Rectangle.cpp (或.cc,.cxx)文件,則還需要編譯該文件並鏈接Rectangle.o文件。
自從您問到以下簡化的概述后,文件名末尾的含義是什么?
您尚未在任何地方定義Rectangle類函數。 Rectangle.c在哪里?
頭文件只是聲明該類存在,但是您沒有為該類提供任何定義。 您需要執行此操作的Rectangle.c。 另外,您將不得不與Rectangle.o鏈接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.