I can't compile cocos2d-x project on Linux. I think the problem related to linking

I can't compile cocos2d-x project on Linux. I think the problem related to linking
0

Hi. I’ve installed Cocos2d-x on KDE Neon Linux distro. I created a new cocos2d-x project like this:
cocos new MyGameCpp -p com.mygamecpp -l cpp -d .

Then I’ve tried to compile the project but it was really hard because I had to install many dependent packages as manual (like GLEW, Sqlite3 etc.).
But I couldn’t compile the project for Linux. I get this error message:

Scanning dependencies of target MyGameCpp
[100%] Building CXX object CMakeFiles/MyGameCpp.dir/Classes/HelloWorldScene.cpp.o                                                               
[100%] Building CXX object CMakeFiles/MyGameCpp.dir/Classes/AppDelegate.cpp.o                                                                   
[100%] Building CXX object CMakeFiles/MyGameCpp.dir/proj.linux/main.cpp.o                                                                       
[100%] Linking CXX executable bin/MyGameCpp/MyGameCpp
/usr/bin/ld: ../cocos2d/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: ../cocos2d/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: ../cocos2d/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: ../cocos2d/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: ../cocos2d/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: ../cocos2d/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: ../cocos2d/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: ../cocos2d/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: ../cocos2d/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: ../cocos2d/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: ../cocos2d/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: ../cocos2d/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: ../cocos2d/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: ../cocos2d/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: ../cocos2d/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: ../cocos2d/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: ../cocos2d/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: ../cocos2d/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: ../cocos2d/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: ../cocos2d/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: ../cocos2d/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: ../cocos2d/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: ../cocos2d/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: ../cocos2d/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: ../cocos2d/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: son bağlama başarısız: Çıktıda gösterilemeyen bölüm
collect2: error: ld returned 1 exit status
CMakeFiles/MyGameCpp.dir/build.make:152: recipe for target 'bin/MyGameCpp/MyGameCpp' failed
make[2]: *** [bin/MyGameCpp/MyGameCpp] Error 1
CMakeFiles/Makefile2:88: recipe for target 'CMakeFiles/MyGameCpp.dir/all' failed
make[1]: *** [CMakeFiles/MyGameCpp.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
Error running command, return code: 2.

What is the problem? Thanks.

What distro. What gcc.

And did you add this? Can't make Cocos2d-x compile on Ubuntu 18.04

1 Like

Thanks. Your comment is correct comment. I want to ask a question if it is not a problem for you: Why did this CMAKE command not be in CMakeLists.txt as default if we need it? I think the all users will get same error if they do not add it?

It was supposed to get merged a while back. I’ll make sure it gets done. Also we don’t see only a small percentage of Linux users. I prefer it myself :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.