Using a single cocos2d-x library for multiple Projects

Hello,

Currently when we create a new project using cocos new myGame -l cpp

we get myGame folder with a cocos2d folder. we get another cocos2d folder each time we create a new project.

What i want is that all my projects use on cocos2d folder. is there a short way of doing this?

Thanks

I don’t think so there is any short way of doing this.

what would you suggest?

Its fairly straight forward if you create one project then copy the coocs2d folder back up one directory. Now if you put all your projects down one folder from here and change the paths in android and ios projects back up one directory it will all link against the one cocos2d folder here is an example structure

  1. Cocos2d
  2. Projects
    3.Project 1.
    4.Project 2.

So inside each project just change the search paths and add an extra "…/’ to each path

that was my first thought … i went in search paths and add …/

but there are too many linking errors now… is there anything I’m missing?

Well on ios you will have to delete and re-add the cocos2d libs xcode project as it will be in red.
On Android just look through all files in the project and change the paths that you need to change
build-cfg.json
settings.gradle
app/jni/Android.mk

I’ve already managed to do this. Keep using the standard console command for creating a new project.

After you create the project structure with the cocos command, delete the cocos2d folder in your project folder, then run the following command inside that project folder where cocos2d was previously (this is on Windows, but you should be able to apply this method to other platforms):

Command to create links: mklink /D Link Target

For example:
mklink /D cocos2d c:\cocos\cocos2d-3.14.1

It will create a soft link to the cocos folder you want to use.

I hope that helps!

@ChrisS91 i have it working now… you also have to re-add the libcocos2d ios.a in link binary with libraries

The answer is to use symlinks or change your search paths and point to the cocos2d-x instance you share.

3 Likes