首页 文章

XCode C链接器命令失败,退出代码为1(使用-v查看调用)

提问于
浏览
-1

我收到“链接器命令失败,退出代码1”的构建失败错误我已经检查了其他论坛帖子,讨论了混淆链接器的重复函数调用 . 我对C没有很多经验,所以我会很乐意帮助你!

ld:1个用于体系结构x86_64 clang的重复符号:错误:链接器命令失败,退出代码为1(使用-v查看调用)

LINE.H

#include <stdio.h>
#include <string>

using namespace std;

class RuntimeException { // generic run-time exception
private:
    string errorMsg;
public:
    RuntimeException(const string& err) { errorMsg = err; }
    string getMessage() const { return errorMsg; }
};

// All that is needed for the special exceptions is the inherited constructor and method.

class EqualLines: public RuntimeException
{
public:
    EqualLines(const string& err)
    : RuntimeException(err) {}
};

class ParallelLines: public RuntimeException
{
public:
    ParallelLines(const string& err)
    : RuntimeException(err) {}
};


class Line {
public:
    Line(double slope, double y_intercept): a(slope), b(y_intercept) {};
    double intersect(const Line L) const throw(ParallelLines,
    EqualLines);
    double getSlope() const {return a;};
    double getIntercept() const {return b;};


private:
    double a;
    double b;
};

LINE.CPP

#include "line.h"
#include <iostream>

double Line::intersect(const Line L) const throw(ParallelLines,
                                                 EqualLines)
{
    if (this->a == L.a && this->b == L.b)
    {
        throw "EqualLines";
    }
    else if (this->a == L.a)
    {
        throw "ParallelLines";
    }

    return (L.b - this->b) / (this->a - L.a);
}

MAIN.CPP

#include "line.cpp"
#include <iostream>

int main()
{
    Line L(2.0, 4.0);
    Line K(3.0, 5.0);

    try
    {
        if (L.getSlope() == K.getSlope() && L.getIntercept() == K.getIntercept())
            throw EqualLines("The lines are equal: infinite intersection");
        else if (L.getSlope() == K.getSlope())
            throw ParallelLines("The lines are parallel: no intersection");
    }
    catch(EqualLines& zde)
    {

    }
    catch(ParallelLines& zde)
    {

    }

    cout << "Line 1: Y = " << L.getSlope() << "x + " << L.getIntercept();

    cout << "\n";

    cout << "Line 2: Y = " << K.getSlope() << "x + " << K.getIntercept();

    cout << "\n\n";


    L.intersect(K);


    return 0;
}

1 回答

  • 0

    在您的主文件中,您应该包含 .h 文件而不是 .cpp .

相关问题