Building on Ubuntu 16.04 issues

The first issue (SOLVED):

/opt/cocos2d-x/cocos/2d/CCActionCamera.cpp:197:22: error: ‘isnan’ was not declared in this scope
     if( isnan(_angleX) )
                      ^
/opt/cocos2d-x/cocos/2d/CCActionCamera.cpp:197:22: note: suggested alternative:
In file included from /usr/include/c++/5.3.0/random:38:0,
                 from /opt/cocos2d-x/cocos/base/ccRandom.h:29,
                 from /opt/cocos2d-x/cocos/base/ccMacros.h:73,
                 from /opt/cocos2d-x/cocos/math/CCGeometry.h:32,
                 from /opt/cocos2d-x/cocos/2d/CCAction.h:32,
                 from /opt/cocos2d-x/cocos/2d/CCActionInterval.h:33,
                 from /opt/cocos2d-x/cocos/2d/CCActionCamera.h:31,
                 from /opt/cocos2d-x/cocos/2d/CCActionCamera.cpp:28:
/usr/include/c++/5.3.0/cmath:641:5: note:   ‘std::isnan’
     isnan(_Tp __x)
cocos/CMakeFiles/cocos2d.dir/build.make:86: recipe for target 'cocos/CMakeFiles/cocos2d.dir/2d/CCActionCamera.cpp.o' failed
make[2]: *** [cocos/CMakeFiles/cocos2d.dir/2d/CCActionCamera.cpp.o] Error 1
CMakeFiles/Makefile2:419: recipe for target 'cocos/CMakeFiles/cocos2d.dir/all' failed
make[1]: *** [cocos/CMakeFiles/cocos2d.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

This is resolved by simply running:

sed -i 's/isnan/std::isnan/g' `grep "isnan" -rl`

The second issue (UNRESOLVED):

[ 17%] Building C object cocos/scripting/lua-bindings/CMakeFiles/luacocos2d.dir/__/__/__/external/lua/lua/ltable.c.o
In file included from /home/eht/tools/cocos2d-x-3.10/external/lua/lua/lua.h:16:0,
                 from /home/eht/tools/cocos2d-x-3.10/external/lua/lua/ltable.c:27:
/home/eht/tools/cocos2d-x-3.10/external/lua/lua/luaconf.h:543:20: warning: ISO C99 requires whitespace after the macro name
 #define luai_numstd::isnan(a) (!luai_numeq((a), (a)))
                    ^
/home/eht/tools/cocos2d-x-3.10/external/lua/lua/ltable.c: In function ‘luaH_set’:
/home/eht/tools/cocos2d-x-3.10/external/lua/lua/luaconf.h:543:20: error: expected expression before ‘:’ token
 #define luai_numstd::isnan(a) (!luai_numeq((a), (a)))
                    ^
/home/eht/tools/cocos2d-x-3.10/external/lua/lua/ltable.c:501:33: note: in expansion of macro ‘luai_numstd’
     else if (ttisnumber(key) && luai_numstd::isnan(nvalue(key)))
                                 ^
cocos/scripting/lua-bindings/CMakeFiles/luacocos2d.dir/build.make:302: recipe for target 'cocos/scripting/lua-bindings/CMakeFiles/luacocos2d.dir/__/__/__/external/lua/lua/ltable.c.o' failed
make[2]: *** [cocos/scripting/lua-bindings/CMakeFiles/luacocos2d.dir/__/__/__/external/lua/lua/ltable.c.o] Error 1
CMakeFiles/Makefile2:672: recipe for target 'cocos/scripting/lua-bindings/CMakeFiles/luacocos2d.dir/all' failed
make[1]: *** [cocos/scripting/lua-bindings/CMakeFiles/luacocos2d.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

Any help appreciated.

I just used 16.04 last week to run through these instructions and I did not run into anything of this nature.

Interesting. This (https://github.com/cocos2d/cocos2d-x/issues/15111) is a documented and active issue that has not been fixed in Master.

Interesting, indeed. Thanks for sending this.

Of note, since the first issue was already documented I created a new issue for the Lua function: https://github.com/cocos2d/cocos2d-x/issues/15544

Hi eht & everybody
I ran at the same problem in 16.04.
I used your solution and it (nearly) works and fixed nicely the fist issue, with exception to a few cases described below.
Concerning your Issue #2:
Apparently there happened to appear luai_num::isnan and your sed changed it to luai_numstd::isnan which was probably not what you intended. Another error introduced by this sed was that std::isnan which already existed at certain places in code was changed to std::std::isnan, so I had to modify your sed to revert double std to single one.

Cheers.

@teosbpl have you cloned fresh from github? those issues were resolved recently and shouldn’t take any tweaking.

However, you may run into an issue with jscocos that will also cause building to fail (https://github.com/cocos2d/cocos2d-x/issues/15624). I have not worked this one out yet.

I cloned probably yesterday.
I found some problems related with multithreaded compilation (make -j4).
I resolved them by running ‘make -j4’ a few times.
Apparently build was finished with no errors, however I didn’t try to compile my project yet.

Apart from this problem, I had no problems, after fixing this issue the cpp_tests ran with no problems.

So, I tried this last week on 15.04 and I compiled fine, using our v3.10 zip file and then cloning from GitHub.

I can try 16.04 and see how it works.

Hi @eht
I have this issue on 16.04 too, simple add:

using namespace std;

to 2 files:

cocos2d/extensions/GUI/CCControlExtension/CCControlUtils.cpp
cocos2d/cocos/2d/CCActionCamera.cpp

Hope this help
P/S: it seem your fix break core files, please copy new source code to cocos2d folder.

So, I downloaded 16.04, installed in a VMWare Fusion virtual machine and followed these steps and it worked up, until I tried to compile cpp-tests. I too see the isnan error. Did anyone make a GitHub issue for this yet?

I didn’t see a GitHub issue so I made one

Error in code blocks while building cocos2d-x “hello world” app

ERRORS:

error: ‘glfwSetWindowMonitor’ was not declared in this scope
recipe for target ‘cocos2d/cocos/CMakeFiles/cocos2dInternal.dir/platform/desktop/CCGLViewImpl-desktop.cpp.o’ failed
recipe for target ‘cocos2d/cocos/CMakeFiles/cocos2dInternal.dir/all’ failed
recipe for target ‘all’ failed

same here .

What version of cocos2d-x?

Hello slackmoehrle,

I found the same problem, and I solved it downloading glfw3 library.

My steps:
$git clone https://github.com/glfw/glfw
$mkdir build
$cd build
$cmake …/glfw
$make -j4
$sudo make install

And then I done a symbolic link to libglfw3.a as libglfw.a
$cd /usr/local/lib
$sudo ln -s libglfw3.a libglfw.a

With theses steps cocos2d-x works for me.
My Operating System: Ubuntu 16.04
My IDE: Code::Blocks 16.01 rev 10760
Cocos2d-x version 3.14.1

I’m having a new problem when I add a new Class to cocosd2-x project the compiler shows an error about “the class is not defined”.
I can solve this error if I add my cpp and h files inside CMakeList.txt file in the same location of AppDelegate and HelloWorldScene files. But it implies rebuild entire proyect (cocos2d-x library).

Can someone explain me how to add new classes in cocosd2-x project with the Code::Blocks IDE?

Best regards,
Programatta.

P.S: Sorry, but my English is not very good.

cocos2d-x-3.14.1
Cocos Console 2.2

Thanks programatta. your steps fix error for cocos2d-x-3.15.1 on ubuntu 16.04 amd64.