bulding gtest with ndk toolchain, not quite there!

912 views
Skip to first unread message

jwalseth

unread,
Feb 4, 2011, 7:35:00 PM2/4/11
to android-ndk
Wanting to exercise purely native unit tests on the Android device, I
had the idea of cross-compiling GoogleTest (aka, gtest see
http://code.google.com/p/googletest/wiki/Primer ) using the NDK tool
chain as described in /android-ndk-r5b/docs/STANDALONE-
TOOLCHAIN.html. Then push the executable across using adb and run
from the adb shell. This should work right?

I got close (I think) but stumped by object files and library with no
symbols. I used 'nm' to look at things and it is always coming up
empty. I am using the Makefile provided with gtest though tinkered
with it more and more trying to fix the problem.

I tried using both methods in 'STANDALONE-TOOLCHAIN.html', the latter
(3/ Invoking the compiler, the easy way) is the one that got me this
close:

Jim-Walseths-MacBook-Pro:make jimwalseth$ make sample1_unittest
arm-linux-androideabi-g++ -I../include -g -mthumb -c ../samples/
sample1.cc
arm-linux-androideabi-g++ -I../include -g -mthumb -c ../samples/
sample1_unittest.cc
arm-linux-androideabi-g++ -I../include -I.. -g -mthumb -c \
../src/gtest-all.cc
arm-linux-androideabi-g++ -I../include -I.. -g -mthumb -c \
../src/gtest_main.cc
ar -rv gtest_main.a gtest-all.o gtest_main.o
ar: creating archive gtest_main.a
a - gtest-all.o
a - gtest_main.o
arm-linux-androideabi-g++ -I../include -g -mthumb sample1.o
sample1_unittest.o gtest_main.a -o sample1_unittest
gtest_main.a: could not read symbols: Archive has no index; run ranlib
to add one
collect2: ld returned 1 exit status
make: *** [sample1_unittest] Error 1


alan

unread,
Feb 7, 2011, 5:16:17 AM2/7/11
to andro...@googlegroups.com
i have managed to get cppunit to work by generating a junit class which searches for c++ tests and generates junit test cases for them, you may be able to do something similar for gtest

David Turner

unread,
Feb 8, 2011, 7:56:55 PM2/8/11
to andro...@googlegroups.com
Di you tried using arm-linux-androideabi-ar instead of "ar"?



--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


jwalseth

unread,
Feb 17, 2011, 8:08:16 PM2/17/11
to android-ndk
Right, David thanks. Though it appeared the "ar" in my path was the
correct one, using arm-linux-androideabi-ar explicitly worked.

NOW I have these executable binaries that (in theory) I can run on an
Android device! I have been able to push the file across using:

adb push sample1_unittest /sdcard

(the only writable path I could find).

But when I start a shell session on the device with

adb shell and navigate to /sdcard and run the exec ( ./
sample1_unittest )

I get Permission Denied. I am assuming there must be some way to
execute a program, or why have the toolchain?

$ adb shell
$ cd sdcard
$ ls
LOST.DIR
Android
sample1_unittest
$ ./sample1_unittest
./sample1_unittest: permission denied

Jim

On Feb 8, 4:56 pm, David Turner <di...@android.com> wrote:
> Di you tried using arm-linux-androideabi-ar instead of "ar"?
>
> On Sat, Feb 5, 2011 at 1:35 AM, jwalseth <jim.wals...@gmail.com> wrote:
> > Wanting to exercise purely native unit tests on the Android device, I
> > had the idea of cross-compiling GoogleTest (aka, gtest see
> >http://code.google.com/p/googletest/wiki/Primer) using the NDK tool

jwalseth

unread,
Feb 17, 2011, 8:36:27 PM2/17/11
to android-ndk
Answer: use /data/local for destination, I am able to run my unit
tests from there! Cool!
Reply all
Reply to author
Forward
0 new messages