Linker error with prebuilt libraries when including all cocos2d-x sources


#1

Hi,
I am trying to set up a shared iOS/Android project. I want to share the cocos2d-x library between the iOS and the Android project, thus I included cocos2d-2.0-rc2-x-2.0.1 as a git submodule, but I only added the relevant and iOS specific files to the Xcode project (like when using the Xcode templates). The project builds and runs fine, but only if I remove cocos2dx/platform/third_party on the filesystem. I did not include this directory in Xcode however. If the directory is present I get these linker errors:

ld: warning: ignoring file /Users/max/Code/Xcode/Ironpaws/libs/cocos2d-x/cocos2dx/platform/third_party/android/prebuilt/libxml2/libs/armeabi/libxml2.a, file was built for archive which is not the architecture being linked (i386) Undefined symbols for architecture i386: "_xmlCheckVersion", referenced from: cocos2d::CCSAXParser::parse(char const*, unsigned int) in CCSAXParser.o "_xmlSAXUserParseMemory", referenced from: cocos2d::CCSAXParser::parse(char const*, unsigned int) in CCSAXParser.o "_xmlCleanupParser", referenced from: cocos2d::CCSAXParser::parse(char const*, unsigned int) in CCSAXParser.o "_xmlMemoryDump", referenced from: cocos2d::CCSAXParser::parse(char const*, unsigned int) in CCSAXParser.o "_xmlFreeDoc", referenced from: cocos2d::CCUserDefault::~CCUserDefault() in CCUserDefault.o cocos2d::CCUserDefault::createXMLFile() in CCUserDefault.o "_xmlSaveFile", referenced from: cocos2d::CCUserDefault::flush() in CCUserDefault.o cocos2d::CCUserDefault::createXMLFile() in CCUserDefault.o "_xmlReadFile", referenced from: cocos2d::CCUserDefault::CCUserDefault() in CCUserDefault.o "_xmlNodeGetContent", referenced from: __ZN7cocos2dL14getValueForKeyEPKc in CCUserDefault.o "_xmlNodeSetContent", referenced from: __ZN7cocos2dL14setValueForKeyEPKcS1_ in CCUserDefault.o "_xmlNewNode", referenced from: __ZN7cocos2dL14setValueForKeyEPKcS1_ in CCUserDefault.o cocos2d::CCUserDefault::createXMLFile() in CCUserDefault.o "_xmlNewText", referenced from: __ZN7cocos2dL14setValueForKeyEPKcS1_ in CCUserDefault.o "_xmlAddChild", referenced from: __ZN7cocos2dL14setValueForKeyEPKcS1_ in CCUserDefault.o "_xmlNewDoc", referenced from: cocos2d::CCUserDefault::createXMLFile() in CCUserDefault.o "_xmlDocSetRootElement", referenced from: cocos2d::CCUserDefault::createXMLFile() in CCUserDefault.o "_xmlDocGetRootElement", referenced from: __ZN7cocos2dL16getXMLNodeForKeyEPKcPP8_xmlNode in CCUserDefault.o "_xmlStrcmp", referenced from: __ZN7cocos2dL16getXMLNodeForKeyEPKcPP8_xmlNode in CCUserDefault.o "_xmlFree", referenced from: cocos2d::CCUserDefault::getBoolForKey(char const*, bool) in CCUserDefault.o cocos2d::CCUserDefault::getIntegerForKey(char const*, int) in CCUserDefault.o cocos2d::CCUserDefault::getDoubleForKey(char const*, double) in CCUserDefault.o cocos2d::CCUserDefault::getStringForKey(char const*, std::string const&) in CCUserDefault.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)

My question is: how can I use the full cocos2d-x sources (shared with the Android project) in Xcode without creating a separate project (via the Xcode templates)? Is there a way to tell Xcode to not link certain files?


#2

I was able to fix the problem myself. I noticed that the target had included Android and Windows specific folders under Build Settings -> Library Search Paths. The setting should include only the following entries:

$(inherited) "$(SRCROOT)/libs/cocos2d-x/cocos2dx/platform/third_party/ios/libraries" "$(SRCROOT)/libs/cocos2d-x/js/spidermonkey-ios/lib"

So if you want to set up an iOS project with including the full cocos2d-x source, you should first create a new project with the Xcode template. Then download the latest cocos2d-x release and put it inside the libs folder, replacing the cocos2dx and CocosDenshion folders. In the Xcode project settings remove cocos2d and CocosDenshion, then add them again from the cocos2d-x folder you put into /libs. Then remove all Android, Windows etc. specific files, update the Header Search Paths and remove all non-iOS entries from the Library Search Paths of the target.

I hope somebody will find this helpful, e.g. when setting up a cocos2d-x iOS/Android project in a git repository where cocos2d-x is included as a submodule.