架构x86_64的未定义符号
Undefined symbols of the architechture x86_64
我正在学习c++,我得到了这个错误
Undefined symbols for architecture x86_64:
"Point::set(int, int)", referenced from:
Point::Point(int, int)in ccHkya9E.o
"Point::add(Point const&)", referenced from:
Point::operator+(Point const&)in ccHkya9E.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
这是我的代码
#include<iostream>
using namespace std;
class Point {
private:
int x, y;
public:
Point() {}
Point(int new_x, int new_y) {set(new_x, new_y);}
Point (const Point & src) {set(src.x, src.y);}
//Operations
Point add (const Point &pt);
Point sub (const Point &pt);
Point operator+(const Point &pt) {return add(pt);}
Point operator-(const Point &pt) {return sub(pt);}
//other member functions
void set(int new_x, int new_y);
int get_x() const {return x;}
int get_y() const {return y;}
};
int main() {
Point point1(20,20);
Point point2(0,5);
Point point3(-10, 25);
Point point4=point1+point2+point3;
cout<<"the point is"<<point4.get_x();
cout<<","<<point4.get_y()<<"."<<endl;
return 0;
}
任何帮助都是感激的!
您只声明了函数:
void set(int new_x, int new_y);
Point add (const Point &pt);
但是您没有为它们提供定义。所以链接器找不到它们的定义并抱怨它,编译器告诉你为这两个函数提供一个定义,你应该。
函数的空(不做任何事情)定义如下:
void set(int new_x, int new_y)
{
}
Point add (const Point &pt)
{
Point temp;
return temp;
}
免责声明:您应该将这些定义替换为您的实际实现,上述定义将使您能够成功编译和链接(而不是按您想要的方式工作)
相关文章:
- vscode g++链路故障:体系结构x86_64的未定义符号
- 体系结构x86_64的未定义符号:std:terminate(),typeinfo,运算符delete[],运算符new
- C++ 中 dlsym 的未定义符号
- 仅在 MacOS 上析构函数的未定义符号
- OSX clang++:用于 cpp 文件中显式实例化模板的体系结构x86_64的未定义符号
- PCL 出错:体系结构x86_64 @pcl的未定义符号
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - 体系结构的未定义符号 x86_64:
- 体系结构x86_64的未定义符号:链接器错误
- C++ std::vector<int> 体系结构的未定义符号 x86_64:
- 生成文件:体系结构x86_64的未定义符号
- libc++abi未定义符号:_ZTVN10__cxxabif120__si-class_type_infoE
- Xcode"体系结构x86_64的未定义符号"
- 体系结构x86_64的未定义符号:找不到原因
- SWIG链接器:未定义符号:_ZN2cv8fastFreeEPv(cv::fastFree(void*))
- 如何修复架构x86_64的未定义符号,Boost Asio 1.58
- 在Qt5上去静态库:架构的未定义符号x86_64:
- 体系结构x86_64的未定义符号:c++/ h 文件和 cpp 文件
- 监视 SDK 下的未定义符号"__Unwind_SjLj_Unregister"
- 使用 Boost/Python 的未定义符号 - 复杂
- 建筑x86_64的未定义符号:"vtkDebugLeaksManager::vtkDebugLeaksManager()",引用自: