NDK & GoogleTest -- Error: limits: No such file or directory

2,156 views
Skip to first unread message

Charles Chan

unread,
May 2, 2014, 7:59:11 PM5/2/14
to andro...@googlegroups.com
Hello,

I am trying to get GoogleTest example working with NDK r9d on Windows with is blocked by an error when compiling the test

    >>> C:/Android/android-ndk-r9d/sources/third_party/googletest/googletest/include/gtest/gtest.h:54:18: fatal error: limits: No such file or directorycompilation terminated.
 
I have read the instructions described in \android-ndk-r9d\sources\third_party\googletest\README.NDK. Here are the steps I took:
1. Create a folder <project>\jni

2. Created jni/Android.mk:
        LOCAL_PATH := $(call my-dir)

        include $(CLEAR_VARS)
        LOCAL_MODULE := foo
        LOCAL_SRC_FILES := foo.cpp
        include $(BUILD_SHARED_LIBRARY)

        include $(CLEAR_VARS)
        LOCAL_MODULE := foo_unittest
        LOCAL_SRC_FILES := foo_unittest.cpp
        LOCAL_STATIC_LIBRARIES := googletest_main
        include $(BUILD_EXECUTABLE)

        $(call import-module,third_party/googletest)

3. Created foo.h, foo.cpp, foo_unit_test.cpp, copied from README.NDK

4. Run ndk-build and got an error:

C:\Users\cchan\Desktop\sample\jni>C:\Android\android-ndk-r9d\ndk-build V=1
del /f/q C:\Users\cchan\Desktop\sample\\libs\armeabi\libfoo.so     >NUL 2>NUL
[armeabi] Install        : libfoo.so => libs/armeabi/libfoo.so
copy /b/y "C:\Users\cchan\Desktop\sample\\obj\local\armeabi\libfoo.so" "C:\Users\cchan\Desktop\sample\\libs\armeabi\libfoo.so" > NUL
C:/Android/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/arm-linux-androideabi-strip --strip-unneeded  C:/Users/cchan/Desktop/sample
//libs/armeabi/libfoo.so
[armeabi] Compile++ thumb: foo_unittest <= foo_unittest.cc
C:/Android/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/arm-linux-androideabi-g++ -MMD -MP -MF C:/Users/cchan/Desktop/sample//obj/l
ocal/armeabi/objs/foo_unittest/foo_unittest.o.d -fpic -ffunction-sections -funwind-tables -fstack-protector -no-canonical-prefixes -march=armv5te -mtune=xscale
-msoft-float -fno-exceptions -fno-rtti -mthumb -Os -g -DNDEBUG -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -IC:/Android/android-ndk-r9d/sources/
cxx-stl/system/include -IC:/Android/android-ndk-r9d/sources/third_party/googletest/googletest/include -IC:/Users/cchan/Desktop/sample//jni -DANDROID  -Wa,--noex
ecstack -Wformat -Werror=format-security      -IC:/Android/android-ndk-r9d/platforms/android-3/arch-arm/usr/include -c  C:/Users/cchan/Desktop/sample//jni/foo_u
nittest.cc -o C:/Users/cchan/Desktop/sample//obj/local/armeabi/objs/foo_unittest/foo_unittest.o
In file included from C:/Users/cchan/Desktop/sample//jni/foo_unittest.cc:1:0:
C:/Android/android-ndk-r9d/sources/third_party/googletest/googletest/include/gtest/gtest.h:54:18: fatal error: limits: No such file or directory
compilation terminated.
make.exe: *** [C:/Users/cchan/Desktop/sample//obj/local/armeabi/objs/foo_unittest/foo_unittest.o] Error 1

When I search for limits.h I can see that there are multiple versions within the NDK, what do I need to do to make it work?

Thanks!
Charles

David Turner

unread,
May 3, 2014, 3:59:46 AM5/3/14
to andro...@googlegroups.com

You need to use a C++ STL with your project, the default is to use the system one which is extremely basic.

Add the following to your Application.mk:

APP_STL := stlport_static

For more details, read $NDK/docs/CPLUS-PLUS-SUPPORT

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at http://groups.google.com/group/android-ndk.
For more options, visit https://groups.google.com/d/optout.

Charles Chan

unread,
May 5, 2014, 8:50:39 PM5/5/14
to andro...@googlegroups.com
Thank you! That help me moved past the roadblock and taught me something new!

(For anyone else who might be attempting to do this ...)
After pushing the shared library and executable over to the device, MAKE SURE to set the permission with the executable bit. Otherwise, you might get a permission error when executing the GoogleTest executable.

10|root@android:/data/local/tmp # chmod 667 foo_unittest
chmod 667 foo_unittest

 255|root@android:/data/local/tmp # chmod 667 libfoo.so
chmod 667 libfoo.so

 255|root@android:/data/local/tmp # LD_LIBRARY_PATH=/data/local/tmp
LD_LIBRARY_PATH=/data/local/tmp
root@android:/data/local/tmp # LD_LIBRARY_PATH=/data/local/tmp
LD_LIBRARY_PATH=/data/local/tmp
root@android:/data/local/tmp # /data/local/tmp/foo_unittest
/data/local/tmp/foo_unittest
Running main() from gtest_main.cc
?[0;32m[==========] ?[mRunning 2 tests from 1 test case.
?[0;32m[----------] ?[mGlobal test environment set-up.
?[0;32m[----------] ?[m2 tests from FooTest
?[0;32m[ RUN      ] ?[mFooTest.ZeroZero
?[0;32m[       OK ] ?[mFooTest.ZeroZero (0 ms)
?[0;32m[ RUN      ] ?[mFooTest.OneOne
?[0;32m[       OK ] ?[mFooTest.OneOne (0 ms)
?[0;32m[----------] ?[m2 tests from FooTest (2 ms total)

?[0;32m[----------] ?[mGlobal test environment tear-down
?[0;32m[==========] ?[m2 tests from 1 test case ran. (11 ms total)
?[0;32m[  PASSED  ] ?[m2 tests.
Reply all
Reply to author
Forward
0 new messages