IOS duplicate symbol _main in: Problem solving

Source: Internet
Author: User

Today hand to dig a hole for oneself, because some files in the project is in the background of the small partners write C/s + + files, so I import all at once, but the compilation appeared duplicate symbol _main IN:A.O and b.o compile errors.

Here's a simple demo to restore this scenario.

Create a new project, and then create a new Hello.h and hello.c file with the following code:

Hello.h

#ifndef __main__hello__#define __main__hello__#include <stdio.h>int Main (), #endif/* defined (__main__hello__) * /

hello.c

#include "Hello.h" int main () {    return 0;}

Then use the main function in VIEWCONTROLLER.M:

#import "ViewController.h" #import "Hello.h" @interface Viewcontroller () @end @implementation Viewcontroller            -( void) Viewdidload {    [super viewdidload];        Main ();} -(void) didreceivememorywarning {    [super didreceivememorywarning];    Dispose of any resources the can be recreated.} @end

compile-time specific error messages are as follows:

Duplicate symbol _main in:    /users/apple/library/developer/xcode/deriveddata/main-alxynewqhvyqdafbjcjfzntmqfml /BUILD/INTERMEDIATES/MAIN.BUILD/DEBUG-IPHONESIMULATOR/MAIN.BUILD/OBJECTS-NORMAL/I386/HELLO.O    /Users/apple/ library/developer/xcode/deriveddata/main-alxynewqhvyqdafbjcjfzntmqfml/build/intermediates/main.build/ Debug-iphonesimulator/main.build/objects-normal/i386/main.old:1 duplicate symbol for architecture I386clang:error: Linker command failed with exit code 1 (use-v to see invocation)

the reason for the error is obvious (because my demo is too simple):

The hello.c file has a main function that has a symbol _main when it is translated into a hello.o file.

In the original main.m file of the project there is also a main function, in the translation into the MAIN.O file also has a symbol _main.

There is only one main in a project, so there is a conflict.


Workaround: Do not invoke the main function in a C + + file, or rewrite the function name, but it is not possible to change the function's return type or parameter list.


Later encountered duplicate symbol and other problems, can be from this point of view, the problem is often in the project we have some of the same name of the method or function, resulting in the compilation of conflicts. The compile-time error message, A.O and B.O, identifies the two files in which the two duplicate symbols appear, and then opens the two file search conflict method name in the project to compare the changes.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.