Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode, Duplicate symbol _main

Tags:

xcode

Ah..I figure out it's that I have multiple entries under Targets/Compiled Sources ( in newer XCode it's under Build Phases/Compile Sources ). I removed them and the problem is solved. The multiple entry thing probably has to do with Git merge.


It appeared that in my case I was importing a .m file instead of its .h counterpart. Solved by editing

#import "Tools.m"

into

#import "Tools.h"

I also had this problem and it was caused by code I imported from another project. I did a grep for "int main" in my project directory:

grep -nr "int main" .

and found

./main.m:13:int main(int argc, char *argv[])
./IMPORTED_DIR/main.m:13:int main(int argc, char *argv[])

the IMPORTED_DIR contained the extra main.m that was causing the error for me

I removed that file from the Project -> Targets -> Build phases -> Compile sources list and then it compiled


I was facing the same issue with using two third party framework. (AppLovin and Flurry) And I came to know that by removing "all_load" from "Other Linker Flags" in build settings.


I had the same problem opening a project, that was created with Xcode 4.0.2, with Xcode 4.1. I simply solved by clicking on "Modernize Project" (Editor/Modernize Project). This procedure automatically removed all duplicates.