gpt4 book ai didi

c++ - 尝试在 Xcode 中编译时出现 Mach-O 错误

转载 作者:行者123 更新时间:2023-11-30 04:27:27 28 4
gpt4 key购买 nike

我正在 Xcode 中开发 C++ 程序,当我尝试构建和运行应用程序时,我不断收到 Mach-O 错误(加上“构建失败”错误消息)。下面是我正在使用的代码:

//
// QuadSolver.cpp
// Calculator
//
//
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
//enter the three variables
double a;
double b;
double c;
cout << "Enter A";
cin >> a;

cout << "Enter B";
cin >> b;

cout << "Enter C";
cin >> c;

//calculating a discriminant
double d;
d = b * b - 4 * a * c;
double x1, x2;

if (d == 0)
{
x1 = x2 = -b / (2 * a);
cout << "There's only one solution: ";
cout << x1;
system("PAUSE");
return 0;
}

else if (d < 0)
{
cout << "There are no possible solutions, as the discriminant is smaller than zero";
system("PAUSE");
return 0;
}
else if (d > 0)
{
x1 = (-b - sqrt(d)) / (2 * a);
x2 = (-b + sqrt(d)) / (2 * a);
cout << "There are two solutions:";
cout << "x1=";
cout << x1;
cout << "x2=";
cout << x2;
}
}

错误信息是这样的:

ld: duplicate symbol _main in /Users/myusername/Library/Developer/Xcode/DerivedData/Calculator-cwpaasypxtqkpvfsbfjekrgrgvbq/Build/Intermediates/Calculator.build/Debug/Calculator.build/Objects-normal/x86_64/QuadSolver.o and /Users/myusername/Library/Developer/Xcode/DerivedData/Calculator-cwpaasypxtqkpvfsbfjekrgrgvbq/Build/Intermediates/Calculator.build/Debug/Calculator.build/Objects-normal/x86_64/main.o for architecture x86_64

最佳答案

您的main 函数在两个地方定义。在上面的小程序和名为 main 的源文件中,它可能作为模板的一部分出现。我不确定您使用的是哪个模板,但在您的项目中查找名为 main 的文件并将其删除或注释掉其对 main 函数的实现。

关于c++ - 尝试在 Xcode 中编译时出现 Mach-O 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10900742/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com