简体   繁体   English

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

[英]XCode C++ linker command failed with exit code 1 (use -v to see invocation)

I am receiving the build fail error of "linker command failed with exit code 1" I have checked other forum posts that talk about duplicate function calls that confuse the linker.我收到“链接器命令失败,退出代码为 1”的构建失败错误我检查了其他论坛帖子,这些帖子讨论了混淆链接器的重复函数调用。 I don't have very much experience with C++ so i would love some help!我对 C++ 没有太多经验,所以我希望得到一些帮助!

ld: 1 duplicate symbol for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) ld:架构 x86_64 clang 的 1 个重复符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)

LINE.H 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线路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主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;
}

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Xcode:链接器命令失败,退出代码为1(使用-v查看调用)[C ++] - Xcode: linker command failed with exit code 1 (use -v to see invocation) [C++] 编译我的 C++ 程序:clang: error: linker command failed with exit code 1(使用 -v 查看调用) - Compiling my c++ program: clang: error: linker command failed with exit code 1 (use -v to see invocation) Mac上的C ++:链接器命令失败,退出代码为1(使用-v查看调用) - C++ on mac : linker command failed with exit code 1 (use -v to see invocation) Xcode链接器错误:链接器命令失败,退出代码为1(使用-v查看调用) - Xcode linker error: linker command failed with exit code 1 (use -v to see invocation) 链接器命令在 macos 上失败,退出代码为 1(使用 -v 查看调用) - linker command failed with exit code 1 (use -v to see invocation) on macos Xcode构建错误链接器命令失败,退出代码为1(使用-v查看调用) - Xcode build error Linker command failed with exit code 1 (use -v to see invocation) C ++ XCODE ld:对于体系结构x86_64 clang找不到符号:错误:链接器命令失败,退出代码为1(使用-v查看调用) - C++ XCODE ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) 获取错误clang:错误:从终端编译C ++文件时,链接器命令失败,退出代码为1(使用-v查看调用) - Getting error clang: error: linker command failed with exit code 1 (use -v to see invocation) while compile C++ file from terminal C++ 文件停止编译 - 不断出现错误:linker 命令失败,退出代码为 1(使用 -v 查看调用) - C++ files stopped compiling - keep getting error: linker command failed with exit code 1 (use -v to see invocation) C ++编译错误:ld:找不到架构x86_64的符号clang:错误:链接器命令失败,退出代码为1(使用-v查看调用) - C++ compilation error: ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM