10

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

kit
  • 1,166
  • 5
  • 16
  • 23
Prithvi Raj
  • 103
  • 1
  • 1
  • 6

11 Answers11

19

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.

warrenm
  • 31,094
  • 6
  • 92
  • 116
  • 3
    As a clarification, the reason why you see the error is that libTitanium, the primary Titanium library file, contains a `main` entry point and this is therefore redundant to the `main` function in main.m. I'm not sure why this problem doesn't crop up elsewhere, but it must be something with the way the compiler is invoked by Titanium, to hook into their entry point instead of the one in main.m. – warrenm Mar 29 '10 at 01:11
  • 2
    In my case, a library I'm using had it's own main.m. Commented out and it worked – Teofilo Israel Vizcaino Rodrig Jan 09 '12 at 12:19
  • While that works, I think this is the correct way to handle this: http://stackoverflow.com/questions/3380972/xcode-duplicate-symbol-main – Jacksonkr Jan 26 '12 at 18:20
  • No disagreement from me on that. I suppose I had less experience with Build Phases last year, which explains how I overlooked the obvious solution. – warrenm Jan 26 '12 at 18:31
11

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

boulder_ruby
  • 38,457
  • 9
  • 79
  • 100
Vishal Jaiswal
  • 111
  • 1
  • 3
8

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.

Community
  • 1
  • 1
William Jockusch
  • 26,513
  • 49
  • 182
  • 323
  • http://stackoverflow.com/questions/932856/calling-method-on-category-included-from-iphone-static-library-causes-nsinvalidar, the link suggest to use -ObjC. – AechoLiu Mar 31 '11 at 03:52
  • 1
    This was the cause in a our project. It was an older project where -all_load was being used and we just linked a new library in. The result was over 200 duplications. Removing -all_load fixed it. – David Wong May 10 '13 at 07:12
6

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.

gstroup
  • 1,064
  • 8
  • 16
1

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.

Emil
  • 7,220
  • 17
  • 76
  • 135
1

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;
    }
}
helsont
  • 4,347
  • 4
  • 23
  • 28
0

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

Doug Squires
  • 81
  • 1
  • 4
0

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

/\*((?!\*/).)*\*/
boulder_ruby
  • 38,457
  • 9
  • 79
  • 100
0

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

Venuu Munnuruu
  • 285
  • 1
  • 6
  • 17
0

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.

Vikdor
  • 23,934
  • 10
  • 61
  • 84
Sri
  • 1
-1

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

eildiz
  • 487
  • 1
  • 7
  • 14