How to connect to coco2d static library (1.1 beta 2) using workspaces in Xcode 4.3.1

I have done the following:

  • Created workspace
  • Added by my project
  • Added iOS Cocos2d project (drag and drop to project navigator). This is the brother of my project (not a child).
  • In my project, in the build phase related to libcocos2d.a
  • In the build settings of my project - Install Always look for paths to YES
  • An original tree variable has been created that points to the folder containing the cocos2d iOS xcodeproj file.
  • A variable in the source data tree from step 6 has been added to the user header pools of my project. Set as recursive. 8. The project navigator by clicking on the libcocos2d.a library (it looks red). Set the location "Relative to product assembly." You will install this in the rightmost window in Xcode 4.3.1.
  • Closed workspace and open pbxproj file in TextWrangler. I searched for the path containing libcocos2d.a Delete the path, so the entry reads only "libcocos2d.a". This is due to the fact that after compilation, the library is still located in the same application directory.

Work codes and autocomplete. But this does not compile. About 70 linker errors appear when I try to build, everyone says something like:

Undefined characters for armv7 architecture: "_OBJC_CLASS _ $ _ CCDirector" referenced: objc-class-ref in AppDelegate.o objc-class-ref in ViewController.o "_kEAGLColorFormatRGB565" referenced: - [RIAppDelegate applicationDidFinL in AppDelegate.o "_OBJC_CLASS _ $ _ CCTexture2D" referenced by: objc-class-ref in AppDelegate.o "_OBJC_CLASS _ $ _ EAGLView" referenced: objc-class-ref in AppDelegate.o

If I try to build for the simulator, then instead of armv7 it says that there are no symbols for i386. The cocos2d project itself compiles and builds perfectly. This is my project that has the above errors.

The cocos2d library is present in the build directory of my application after I try to create.

EDITOR: Forgot to mention. I also edited the outline for my project so as not to build in parallel. I also added the cocos2d target and made it the top of the list (so it should be built first).

EDIT: clarify - after making changes to the pbxproj file, as described above, the libcocos2d.a file is no longer red. It looks ok. Also, my application is also built, despite the fact that there are errors in the links, and the assembly fails. (It is not actually created, but the product is not “red.” The application file is created in the same place where the cocos2d library is created.

+8
ios xcode4 static-libraries cocos2d-iphone static-linking
source share
2 answers

I am trying to use Cocos2d as a static library instead of a template. The reason is that it makes it easier to develop my project in a modular way. In addition, the transition between cocos2d versions and so on is simplified. After searching the cocos2d-x forums, I found this link: http://cfc.kizzx2.com/index.php/cocos2d-x-with-xcode-4-from-scratch-without-template/

I figured out the framework that I needed to add, and which solved all the binding problems.

I still haven’t sent the application to the store, so if someone with more experience can look at it to check if there are any errors / errors, that would be great. English is second to me, so please do not mind. This was done using cocos2d1.1beta2 and Xcode 4.3.1

  • Create Xcode Workspace
  • Go to the folder containing the cocos2d xcodeproj file (iOS / Mac). Here you unpacked cocos2d after downloading it.
  • Drag the xcodeproj file into the Xcode navigator window (in most windows).
  • Click on the tiny triangle next to the cocos2d project file so that all its contents disappear.
  • Add a new project to the workspace by right-clicking in the navigator and "New Project". Make sure that the project is added as a brother to the cocos2d project, and not as a child. I selected one application window (iOS)
  • In this new project, go to build settings and change "Always search for user paths" to "Yes"
  • Add the location of your cocos2d folder to the "User Header Search Paths". If you like, you can add the cocos2d folder to your list of source trees in Xcode and instead just enter the variable name here. For example: $ {COCOS2D_SRC}. This is useful if you later want to change the folder structure of the build environment.

  • Click on the target and select the assembly phase tab. You want to link the following files to your library. Make sure they are there. libcocos2d.a libz.dylib libxml2.dylib OpenGLES.framework QuartzCore.framework UIKit.framework Foundation.framework CoreGraphics.framework

If libcocos2d.a is "red" then don't worry about it. It still compiles / links correctly.

  • In the build settings, change "Only build active architectures" to "YES."

Otherwise, you may receive an error message by ignoring the file / Users / Pteriedaktyl / Library / Developer / Xcode / DerivedData / Build / Products / Debug -iphoneos / libcocos2d.a, the file was created for an archive that is not related to architecture (armv6 )

  • In your info.plist file, be sure to delete the entry inside “required device capabilities” that says armv7. Otherwise, your code will only work on newer devices.

Now you are tuned! You must have access to cocos2d api from the sibling project. If you ever want to change your version of cocos2d, you just need to change the cocos2d project, which is in the workspace, update the path to the source tree (if necessary) and the link to the new libCocos2d.a

Testing: To try, I changed the application delegate and looked at the controller code to match the code of one of my old welcome projects.

Please try this and add to the stream if you encounter any problems.

+11
source share

In the "Utilities" area for libCocos2d.a, under the credentials and type where you install the library with respect to "Product Builds", scroll down to make sure that the target membership is selected for your purposes. If this is not the case, it will not include it in the actual assembly made by the target. At least that was the only way to reproduce this problem.

+1
source share

All Articles