Sunday, March 2, 2014

Two annoying error in Cocos2d-x compilation

Working on Open Source technology require us to pay more attention on the works that we commit, especially the document/development guide must be up to date. For example, while I'm setting up the development environment for Cocos2d-x on Linux, there are some minor annoying build error which do not mention clearly on the document. As of this writing, I was using Ubuntu 13.04, and Cocos2d-x 2.2.2.

-Werror=maybe-unintialized
 CXX obj/release/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.o
../Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp: In member function ‘virtual void TestColliderDetector::update(float)’:
../Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp:1062:27: error: ‘maxx’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
../Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp:1062:27: error: ‘miny’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
../Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp:1062:27: error: ‘minx’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
cc1plus: all warnings being treated as errors
make[1]: *** [obj/release/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.o] Error 1
The first error I encountered was the variable has not been initialize. This is due to the compilation flag set to -Werror set in cocos2dx.mk located in <Cocos2dx_root>/cocos2dx/proj.linux. The simplest way to get rid of this error is to initialize those variable to 0.

-Werror=unused-variable
 CXX obj/release/Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest.o
../Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp: In member function ‘void UIListViewExTest_Vertical::selectedItemEvent(cocos2d::CCObject*, cocos2d::gui::ListViewEventType)’:
../Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp:170:25: error: unused variable ‘listViewEx’ [-Werror=unused-variable]
../Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp: In member function ‘void UIListViewExTest_Horizontal::selectedItemEvent(cocos2d::CCObject*, cocos2d::gui::ListViewEventType)’:
../Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp:346:29: error: unused variable ‘listViewEx’ [-Werror=unused-variable]
cc1plus: all warnings being treated as errors
The second error is there are some variable has been declare but it is not being use. To get rid of this problem, put additional -Wno-unused-variable flag into cocos2dx.mk file as shown below:
CC = gcc
CXX = g++
CCFLAGS += -MMD -Wall -Werror -Wno-unused-variable -fPIC
CXXFLAGS += -MMD -Wall -Werror -Wno-unused-variable -fPIC
...
...

No comments: