1

I have a problem when I try to compile my program. Do not think it's the code. Create a project so Xcode gives me the main code, it I'm not using, instead create a new file called Triangulo.cpp, I just want to compile this file to see if it works.

This is the text that appears after trying to compile.

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)

Here is the code:

//
//  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;
}
3
  • I can't really tell what it is without code but it looks like you may be trying to use #include improperly. Make sure you're not including the same class multiple times on the same document. Commented Apr 7, 2015 at 20:48
  • Just test it in D ++ on Windows and it works, but in Xcode not. :/ Commented Apr 7, 2015 at 21:19
  • You have duplicate _main symbols. By default, xcode makes a main.c in your project. Commented Apr 7, 2015 at 21:25

1 Answer 1

1

Your project accidentally has a source file which is called "main.c" (or .m or .cpp) which also has a function called "main". Remove that extra file from the project. It's probably starter code that came when you created the project from a template.

Sign up to request clarification or add additional context in comments.

2 Comments

No problem, I've got lots of points anyway. Glad I could help.
@OscarEspinosa Just accept the answer if it solves your problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.