1

I have been creating an entire plethora of c++ syntax to help beginners. I use Xcode as my primary IDE. I tried running a program in "function" target but it keeps showing this error.

duplicate symbol _main in: 
    /Users/xivya/Library/Developer/Xcode/DerivedData/parentcpp-afpbdfpaaxeerfdalgncgzpkuaqt/Build/Intermediates.noindex/parentcpp.build/Debug/function.build/Objects-normal/x86_64/manipulator.o
    /Users/xivya/Library/Developer/Xcode/DerivedData/parentcpp-afpbdfpaaxeerfdalgncgzpkuaqt/Build/Intermediates.noindex/parentcpp.build/Debug/function.build/Objects-normal/x86_64/pattern_program.o 
ld: 1 duplicate symbol for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Error code

I have selected "function" target from top-left, see image -

Image contains Target members and entire structure

But at mid-right of the screen "array" target is selected under "Target membership". It selects itself automatically. Whenever I change my target to anything else no error happens. Any and all help will be highly appreciated!

  • 2
    What are the targets associated with `manipulator.cpp` and `pattern_program.cpp`? It looks like your target compiles certain files and end up with more than one `main()`, which will obviously break at link time. – JBL Jun 17 '19 at 13:03
  • On second thought I think you need to wait till you find someone with more xcode experience. I can't help you with that. The behavior you describe about targets appears different from every other IDE I have ever used. – drescherjm Jun 17 '19 at 13:32
  • This tells me a target is not what I expected and xcode has projects: https://stackoverflow.com/questions/20637435/xcode-what-is-a-target-and-scheme-in-plain-language – drescherjm Jun 17 '19 at 13:36

1 Answers1

1

I will divide the answer into two categories.

> Hunting down the issues

Whenever you've multiple targets lurking into your project structure, it may invoke the same error if you ignore just one thing. Suppose, you ran a target and wish to run some different target now. It's obvious that you will change the active scheme from the top-left. More obvious that you will choose the corresponding Build Phases BUT one might miss a minute option to change the target from "select a project or target" option lurking at that instance. If you didn't get me please, read it again or see these pictures.

There is nothing wrong here. pointers target has been selected and reference.cpp execute without any issue.

Now, what if we chose to run a different target? We will do all the customary things required.

We chose function target and in Build Phases we chose the required file. What we miss to observe is that pointers target is still been selected and Xcode hasn't changed it.

That creates a problem which leads to errors like this:

A possible error that can be displayed if one misses changing the target at a different instance, where Xcode should already have changed the target but has not.

Please keep those small things in mind.

> Meaning of error

Most of the times one might encounter "duplicate...etc.." type error. This may roughly mean that Xcode is not sure as to which target to run, as you might have forgotten to change the target at a different instance, probably in Build Phases pannel.

Community
  • 1
  • 1