CMake Linux build with shared libraries : prebuilt not PIC?

Hello,

  1. First disclaimer : I m not using latest version ( I saw there were some CMakeLists.txt changes recently ).
    I merged a commit a bit after 3.2 release into my version ( already with quite a few modifications ).
    So I m talking about this version to be more precise :
    https://github.com/asmodehn/cocos2d-x/commit/4582d4ca8fcbee1158f1241feadfc979ac3e1cd0

The last commit that I merged from cocos2d-x repo is 57859beb68866ba82c90a3ecde4c5d19976b81fa

  1. The Problem : While building our game ( quite big : more than 20k lines of c++ without counting cocos and other libraries ) with cmake, on win32, There was a problem where the linking was taking a really long time using VS2013 (more than 10 minutes on non incremental mode. incremental mode was running for ever).
    This doesnt happen with gcc on Linux, so I think it must be a bug in the linker… Anyway I no clue about how to solve it ( and I certainly dont want to spend time debugging the linker ) so I went to look for a solution in another direction…

I realized that the cmake script builds everything as static libraries. However the VS solution uses .dll libraries for cocos, cocostudio and cocosui.
So I decided to make the cmake build them as shared libraries as well.
It works now fine on windows and my linking is back under 10 seconds.
However on Linux I get :

linking …/…/…/lib/libcocos2d.so (c++)
/usr/bin/ld: /home/alexv/Projects/WkCocos/depends/cocos2d-x/external/websockets/prebuilt/linux/64-bit/libwebsockets.a(libwebsockets.c.o): relocation R_X86_64_32 against `.rodata.str1.1’ can not be used when making a shared object; recompile with -fPIC
/home/alexv/Projects/WkCocos/depends/cocos2d-x/external/websockets/prebuilt/linux/64-bit/libwebsockets.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status

This happens because I am linking a dll from static libraries on a unix machine.
For this to work the static libraries need to be compiled with the Position Independent Code flag.
I did it in the cocos CMakeLists.txt with a simple global flag :

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

However we still need to do it for all the dependencies that are downloaded as binaries with the download-deps.py script in external/ folder. I downloaded https://github.com/cocos2d/cocos2d-x-3rd-party-libs-bin/archive/v3-deps-7.zip so I assume this change hasnt been done yet.

=> Is there a plan for this to happen ? Any ETA ?
=> Should I do it myself ? where ? ( I cant really test all the libraries… )

Thanks for any hint on what the next step is to solve this issue.

OK I had a look at that :
https://github.com/cocos2d/cocos2d-x-3rd-party-libs-bin

But it seems unrelated to this :

Where can I find the source of all the libraries cocos uses, so that I can rebuild them with PIC enabled when needed ?

Thanks.

We are committing other 3rd party library source code. It is not finished.

Understood.
Let me know if / how I can help.

As far as I know, the Linux version cannot build a shared cocos2dx library right now.
And windows is already using it that way in VS solution.
If the build stays inconsistent on different platforms for too long, it will become harder to fix / maintain.

Cheers.

Shared library is required by cocos studio.
On other platforms, we don’t need shared library, and it is more easier to use static library.

What we are doing is

It is not easy to do it to support all platforms. And we will try to finish it in v3.3.

Small update on that topic : https://github.com/cocos2d/cocos2d-x-3rd-party-libs-src/pull/10

Thanks @Asmodehn.