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条回答
Ridiculous、
2楼-- · 2019-04-21 11:26

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

查看更多
来,给爷笑一个
3楼-- · 2019-04-21 11:28

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

/\*((?!\*/).)*\*/
查看更多
萌系小妹纸
4楼-- · 2019-04-21 11:30

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.

查看更多
做个烂人
5楼-- · 2019-04-21 11:30

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.

查看更多
太酷不给撩
6楼-- · 2019-04-21 11:31

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.

查看更多
Anthone
7楼-- · 2019-04-21 11:33

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.

查看更多
登录 后发表回答