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

cocos2d-x compile broken on Ubuntu 17、18 #19246

Open
drelaptop opened this issue Dec 14, 2018 · 13 comments
Open

cocos2d-x compile broken on Ubuntu 17、18 #19246

drelaptop opened this issue Dec 14, 2018 · 13 comments
Assignees
Milestone

Comments

@drelaptop
Copy link
Contributor

  • cocos2d-x version: 3.17, 3.17.1
  • devices test on: ubuntu 17, 18

compile errors like:

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 PIE object; recompile with -fPIC
/usr/bin/ld: ../../../../external/freetype2/prebuilt/linux/64-bit/libfreetype.a(ftinit.linux64.o): relocation R_X86_64_32 against symbol `tt_driver_class' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../../../external/freetype2/prebuilt/linux/64-bit/libfreetype.a(ftsystem.linux64.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../../../external/freetype2/prebuilt/linux/64-bit/libfreetype.a(sfnt.linux64.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../../../external/freetype2/prebuilt/linux/64-bit/libfreetype.a(psaux.linux64.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../../../external/freetype2/prebuilt/linux/64-bit/libfreetype.a(psnames.linux64.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../../../external/freetype2/prebuilt/linux/64-bit/libfreetype.a(pfr.linux64.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../../../external/freetype2/prebuilt/linux/64-bit/libfreetype.a(truetype.linux64.o): relocation R_X86_64_32 against `.text' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../../../external/freetype2/prebuilt/linux/64-bit/libfreetype.a(winfnt.linux64.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../../../external/freetype2/prebuilt/linux/64-bit/libfreetype.a(type1.linux64.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../../../external/freetype2/prebuilt/linux/64-bit/libfreetype.a(type42.linux64.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../../../external/freetype2/prebuilt/linux/64-bit/libfreetype.a(cff.linux64.o): relocation R_X86_64_32 against `.text' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../../../external/freetype2/prebuilt/linux/64-bit/libfreetype.a(type1cid.linux64.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../../../external/freetype2/prebuilt/linux/64-bit/libfreetype.a(bdf.linux64.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../../../external/freetype2/prebuilt/linux/64-bit/libfreetype.a(pcf.linux64.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../../../external/freetype2/prebuilt/linux/64-bit/libfreetype.a(ftf.linux64.o): relocation R_X86_64_32S against `.text' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../../../external/freetype2/prebuilt/linux/64-bit/libfreetype.a(smooth.linux64.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../../../external/freetype2/prebuilt/linux/64-bit/libfreetype.a(raster.linux64.o): relocation R_X86_64_32S against symbol `ft_raster1_renderer_class' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../../../external/freetype2/prebuilt/linux/64-bit/libfreetype.a(autofit.linux64.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../../../external/freetype2/prebuilt/linux/64-bit/libfreetype.a(pshinter.linux64.o): relocation R_X86_64_32S against `.text' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../../../external/freetype2/prebuilt/linux/64-bit/libfreetype.a(ftglyph.linux64.o): relocation R_X86_64_32S against symbol `ft_bitmap_glyph_class' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../../../external/freetype2/prebuilt/linux/64-bit/libfreetype.a(ftstroke.linux64.o): relocation R_X86_64_32S against symbol `ft_outline_glyph_class' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../../../external/freetype2/prebuilt/linux/64-bit/libfreetype.a(ftgzip.linux64.o): relocation R_X86_64_32S against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../../../external/freetype2/prebuilt/linux/64-bit/libfreetype.a(ftlzw.linux64.o): relocation R_X86_64_32S against `.text' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../../../external/freetype2/prebuilt/linux/64-bit/libfreetype.a(ftbitmap.linux64.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
engine/tests/cpp-empty-test/CMakeFiles/cpp-empty-test.dir/build.make:185: recipe for target 'bin/Debug/cpp-empty-test/cpp-empty-test' failed
make[2]: *** [bin/Debug/cpp-empty-test/cpp-empty-test] Error 1
CMakeFiles/Makefile2:1445: recipe for target 'engine/tests/cpp-empty-test/CMakeFiles/cpp-empty-test.dir/all' failed
make[1]: *** [engine/tests/cpp-empty-test/CMakeFiles/cpp-empty-test.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
@drelaptop drelaptop added this to the next milestone Dec 14, 2018
@drelaptop drelaptop changed the title cocos2d-x compile broken on ubuntu 17 or 18 cocos2d-x compile broken on ubuntu 17、18 Dec 14, 2018
@drelaptop drelaptop changed the title cocos2d-x compile broken on ubuntu 17、18 cocos2d-x compile broken on Ubuntu 17、18 Dec 14, 2018
@flykule
Copy link

flykule commented Dec 20, 2018

Hi, you can add " set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -no-pie -fno-exceptions -std=c++11 -Wno-deprecated-declarations -Wno-reorder") " to CMakeList below line 70.It worked for me!

@slackmoehrle
Copy link
Contributor

@flykule Thank you for commenting! I am going to try this out.

@slackmoehrle
Copy link
Contributor

@flykule Thank you so much!

I have to modify a bit to:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -no-pie -fexceptions -std=c++11 -Wno-deprecated-declarations -Wno-reorder")

@playmyskay
Copy link

playmyskay commented Dec 21, 2018

@flykule Thank you so much!

I have to modify a bit to:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -no-pie -fexceptions -std=c++11 -Wno-deprecated-declarations -Wno-reorder")

Compiling with -no-pie option just for one library (freetype2) sounds a little bit strange. In my opinion the prebuilt of libfreetype.a should be compiled with -fPIC option, or i am wrong?

Sorry, i am not a compiler/linker expert.

If you remove the dependency to libfreetype.a (i.e. in link.txt) you are able to successfully link everything with a clean/new project.

I compiled and linked the libfreetype.a by myself and replaced it with the prebuilt. Now it's linking.

@slackmoehrle
Copy link
Contributor

@playmyskay Yeah, true perhaps.

I have tried a few things, so far and nothing works.

elseif(LINUX)
        #target_compile_options(${target} PUBLIC -fPIC)
        #target_compile_options(${target} PUBLIC -no-pie)

@playmyskay
Copy link

playmyskay commented Dec 21, 2018

@slackmoehrle

step1:
Compile the freetype library by yourself from: https://github.com/cocos2d/cocos2d-x-3rd-party-libs-src

./build.sh -p=linux --libs=freetype --arch=x86_64 --mode=release

output file: cocos2d-x-3rd-party-libs-src/build/linux/freetype/prebuilt/x86_64/libfreetype.a

step2:
Create or use an existing project and replace the file libfreetype.a with the output file of step1. Now link again and it works in my case.

file to replace: _YourProject_/cocos2d/external/freetype2/prebuilt/linux/64-bit/libfreetype.a

The file in repo 'https://github.com/cocos2d/cocos2d-x-3rd-party-libs-bin' must be replaced with a correct binary.

@leJTA
Copy link

leJTA commented Jan 7, 2019

@slackmoehrle

step1:
Compile the freetype library by yourself from: https://github.com/cocos2d/cocos2d-x-3rd-party-libs-src

./build.sh -p=linux --libs=freetype --arch=x86_64 --mode=release

output file: cocos2d-x-3rd-party-libs-src/build/linux/freetype/prebuilt/x86_64/libfreetype.a

step2:
Create or use an existing project and replace the file libfreetype.a with the output file of step1. Now link again and it works in my case.

file to replace: _YourProject_/cocos2d/external/freetype2/prebuilt/linux/64-bit/libfreetype.a

The file in repo 'https://github.com/cocos2d/cocos2d-x-3rd-party-libs-bin' must be replaced with a correct binary.

Thank you very much i had the same problem and it solved it

@AbaoFromCUG
Copy link

It solve by rollback gcc version and g++ version ,reference the file cocos2d-x-3.17.1/build/install-deps-linux.sh , in the end:

........
sudo update-alternatives --remove-all gcc
sudo update-alternatives --remove-all g++

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 60
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 60

echo "Cocos uses GCC Version: `gcc --version`"
echo "Cocos uses G++ Version: `g++ --version`"
echo "Cocos uses ld Version: `ld --version`"
echo "Cocos uses /usr/bin/ld Version: `/usr/bin/ld --version`"

the "-fPIC" error occur because gcc\g++ version too new (ubuntu17 or 18) , may be cocos2d-x should update gcc version

@minggo
Copy link
Contributor

minggo commented Feb 25, 2019

i think we can use ubuntu 18 for next the testing version

@stephenwithav
Copy link

That would be fantastic, @minggo! I just started learning Cocos and this was a pain point.

@minggo minggo modified the milestones: 3.17.2, next Apr 30, 2019
@codewithmichael
Copy link

codewithmichael commented Jul 22, 2019

Just to share another [easier] solution for 3.17.1 (Ubuntu 18.04 LTS / LinuxMint 19.1):
I just created a symlink to avoid editing my shared CMake build's link.txt.

$ cd ~/cocos2d-x/external/freetype2/prebuilt/linux/64-bit
$ mv libfreetype.a libfreetype.a.bak
$ ln -s /usr/lib/x86_64-linux-gnu/libfreetype.a

(Edit) Note: The package libfreetype6-dev must be installed.

@theSlyest
Copy link
Contributor

theSlyest commented Oct 30, 2019

I just had a similar issue with libfmod:

/usr/bin/ld: ../../cocos2d/external/linux-specific/fmod/prebuilt/64-bit/libfmod.so: .dynsym local symbol at index 2 (>= sh_info of 2)

How can I solve it?

@jack9603301
Copy link

Can you improve the documentation for cocos2dx installation in Linux? It’s best not to set the operating system dependency. but I can’t see it in the documentation. I use kubuntu 20.04

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

No branches or pull requests