2012-06-05 151 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函數的實現。