duplicate symbol _main in

I'm very new to Xcode and am trying to use it to write and build C code. I made a project and got everything to work (it'll run Hello World and all that) but once I add a second file to the project (so that I don't have to create a whole new workspace and project and such for every new file I want to work on) the build fails and I get this error:


Apple Mach-O Linker (Id) Error

Linker command failed with exit code 1 (use -v to see invocation)


I don't know what any of that means. Once I get to the error it says all this:


duplicate symbol _main in:

/Users/JacobSax/Library/Developer/Xcode/DerivedData/C_Programming-ezejclzfpncidecllfwsjhptguwi/Build/Intermediates.noindex/C Programming.build/Debug/C Programming.build/Objects-normal/x86_64/Program 2.o

/Users/JacobSax/Library/Developer/Xcode/DerivedData/C_Programming-ezejclzfpncidecllfwsjhptguwi/Build/Intermediates.noindex/C Programming.build/Debug/C Programming.build/Objects-normal/x86_64/Program 3.o

ld: 1 duplicate symbol for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)


I just want to be able to have multiple files in my project so I don't have to make a new workspace or project whenever I'm writing code. Forgive me for my lack of knowledge. Thanks.

If you look at the two files, I suspect the both have the same "int main(...)" definition (this is what the default "C" file contains when you create a new file in Xcode). The "int main(...)" is the main program procedure that the operating system calls to start up the program. You two files each have a "main" procedure defined, and that is why when you link the object code together, you get duplicate symbols.


Either rename one of the procedures to something else, and call it from the first "main" procedure, or make a new target in you project, remove the second file from the first target, and add it to the second target.


Jonathan

I have the exact problem. I'm a newbie coder and have no idea what you, Johnathan, are talking about. In layman terms, how do i fix this?

duplicate symbol _main in
 
 
Q