Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build cocos2d-x as a shared library on Linux with BUILD_SHARED_LIBS:BOOL=ON fails with "libfreetype.a(ftbase.linux64.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC" #18399

Open
cirosantilli opened this issue Oct 23, 2017 · 2 comments

Comments

@cirosantilli
Copy link

cirosantilli commented Oct 23, 2017

Why I want to do this:

  • make executables smaller
  • make it more Debian packageable (Debian requires shared libs I think)

Specs:

  • cocos2d-x version: 0398875
    trunk
  • devices test on: Linux Ubuntu 17.04

Steps to Reproduce:

  1. cmake -DBUILD_SHARED_LIBS:BOOL=ON && make
    (Using gcc 6.3 from my distro)

Outcome: link fails with:

/usr/bin/ld: ../../../external/freetype2/prebuilt/linux/64-bit/libfreetype.a(ftbase.linux64.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC

However, freetype is already compiled with -fPIC if you compile it yourself, https://github.com/cocos2d/cocos2d-x-3rd-party-libs-src/blob/d020d9ef98dea233992802d151afdbbbff3acd8e/contrib/src/main.mak#L288 so I think it is about having the prebuilt binary built with an old GCC? So I just compile it myself with:

./build.sh -p=linux --libs=freetype

and copy into the prebuilts and it works.

Next, the link fails with:

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/libcurl.so: undefined reference to symbol 'inflateEnd'                                                   
/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/libz.so: error adding symbols: DSO missing from command line

libz.a gets built together with freetype: linux/z/prebuilt/x86_64/libz.a, which uses libz functions, however for some reason it is not present in the binaries https://github.com/cocos2d/cocos2d-x-3rd-party-libs-bin/tree/8d1bf3e7199948755c98a36a59bf15c50943e27e and make VERBOSE=1 says it is not used during link, only:

-lz

which ends up looking for my system's shared library, which cannot be used for a shared link .

I also don't understand the error because: readelf says that the /usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/libz.so on my system does have inflateEnd.

I then copy pasted the failing linker command, and replaced all -lz entries with the full path to the built libz.a and the link now works, and cpp-tests runs!

However, even after the link works, I sill have the following conerns:

  • the executable 2x larger rather than smaller!
  • the library is called libcocos2dInternal.so, should be just libcocos2d.so. libcocos2d.so does exist but is much smaller, not sure what it is for.
@cirosantilli cirosantilli changed the title Build cocos as a shared library on Linux with BUILD_SHARED_LIBS:BOOL=ON fails with "libfreetype.a(ftbase.linux64.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC" Build cocos2d-x as a shared library on Linux with BUILD_SHARED_LIBS:BOOL=ON fails with "libfreetype.a(ftbase.linux64.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC" Oct 23, 2017
@simpers
Copy link

simpers commented Nov 2, 2017

Any progress on this yet? Right now I'm using v3.13.1 for building on Linux and v3.16 for iOS, due to all previous versions apparently being deprecated due to a system-call which does not exist in iOS 11 anymore.

@cirosantilli
Copy link
Author

@simpers nope. Cocos really needs some packaging love :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants