Xcode duplicate symbol _main

31,347

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

Solution 2

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

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

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

Solution 5

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;
    }
}
Share:
31,347
Admin
Author by

Admin

Updated on July 09, 2022

Comments

  • Admin
    Admin almost 2 years

    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

  • warrenm
    warrenm about 14 years
    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.
  • AechoLiu
    AechoLiu about 13 years
    stackoverflow.com/questions/932856/…, the link suggest to use -ObjC.
  • Teofilo Israel Vizcaino Rodrig
    Teofilo Israel Vizcaino Rodrig over 12 years
    In my case, a library I'm using had it's own main.m. Commented out and it worked
  • Jacksonkr
    Jacksonkr about 12 years
    While that works, I think this is the correct way to handle this: stackoverflow.com/questions/3380972/xcode-duplicate-symbol-m‌​ain
  • warrenm
    warrenm about 12 years
    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.
  • David Wong
    David Wong almost 11 years
    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.