Xcode duplicate symbol _main

2019-04-21 11:13发布

I'm getting the following error in Xcode 3.2.1 on Snow Leopard 10.6.2 whenever I try to compile any iPhone application generated by Appcelerator Titanium. However, the build error only appears when I select iPhone simulator on the architecture menu and if I select the iPhone device, I am able to run the app on my device .

Further more, the iPhone simulator launches successfully and executes the program directly from the Titanium environment which uses Xcode to build .

Why is this happening ?

ld: duplicate symbol _main in Resources/libTitanium.a(main.o) and /Users/prithviraj/Documents/project/Final/build/iphone/build/Final.build/Debug-iphonesimulator/Final.build/Objects-normal/i386/main.o collect2: ld returned 1 exit status Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1

11条回答
SAY GOODBYE
2楼-- · 2019-04-21 11:34

Check to see if you have multiple declarations of main function in your project.

查看更多
淡お忘
3楼-- · 2019-04-21 11:38

I found this happened when i had an implementation file with a main function in it (say abc.m) and also had another main.m. Once I commented out the main function in abc.m, the project compiled successfully.

查看更多
Viruses.
4楼-- · 2019-04-21 11:40

Seems as though there are multiple ways to get into this state. Mine was different. I read a hint where you could drag from a .xib event selector into the .h implementation of your view controller and it would auto-gen your methods. It did - which was cool. I immediately started getting duplicate symbol errors - which was not cool.

I did not have time to dig deep into the linker to see what happened. I created a new view controller, copied the context of my old .xib into the new guy. Deleted the old .h, .m and .xib and built and it worked again. Very odd, very annoying time waste.

There is obviously some bug with this xcode "convenience".

查看更多
爱情/是我丢掉的垃圾
5楼-- · 2019-04-21 11:42

I spent more than an hour in searching for a correct answer but nothing worked for me. Finally the xcode it self telling something is duplicated, so go to that particular folder(in this case: /Users/prithviraj/Documents/project/Final/build/iphone/build/Final.build/Debug-iphonesimulator/Final.build/Objects-normal/i386/main.o) and delete all the files and also check same in your project whether that particular class/interface is declared twice if yes delete it.

After deletion clean and run the project.

It worked for me hope this helps(-_-).

查看更多
淡お忘
6楼-- · 2019-04-21 11:46

I had this problem because I define a file as such:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
... 
} 

And also had a file main.m:

int main(int argc, char* argv[])
{
    @autoreleasepool {
        int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate");
        return retVal;
    }
}
查看更多
登录 后发表回答