3

I have problem with building my android project with c++ file. It says that I must compile with C++11:

error: 'for' loop initial declarations are only allowed in C99 or C11 mode

And I know what this means, but I want to use c++11. And I have it included in gradle config:

android.ndk {
    moduleName = "native"

    stl = "gnustl_static"
    cppFlags += "-std=c++11"
    cppFlags += "-fexceptions"
    ldLibs.addAll(['android', 'log', 'OpenSLES'])
}

For what I searched, everyone has it same and it works. Does anybody know what is the problem?

Gustavo Pagani
  • 6,583
  • 5
  • 40
  • 71
Syntey
  • 147
  • 1
  • 15

2 Answers2

0

I suppose that you've already had a loop like this:

for(int i = low; i <= high; ++i)
        {
                res = runalg(i);
                if (res > highestres)
                {
                        highestres = res;
                }

        }

Please, declare var i outside of the loop.

It should solve the problem.

Think also about using while instead of for if possible.

EDIT: I found a solution which may be interesting for you:

In your Android.mk add

LOCAL_CFLAGS += -std=c99

For example:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_CFLAGS += -std=c99
LOCAL_SRC_FILES := com_example_ndktest_TestLib.c
LOCAL_MODULE := com_example_ndktest_TestLib
include $(BUILD_SHARED_LIBRARY)

Make sure you add 'LOCAL_CFLAGS' after adding 'include $(CLEAR_VARS)'

From: How to set standard c99 for compile android NDK project

Please check also link above.

Hope it help

Community
  • 1
  • 1
piotrek1543
  • 19,130
  • 7
  • 81
  • 94
0

Problem solved, it must be

CFlags.add("-std=c11")
Syntey
  • 147
  • 1
  • 15