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

时间:2015-04-07 19:47:54

标签: xcode

我尝试编译程序时遇到问题。不要以为它是代码。创建一个项目,以便Xcode为我提供主要代码,我没有使用,而是创建一个名为Triangulo.cpp的新文件,我只想编译此文件以查看它是否有效。

这是尝试编译后出现的文本。

Ld /Users/oscarespinosa/Library/Developer/Xcode/DerivedData/Poligonos_2D-folpbuxmhfipkuadwfzchugbzton/Build/Products/Debug/Poligonos\ 2D normal x86_64
cd "/Users/oscarespinosa/Documents/Ingenieria Aeronautica/2do Semestre/Programacion Orientada a Objetos/Poligonos 2D"
export MACOSX_DEPLOYMENT_TARGET=10.10
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -L/Users/oscarespinosa/Library/Developer/Xcode/DerivedData/Poligonos_2D-folpbuxmhfipkuadwfzchugbzton/Build/Products/Debug -F/Users/oscarespinosa/Library/Developer/Xcode/DerivedData/Poligonos_2D-folpbuxmhfipkuadwfzchugbzton/Build/Products/Debug -filelist /Users/oscarespinosa/Library/Developer/Xcode/DerivedData/Poligonos_2D-folpbuxmhfipkuadwfzchugbzton/Build/Intermediates/Poligonos\ 2D.build/Debug/Poligonos\ 2D.build/Objects-normal/x86_64/Poligonos\ 2D.LinkFileList -mmacosx-version-min=10.10 -stdlib=libc++ -Xlinker -dependency_info -Xlinker /Users/oscarespinosa/Library/Developer/Xcode/DerivedData/Poligonos_2D-folpbuxmhfipkuadwfzchugbzton/Build/Intermediates/Poligonos\ 2D.build/Debug/Poligonos\ 2D.build/Objects-normal/x86_64/Poligonos\ 2D_dependency_info.dat -o /Users/oscarespinosa/Library/Developer/Xcode/DerivedData/Poligonos_2D-folpbuxmhfipkuadwfzchugbzton/Build/Products/Debug/Poligonos\ 2D

duplicate symbol _main in:
/Users/oscarespinosa/Library/Developer/Xcode/DerivedData/Poligonos_2D-folpbuxmhfipkuadwfzchugbzton/Build/Intermediates/Poligonos 2D.build/Debug/Poligonos 2D.build/Objects-normal/x86_64/main.o
/Users/oscarespinosa/Library/Developer/Xcode/DerivedData/Poligonos_2D-folpbuxmhfipkuadwfzchugbzton/Build/Intermediates/Poligonos 2D.build/Debug/Poligonos 2D.build/Objects-normal/x86_64/Triangulo.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

以下是代码:

//
//  Triangulo.cpp
//  Poligonos 2D
//
//  Created by Oscar Espinosa on 4/6/15.
//  Copyright (c) 2015 IPN ESIME Ticoman. All rights reserved.
//

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
int b, h;
float c, a, area, perimetro;

cout << " Calculo de area y perimetro de un triangulo rectangulo" << endl
     << "\n Ingrese el valor de la base: ";
cin >>  b;
cout << "\n Ingrese el valor de la altura: ";
cin >> h;

area = (b*h)/2.00;

c = sqrt(b*b + h*h);
a = c;
perimetro = a+b+c;

cout << "\n El area es: " << area << endl
     << " El perimetro es: " << perimetro;

return 0;
}

1 个答案:

答案 0 :(得分:1)

您的项目意外地有一个名为“main.c”(或.m或.cpp)的源文件,该文件也有一个名为“main”的函数。从项目中删除该额外文件。它可能是您从模板创建项目时出现的入门代码。