2012-06-05 111 views
1

我正在使用Xcode中的C++程序,并且当我尝试构建并运行应用程序时(加上“生成失败”错误信息)。下面是我使用的代码:尝试在Xcode中编译时发生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 
+0

为什么被标记为C#? –

回答

2

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