Linker error when building Cocos2d-X project in XCode

Hi,

I am trying to build my project in XCode (this project is an upgrade from Cocos2d-X 2.2.6 to Cocos2d-X 3.10), but I am getting a linker error:

    /proj.ios_mac/build/IgualOuDiferente_Cocos3x.build/Debug-iphonesimulator/MyGame-mobile.build/Objects-normal/i386/AppDelegate-8B40F64EC413FCA2.o
duplicate symbol _main in:
    /proj.ios_mac/build/MyGame.build/Debug-iphonesimulator/MyGame-mobile.build/Objects-normal/i386/MyGame.o
    /proj.ios_mac/build/MyGame.build/Debug-iphonesimulator/MyGame.build/Objects-normal/i386/main.o
ld: 13 duplicate symbols for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I am not sure what can I do to fix this…

Note: I was able to successfully build a new cocos 2d project using cocos new.

“You have two modules declaring the same class. Perhaps one is no longer needed?
You are importing any header file in both the files .m and .h :frowning: Remove from one place.)
You are importing any .m file somewhere. :- (Import .h file instead of .m file)
You have defined and declared any const variable in outside(above)
the @interface{} in any of .h file, it might being duplicated. :- (Do it
in the .m file.)”


https://www.google.de/#q=duplicate+symbol+_main+in+xcode

Hi,

Actually my whole code is written in C++, so I don’t think that I am importing any .m or .cpp files anywhere.

I’ve done some digging in my code I found out that I had 2 AppDelegate.cpp and AppDelegate.h files on the XCode project. Once I deleted them almost all the errors went away except for this one:

duplicate symbol _main in:
    /Users/felipe/Library/Developer/Xcode/DerivedData/IgualOuDiferente_Cocos3x-avmctbgxqubhqqezeuioqyscamrh/Build/Intermediates/IgualOuDiferente_Cocos3x.build/Debug-iphonesimulator/IgualOuDiferente_Cocos3x-mobile.build/Objects-normal/x86_64/main.o
    /Users/felipe/Library/Developer/Xcode/DerivedData/IgualOuDiferente_Cocos3x-avmctbgxqubhqqezeuioqyscamrh/Build/Intermediates/IgualOuDiferente_Cocos3x.build/Debug-iphonesimulator/IgualOuDiferente_Cocos3x-mobile.build/Objects-normal/x86_64/IgualOuDiferente.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I am not sure where is the problem with this one, since I don’t import the main class anywhere in the code except on the stubs that were already created by the cocos new process.

perhaps you have an incorrect header guard?

you definitely have something defined twice.

Hi,

I search my code and I found out that I had a IgualOuDiferente.cpp file which had a main method inside it. I am not quite sure where it came from, but once I commented out the main method, I was able to build it without any problems.

Thanks for the help! :smile: