Cocos2d-x 4.0 Setup on Ubuntu 20.04.1 LTS

Hello,

I am trying to set up cocos22d-x 4.0 on my Ubuntu 20.04.1 LTS OS, the install-deps-linux.sh command gives the following warning “W: --force-yes is deprecated, use one of the options starting with --allow instead.”.

Besides this when I try to run my project with “cocos run -s NewProj -p linux” command, it gives the following logs:
Building mode: debug
running: ‘cmake …’

– PROJECT_NAME:NewProj
– PROJECT_SOURCE_DIR:/home/durlabh/Documents/cocos2d-x-4.0/projects/NewProj
– COCOS2DX_ROOT_PATH:/home/durlabh/Documents/cocos2d-x-4.0/projects/NewProj/cocos2d
– CMAKE_MODULE_PATH:/home/durlabh/Documents/cocos2d-x-4.0/projects/NewProj/cocos2d/cmake/Modules/
– PROJECT_BINARY_DIR:/home/durlabh/Documents/cocos2d-x-4.0/projects/NewProj/linux-build
– ENGINE_BINARY_PATH:/home/durlabh/Documents/cocos2d-x-4.0/projects/NewProj/linux-build/engine
– PYTHON_PATH:/usr/bin/python2
– COCOS_COMMAND_PATH:/home/durlabh/Documents/cocos2d-x-4.0/tools/cocos2d-console/bin/cocos
– HOST_SYSTEM:Linux
– CMAKE_GENERATOR: Unix Makefiles
– COCOS2DX_LUAJIT_ROOT:/home/durlabh/Documents/cocos2d-x-4.0/tools/cocos2d-console/bin/…/plugins/plugin_luacompile/bin
– LUAJIT32_COMMAND:/home/durlabh/Documents/cocos2d-x-4.0/tools/cocos2d-console/plugins/plugin_luacompile/bin/32bit/luajit-linux
– LUAJIT64_COMMAND:/home/durlabh/Documents/cocos2d-x-4.0/tools/cocos2d-console/plugins/plugin_luacompile/bin/64bit/luajit-linux
– Fontconfig include dirs: /usr/include/uuid;/usr/include/freetype2;/usr/include/libpng16
– GTK3 include dirs: /usr/include/gtk-3.0;/usr/include/at-spi2-atk/2.0;/usr/include/at-spi-2.0;/usr/include/dbus-1.0;/usr/lib/x86_64-linux-gnu/dbus-1.0/include;/usr/include/gtk-3.0;/usr/include/gio-unix-2.0;/usr/include/cairo;/usr/include/pango-1.0;/usr/include/fribidi;/usr/include/harfbuzz;/usr/include/atk-1.0;/usr/include/cairo;/usr/include/pixman-1;/usr/include/uuid;/usr/include/freetype2;/usr/include/libpng16;/usr/include/gdk-pixbuf-2.0;/usr/include/libmount;/usr/include/blkid;/usr/include/glib-2.0;/usr/lib/x86_64-linux-gnu/glib-2.0/include
– ZLIB include dirs: /usr/include
– PNG include dirs: /usr/include;/usr/include
– GLEW include dirs: /usr/include
CMake Warning (dev) at /usr/share/cmake-3.16/Modules/FindOpenGL.cmake:275 (message):
Policy CMP0072 is not set: FindOpenGL prefers GLVND by default when
available. Run “cmake --help-policy CMP0072” for policy details. Use the
cmake_policy command to set the policy and suppress this warning.

FindOpenGL found both a legacy GL library:

OPENGL_gl_LIBRARY: /usr/lib/x86_64-linux-gnu/libGL.so

and GLVND libraries for OpenGL and GLX:

OPENGL_opengl_LIBRARY: /usr/lib/x86_64-linux-gnu/libOpenGL.so
OPENGL_glx_LIBRARY: /usr/lib/x86_64-linux-gnu/libGLX.so

OpenGL_GL_PREFERENCE has not been set to “GLVND” or “LEGACY”, so for
compatibility with CMake 3.10 and below the legacy GL library will be used.
Call Stack (most recent call first):
cocos2d/cmake/Modules/CocosBuildHelpers.cmake:294 (find_package)
cocos2d/cmake/Modules/CocosConfigDepend.cmake:16 (cocos_find_package)
cocos2d/cmake/Modules/CocosConfigDepend.cmake:92 (cocos2dx_depend)
cocos2d/cocos/CMakeLists.txt:117 (use_cocos2dx_libs_depend)
This warning is for project developers. Use -Wno-dev to suppress it.

– OpenGL include dirs: /usr/include
– CURL include dirs: /usr/include/x86_64-linux-gnu
– SQLite3 include dirs: /usr/include
– Configuring done
– Generating done
– Build files have been written to: /home/durlabh/Documents/cocos2d-x-4.0/projects/NewProj/linux-build
running: ‘cmake --build . --config Debug’

Copying resources for NewProj …
copying to /home/durlabh/Documents/cocos2d-x-4.0/projects/NewProj/linux-build/bin/NewProj/Resources
[ 0%] Built target SYNC_RESOURCE-NewProj
[ 0%] Built target ext_unzip
[ 3%] Built target ext_recast
[ 4%] Built target ext_tinyxml2
[ 5%] Built target ext_xxhash
[ 5%] Built target ext_xxtea
[ 6%] Built target ext_clipper
[ 7%] Built target ext_edtaa3func
[ 7%] Built target ext_convertUTF
[ 8%] Built target ext_poly2tri
[ 8%] Built target ext_md5
[ 9%] Built target external
[100%] Built target cocos2d
[100%] Linking CXX executable bin/NewProj/NewProj
/usr/bin/ld: …/cocos2d/external/linux-specific/fmod/prebuilt/64-bit/libfmod.so: .dynsym local symbol at index 2 (>= sh_info of 2)
/usr/bin/ld: …/cocos2d/external/linux-specific/fmod/prebuilt/64-bit/libfmod.so: .dynsym local symbol at index 3 (>= sh_info of 2)
/usr/bin/ld: …/cocos2d/external/linux-specific/fmod/prebuilt/64-bit/libfmod.so: .dynsym local symbol at index 4 (>= sh_info of 2)
/usr/bin/ld: cannot find -lXxf86vm
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/NewProj.dir/build.make:152: bin/NewProj/NewProj] Error 1
make[1]: *** [CMakeFiles/Makefile2:597: CMakeFiles/NewProj.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
Error running command, return code: 2.

Can anyone point out what I might be doing wrong!!

Did you look at our Linux install doc, by chance?

I haven’t tested 20 yet but we have proper steps in the docs for 18.

I can test 20 if you still fail after trying what the docs say.

Hello @slackmoehrle,

Thank you for the quick reply. Yes I have followed the steps but it’s giving the same error.

I can test tomorrow

So far, I am seeing a chipmunk issue.

I started a GitHub Pull Request to help clarify instructions so far on 20.04.

1 Like

I did some digging and found the solution for issue “cannot find -lXxf86vm” by installing glfw libraries. Now I am also facing the chipmunk issue can you please suggest how to proceed!!

I am working through this and I’ll continue to update the PR.

Okay thanks

I think this has something to do with gcc version, but I will work on this more today and update the prerequisites doc to reflect any changes

I found this: https://github.com/cocos2d/cocos2d-x/issues/20471

I hadn’t noticed this issue before. Let’s try this and see what happens.

The fast-math features do work on my environment, which is Lubuntu 19.04. However, I did try building Chipmunk 7.0.3, 7.0.2, 7.0.0, and 7.0.1 (so I could compile without the “-ffast-math” flag), but none of them worked properly with cocos2d-x v4. Only the one shipped with cocos2d-x v4 works perfectly for me.

Chipmunk throws a runtime sanity check error saying that the physics body’s velocity is invalid. I dug into it, and found that the velocity somehow gets set to a NaN value, for a dynamic body, soon after it’s instantiated. And yes, my project has nothing more than just a creation of a Node, with a dynamic physics body, which is added to the scene. I confirmed that it’s the dynamic physics body which triggers the runtime error.

I believe it’s an issue with Chipmunk. Here’s the piece of Chipmunk code responsible for setting the velocity (zero right after it’s instantiated) to a NaN value:

Take a look at this chunk from that line:

cpvmult(body->f, body->m_inv)

For a dynamic body, m_inv is initially set to INFINITY, as you can see from here.

Looking back at that chunk, you can see how INFINITY is multiplied to the body->f vector, which results in a vector with both values set to an NaN value, since body->f is initially a zero vector.

This answer says that that’s what you get when INFINITY is multiplied to 0: https://stackoverflow.com/a/32969493/1031018

I hope someone will look into it and help us integrate Chipmunk 7.x with cocos2d-x v4 without runtime errors.

I will ask the engineering team to look into this.

1 Like

I managed to build Chipmunk 7.0.1 for cocos2d-x v4 (release build) without fast-math optimization: libchipmunk.a - Google Drive

I used this official way of building Chipmunk for cocos2d-x, where patching is involved to make it work with cocos2d-x:

You can build it for yourself, or you can use my build. If you do build yourself, just make sure to remove -ffast-math from the compiler flags in CMakeLists.txt file of Chipmunk, so you don’t get such reference errors whilst linking.

I think cocos2d-x team should update the build of Chipmunk that ships with cocos2d-x. fast-math is not just losing support, it’s also not compliant with IEEE standards.

Read more here: performance - What does gcc's ffast-math actually do? - Stack Overflow

1 Like

This is great. Thank you. Until we update the dependencies I will make a note in the documentation to see this post about a fix.

I’ll finish testing the rest of the Linux steps today with this fix.

Hello @nahiyan thank you for the response. I will try the fix and get back to you.

Hello @nahiyan,

The fix works thanks. :smile:

1 Like