C++:error: ld returned 1 exit status

CodeBlocks编译C++项目出错

error: ld returned 1 exit status。

Fun.h

#include
using namespace std;
#include

class Point{
private:
    int x,y;
public:
    void set_xy(int a,int b);
    int getx();
    int gety();
};

float line_long(Point m,Point n);

Fun.cpp

#include "Fun.h"
void Point::set_xy(int a,int b)
{
    x=a;y=b;
}
int Point::getx()
{
    return x;
}
int Point::gety()
{
    return y;
}
float line_long(Point m,Point n)
{
    return sqrt((pow((m.getx()-n.getx()),2)) + pow((m.gety()-n.gety()),2));
}

main.cpp

#include "Fun.h"
int main()
{
    Point p1,p2;
    p1.set_xy(0,0);
    p2.set_xy(1,1);
    cout<<line_long(p1,p2);
}

解决错误

在同一个项目中先后建立了以上三个文件,语法无错误,编译出现如题错误提示,接下来,我们要设置链接及编译。
右击项目目录中的文件选择属性,做如下所示设置
C++:error: ld returned 1 exit status_第1张图片
C++:error: ld returned 1 exit status_第2张图片
C++:error: ld returned 1 exit status_第3张图片

重新编译

正常运行
C++:error: ld returned 1 exit status_第4张图片

你可能感兴趣的:(C++)