Xcode duplicate symbol _main

感情迁移 提交于 2019-12-10 02:04:25

问题


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


回答1:


I can't tell you why this is happening, but I can suggest a workaround. When I commented out the entire contents of the main.m file that was generated for my Titanium project, I was able to compile successfully and run on the Simulator. Let me know if that works for you.




回答2:


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




回答3:


I just spent a couple hours battling this one. It was because I was using the -all_load linker flag. If you are using that flag to get around the category bug, there are some other solutions -- see here.




回答4:


I had a similar problem. A unit test class was accidentally included in my build. If you search your project for "main(" you'll probably find the duplicate functions.




回答5:


This happened to me for 2 reasons:

1: Class A calls class B and both had imported the same class. Fix it by importing the class in .m file.

2: Two classes have a constant with the same name (even if the constant is defined in the .m file). Fix it by changing the name of the constants.




回答6:


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;
    }
}



回答7:


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".




回答8:


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.




回答9:


Based off what I can tell from these other answers, I'm going to need to be remove a bunch of main methods.

But to do that easily I first need to remove all the gd comments from my files because they are assiduously documented with comments at nearly every other line

This regular expression matches all C multi-line comments including their delimeters & may help you on your journey

/\*((?!\*/).)*\*/



回答10:


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(-_-).




回答11:


Delete /Users/{username}/Library/Developer/Xcode/DerivedData folder and build again.



来源:https://stackoverflow.com/questions/2535265/xcode-duplicate-symbol-main

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!