cocos2d-x-2.1.4 : error: format not a string literal and no format arguments [-Werror=format-security]
Asked Answered
C

2

14

I am working on a game on cocos2d-x-2.1.4, however, when I try to build it on Android, it failed with the error: format not a string literal and no format arguments [-Werror=format-security] on the file CCCommon.cpp

However, when I check the offensive line, it is totally fine. The file also build fine and always been fine when I build for WIN32 and iOS with Visual Studio and XCode..

The error log is as follows:

C:/Development/External/cocos2d-2.1rc0-x-2.1.3/projects/Game_C2DX213/proj.android/../../..//cocos2dx/platform/android/CCCommon.cpp: In function 'void cocos2d::CCLog(char const*, ...)':
/cygdrive/c/eclipse/android-ndk-r9/build/core/build-binary.mk:348: recipe for target `obj/local/armeabi/objs/cocos2dx_static/platform/android/CCCommon.o' failed
C:/Development/External/cocos2d-2.1rc0-x-2.1.3/projects/Game_C2DX213/proj.android/../../..//cocos2dx/platform/android/CCCommon.cpp:44:72: error: format not a string literal and no format arguments [-Werror=format-security]
C:/Development/External/cocos2d-2.1rc0-x-2.1.3/projects/Game_C2DX213/proj.android/../../..//cocos2dx/platform/android/CCCommon.cpp: In function 'void cocos2d::CCLuaLog(char const*)':
make: Leaving directory `/cygdrive/c/Development/External/cocos2d-2.1rc0-x-2.1.3/projects/Game_C2DX213/proj.android'
C:/Development/External/cocos2d-2.1rc0-x-2.1.3/projects/Game_C2DX213/proj.android/../../..//cocos2dx/platform/android/CCCommon.cpp:54:77: error: format not a string literal and no format arguments [-Werror=format-security]
cc1plus.exe: some warnings being treated as errors
Clouded answered 23/8, 2013 at 2:25 Comment(0)
C
24

Note that cocos2d-x-2.1.4 may not be compatible with ndk-r9, have you try out r8e instead?

You can also put this in your Application.mk to disable treating those warnings as errors: APP_CFLAGS += -Wno-error=format-security

There are more solutions for the same problem in this thread:

http://www.cocos2d-x.org/boards/6/topics/32437?r=33260#message-33260

reference: http://www.cocos2d-x.org/boards/6/topics/33525?r=33579

Carpic answered 23/8, 2013 at 2:29 Comment(6)
where is Application.mk file located? Did you mean Android.mk file under $COCOS2DX_HOME/cocos2dx/Android.mk? I tried to put a line "APP_CFLAGS += -Wno-error=format-security" as a first line in that file but error persistsCake
"It's caused by android-ndk-r9, you could delete -Werror=format-security from android-ndk-r9/build/core/default-build-commands.mk" the following helped me, thanksCake
@Cake - If I understand correctly, your answer is different and relates to changing Android's files rather than developer's project files.Seed
@kilaka - yes, so i've patched android ndk itself. It's still better to change project's files rather then the ndk but it didn't work for me :(Cake
you should not patch NDK. there is LOCAL_DISABLE_FORMAT_STRING_CHECKS flag in android make files that controls it.Bellhop
APP_CFLAGS += -Wno-error=format-security takes no effect, LOCAL_DISABLE_FORMAT_STRING_CHECKS := true helped.Raybourne
B
13

you have to defice in you Android.mk following LOCAL_DISABLE_FORMAT_STRING_CHECKS := true

Bellhop answered 21/8, 2014 at 12:37 Comment(2)
If i am using Android Studio, how would you do this? Editing Android.mk does not seem to work.Unprincipled
@harikris imho you are compiling it via gradle and "new build system". It creates temporary Android.mk and uses it instead of your file. You have to read documentation and find a key to provide gragle with path to custom android.mk Or you may save lots time and use ndk-build as usual.Bellhop

© 2022 - 2024 — McMap. All rights reserved.