hello-jni modified to use stlport (attached)

1,157 views
Skip to first unread message

Dmitry.Skiba

unread,
Jul 9, 2009, 3:26:00 AM7/9/09
to android-ndk
Hello.

I managed to get stlport (from gears) working with NDK.
I've attached modified hello-jni sample:
http://android-ndk.googlegroups.com/web/hello-jni-with-stlport.zip

NOTE: you need to do step (3).

What was modified:
(1) Paths in _STLP_NATIVE_* macros in stlport/stl/config/_android.h.
In NDK all headers are just dumped in one "include" folder.
(2) stdport/stddef.h and stlport/stdarg.h are renamed to stddef.aaa
and stdarg.aaa because they caused recursive inclusion of themselves.
(3) utility header from build\platforms\android-1.5\arch-arm\usr
\include\utility was renamed to utility.aaa, because it was getting in
the way of stlport's one.

Makoto

unread,
Aug 1, 2009, 6:33:17 AM8/1/09
to android-ndk
Hi.

Thank you for the instruction.

I am currently trying to port one C++ library (the more detail is at
http://groups.google.com/group/android-ndk/browse_thread/thread/10f2e02c5d6857cb/2bb674b03ccdf801
) and realized that it's raising error because NDK does not have
iostream which depends on STL (I am C++ newbie. sorry if this
explanation is wrong).

I copied the stlport in the zip to my source dir and modified
Android.mk to include the stlport, but facing various problems. I
would appreciate if you could spot something I did wrong.


$ ls sources/zinnia/
.git/ Android.mk example.c example.cpp stlport/
zinnia-0.05/

$ tail sources/zinnia/Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := zinnia
LOCAL_SRC_FILES := example.cpp \
zinnia-0.05/zinnia.cpp
LOCAL_CFLAGS := -I$(LOCAL_PATH)/stlport

When I ran make command, I got a error complaining that std::pair are
defined twice.

$ make APP=zinnia -B
Android NDK: Building for application 'zinnia'
Compile++ thumb: zinnia <= sources/zinnia/example.cpp
In file included from sources/zinnia/stlport/stl/_algobase.h:50,
from sources/zinnia/stlport/stl/_alloc.h:47,
from sources/zinnia/stlport/stl/_string.h:23,
from sources/zinnia/stlport/stl/_ios_base.h:34,
from sources/zinnia/stlport/stl/_ios.h:23,
from sources/zinnia/stlport/stl/_istream.h:27,
from sources/zinnia/stlport/iostream:39,
from sources/zinnia/stlport/iostream.h:24,
from sources/zinnia/example.cpp:1:
sources/zinnia/stlport/stl/_pair.h:45: error: redefinition of
'struct std::pair<_T1, _T2>'
build/platforms/android-1.5/arch-arm/usr/include/stl_pair.h:64:
error: previous definition of 'struct std::pair<_T1, _T2>'
sources/zinnia/stlport/stl/_pair.h:73: error: redefinition of
'template<class _T1, class _T2> bool std::operator==(const
std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)'

I commented out sources/zinnia/stlport/stl/_pair.h and now getting
these errors. Looks it's complaining that these are not defined
(exampe.cpp is just a sample c++ code at http://zinnia.sourceforge.net/)

* std::locale::_M_use_facet(std::locale::id const&) const
* std::ios_base::_M_throw_failure()
* std::locale::locale(std::locale const&)
* std::locale::~locale()

$ make APP=zinnia -B
Android NDK: Building for application 'zinnia'
Compile++ thumb: zinnia <= sources/zinnia/example.cpp
Compile++ thumb: zinnia <= sources/zinnia/zinnia-0.05/zinnia.cpp
SharedLibrary : libzinnia.so
out/apps/zinnia/android-1.5-arm/objs/zinnia/zinnia-0.05/zinnia.o: In
function `main':
sources/zinnia/zinnia-0.05/zinnia.cpp:11: multiple definition of
`main'
out/apps/zinnia/android-1.5-arm/objs/zinnia/example.o:sources/zinnia/
example.cpp:9: first defined here
/Applications/android-ndk-1.5_r1/build/prebuilt/darwin-x86/arm-
eabi-4.2.1/bin/../lib/gcc/arm-eabi/4.2.1/../../../../arm-eabi/bin/ld:
Warning: size of symbol `main' changed from 988 in out/apps/zinnia/
android-1.5-arm/objs/zinnia/example.o to 4 in out/apps/zinnia/
android-1.5-arm/objs/zinnia/zinnia-0.05/zinnia.o
out/apps/zinnia/android-1.5-arm/objs/zinnia/example.o: In function
`std::num_put<char, std::ostreambuf_iterator<char,
std::char_traits<char> > >* std::_UseFacet<std::num_put<char,
std::ostreambuf_iterator<char, std::char_traits<char> > > >
(std::locale const&, std::num_put<char, std::ostreambuf_iterator<char,
std::char_traits<char> > > const*)':
example.cpp:
(.gnu.linkonce.t._ZSt9_UseFacetISt7num_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEEEPT_RKSt6localePKS6_
+0x10): undefined reference to `std::locale::_M_use_facet
(std::locale::id const&) const'
out/apps/zinnia/android-1.5-arm/objs/zinnia/example.o: In function
`bool stlp_priv::__init_bostr<char, std::char_traits<char> >
(std::basic_ostream<char, std::char_traits<char> >&)':
example.cpp:
(.gnu.linkonce.t._ZN9stlp_priv12__init_bostrIcSt11char_traitsIcEEEbRSt13basic_ostreamIT_T0_E
+0xd4): undefined reference to `std::ios_base::_M_throw_failure()'
out/apps/zinnia/android-1.5-arm/objs/zinnia/example.o: In function
`std::basic_ostream<char, std::char_traits<char> >&
stlp_priv::__put_num<char, std::char_traits<char>, double>
(std::basic_ostream<char, std::char_traits<char> >&, double)':
example.cpp:
(.gnu.linkonce.t._ZN9stlp_priv9__put_numIcSt11char_traitsIcEdEERSt13basic_ostreamIT_T0_ES7_T1_
+0xbc): undefined reference to `std::ios_base::_M_throw_failure()'
example.cpp:
(.gnu.linkonce.t._ZN9stlp_priv9__put_numIcSt11char_traitsIcEdEERSt13basic_ostreamIT_T0_ES7_T1_
+0xd8): undefined reference to `std::locale::locale(std::locale
const&)'
example.cpp:
(.gnu.linkonce.t._ZN9stlp_priv9__put_numIcSt11char_traitsIcEdEERSt13basic_ostreamIT_T0_ES7_T1_
+0x144): undefined reference to `std::locale::~locale()'
out/apps/zinnia/android-1.5-arm/objs/zinnia/example.o: In function
`std::basic_ostream<char, std::char_traits<char> >::put(char)':
example.cpp:(.gnu.linkonce.t._ZNSo3putEc+0x114): undefined reference
to `std::ios_base::_M_throw_failure()'
out/apps/zinnia/android-1.5-arm/objs/zinnia/example.o: In function
`std::basic_ostream<char, std::char_traits<char> >& std::endl<char,
std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&)':
example.cpp:
(.gnu.linkonce.t._ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
+0x7c): undefined reference to `std::ios_base::_M_throw_failure()'
out/apps/zinnia/android-1.5-arm/objs/zinnia/example.o: In function
`std::basic_ostream<char, std::char_traits<char> >::_M_put_nowiden
(char const*)':
example.cpp:(.gnu.linkonce.t._ZNSo14_M_put_nowidenEPKc+0x94):
undefined reference to `std::ios_base::_M_throw_failure()'
example.cpp:(.gnu.linkonce.t._ZNSo14_M_put_nowidenEPKc+0x130):
undefined reference to `std::ios_base::_M_throw_failure()'
out/apps/zinnia/android-1.5-arm/objs/zinnia/example.o: In function
`main':
example.cpp:(.text.main+0x4): undefined reference to
`zinnia::Recognizer::create()'
example.cpp:(.text.main+0x30): undefined reference to
`zinnia::Character::create()'
example.cpp:(.text.main+0x3c4): undefined reference to `std::cout'
example.cpp:(.text.main+0x3d8): undefined reference to `std::cerr'
out/apps/zinnia/android-1.5-arm/objs/zinnia/zinnia-0.05/zinnia.o: In
function `main':
zinnia.cpp:(.text.main+0x0): undefined reference to `zinnia_do'
collect2: ld returned 1 exit status
make: *** [out/apps/zinnia/android-1.5-arm/libzinnia.so] Error 1

Thanks.

Makoto

John Ripley

unread,
Aug 2, 2009, 10:43:42 AM8/2/09
to andro...@googlegroups.com
Hi Makoto,

You can try using the version of STLport I've prepared here: http://code.google.com/p/android-ndk-wrappers/ (in no way an officially sanctioned project - just a convenience hack I'm using).

Add the defines that the script in bin/arm-linux-g++ uses, and include that version of STLport. Alternatively, just use your library's existing build system and get it to use arm-linux-g++ as the compiler, instead of invoking the NDK's Android.mk (but this makes the rest of the build process messy). It should give you all STL features, including iostreams (but still lacks rtti/exceptions).

2009/8/1 Makoto <inou...@googlemail.com>

Makoto

unread,
Aug 3, 2009, 8:30:07 PM8/3/09
to android-ndk
Hi, John.

Thank you very much for letting me know your code.

I downloaded, tweaked a bit (changed linux-x86 to darwin-x86, as I use
Mac), and ran setup.sh, which seemed working fine.

http://gist.github.com/160900

Then I tried to include iosteam, but did not find anywhere under
$NDK_DIR apart from "stlport" directory I manually copied before I
tried out your approach.

makoto-inoues-macbook:android-ndk-1.5_r1 makoto$ find . -name
'*iostream*' -print
./sources/zinnia/stlport/iostream
./sources/zinnia/stlport/iostream.h
./sources/zinnia/stlport/stdiostream.h
./sources/zinnia/stlport/stl/_iostream_string.h
./sources/zinnia/stlport/using/h/iostream.h
./sources/zinnia/stlport/using/iostream

Let me know if I am missing anything.

Thanks.

On Aug 2, 3:43 pm, John Ripley <jrip...@google.com> wrote:
> Hi Makoto,
>
> You can try using the version of STLport I've prepared here:http://code.google.com/p/android-ndk-wrappers/(in no way an officially
> sanctioned project - just a convenience hack I'm using).
>
> Add the defines that the script in bin/arm-linux-g++ uses, and include that
> version of STLport. Alternatively, just use your library's existing build
> system and get it to use arm-linux-g++ as the compiler, instead of invoking
> the NDK's Android.mk (but this makes the rest of the build process messy).
> It should give you all STL features, including iostreams (but still lacks
> rtti/exceptions).
>
> 2009/8/1 Makoto <inoue...@googlemail.com>
>
>
>
>
>
> > Hi.
>
> > Thank you for the instruction.
>
> > I am currently trying to port one C++ library (the more detail is at
>
> >http://groups.google.com/group/android-ndk/browse_thread/thread/10f2e...
> > (exampe.cpp is just a sample c++ code athttp://zinnia.sourceforge.net/)

John Ripley

unread,
Aug 4, 2009, 5:12:18 AM8/4/09
to andro...@googlegroups.com
The trunk/bin/arm-linux-g++ script adds include paths (-I) so that you can just use '#include <iostream>'. If you're using the NDK's build system (and not bin/arm-linux-g++) then you'll need to add the flags from that script into your Android.mk. You'll need all the -D defines, -I include for stlport, -L for the path to the built STLport static library, and -l to source libstlport.a.

(Btw - if we start getting a lot of traffic for wrapper/STLport questions, I'll make a google group for it as it's not really on-topic)

2009/8/4 Makoto <inou...@googlemail.com>

Makoto

unread,
Aug 4, 2009, 3:56:32 PM8/4/09
to android-ndk
Hi John.

I wasn't quite sure how to define all you mentioned at android.mk
(sorry, I think I am too newbie to even digest your explanation), so
just I run the arm-linux-g++ directly , and here is the result.

Unknown-00-21-e9-db-a7-d3:zinnia makoto$ /Applications/android-ndk-
wrappers-read-only/bin/arm-linux-g++ example.cpp
sed: illegal option -- r
usage: sed script [-Ealn] [-i extension] [file ...]
sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ...
[file ...]
sed: illegal option -- r
usage: sed script [-Ealn] [-i extension] [file ...]
sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ...
[file ...]
/var/folders/Fd/FdTalhBeHIysWX+L6Gd8cU+++TI/-Tmp-//ccBX68ar.o: In
function `main':
example.cpp:(.text.main+0x2c): undefined reference to
`zinnia::Recognizer::create()'
example.cpp:(.text.main+0xe4): undefined reference to
`zinnia::Character::create()'
collect2: ld returned 1 exit status


It's not complaining any more about iostream, so I guess stlport part
went well, and I think I just hit completely different problem.
I'll try to investigate a bit more myself. Thank you for your help
about stlport.

Makoto

On Aug 4, 10:12 am, John Ripley <jrip...@google.com> wrote:
> The trunk/bin/arm-linux-g++ script adds include paths (-I) so that you can
> just use '#include <iostream>'. If you're using the NDK's build system (and
> not bin/arm-linux-g++) then you'll need to add the flags from that script
> into your Android.mk. You'll need all the -D defines, -I include for
> stlport, -L for the path to the built STLport static library, and -l to
> source libstlport.a.
>
> (Btw - if we start getting a lot of traffic for wrapper/STLport questions,
> I'll make a google group for it as it's not really on-topic)
>
> 2009/8/4 Makoto <inoue...@googlemail.com>
>
>
>
>
>
> > Hi, John.
>
> > Thank you very much for letting me know your code.
>
> > I downloaded, tweaked a bit (changed linux-x86 to darwin-x86, as I use
> > Mac), and ran setup.sh, which seemed working fine.
>
> >http://gist.github.com/160900
>
> > Then I tried to include iosteam, but did not find anywhere under
> > $NDK_DIR apart from "stlport" directory I manually copied before I
> > tried out your approach.
>
> > makoto-inoues-macbook:android-ndk-1.5_r1 makoto$ find . -name
> > '*iostream*' -print
> > ./sources/zinnia/stlport/iostream
> > ./sources/zinnia/stlport/iostream.h
> > ./sources/zinnia/stlport/stdiostream.h
> > ./sources/zinnia/stlport/stl/_iostream_string.h
> > ./sources/zinnia/stlport/using/h/iostream.h
> > ./sources/zinnia/stlport/using/iostream
>
> > Let me know if I am missing anything.
>
> > Thanks.
>
> > On Aug 2, 3:43 pm, John Ripley <jrip...@google.com> wrote:
> > > Hi Makoto,
>
> > > You can try using the version of STLport I've prepared here:
> >http://code.google.com/p/android-ndk-wrappers/(in<http://code.google.com/p/android-ndk-wrappers/%28in>no way an officially
> > > > > I've attached modified hello-jni sample:...
>
> read more »

John Ripley

unread,
Aug 4, 2009, 5:08:19 PM8/4/09
to andro...@googlegroups.com
I've been asked similar questions a few times now, so I decided to just check in a complete working NDK-based example. I also fixed up Darwin support (I hope - can't test it).

Update your android-ndk-wrappers repository, then symlink the 'apps/hello-stl' and 'samples/hello-stl' directories into the NDK tree. Edit the Android.mk under samples/hello-stl to point STLPORT at the right directory. Build in the usual fashion. Make sure you built STLport already from the ndk-wrappers directory. Hope that helps!

That's now a complete example of getting STLport working with the NDK, using the NDK build system.

2009/8/4 Makoto <inou...@googlemail.com>

Makoto

unread,
Aug 5, 2009, 6:19:23 PM8/5/09
to android-ndk
Hi, John.

Thank you very much for your update. I think I managed to compile the
library I wanted to port(zinnia).

You still had "linux-x86" hard-coded at stlport/build/lib/android.mak
line 12, so changed as follows.

-TOOLCHAIN_PREFIX := $(NDK_DIR)/build/prebuilt/linux-x86/arm-
eabi-4.2.1/bin/arm-eabi-
+TOOLCHAIN_PREFIX := $(NDK_DIR)/build/prebuilt/darwin-x86/arm-
eabi-4.2.1/bin/arm-eabi-

Then, I made symlink(as you suggested) and ran your sample hello-stl,
which compiled fine.

Unknown-00-21-e9-db-a7-d3:android-ndk-1.5_r1 makoto$ ls -ltr apps/
hello-stl
lrwxr-xr-x 1 makoto staff 59 5 Aug 21:43 apps/hello-stl -> /
Applications/android-ndk-wrappers-read-only/apps/hello-stl
Unknown-00-21-e9-db-a7-d3:android-ndk-1.5_r1 makoto$ ls -ltr sources/
samples/hello-stl
lrwxr-xr-x 1 makoto staff 62 5 Aug 21:52 sources/samples/hello-stl
-> /Applications/android-ndk-wrappers-read-only/samples/hello-stl
Unknown-00-21-e9-db-a7-d3:android-ndk-1.5_r1 makoto$ make APP=hello-
stl
Android NDK: Building for application 'hello-stl'
Compile++ thumb: hello-stl <= sources/samples/hello-stl/hello-stl.cc
SharedLibrary : libhello-stl.so
Install : libhello-stl.so => apps/hello-stl/project/libs/
armeabi

As a next step, I changed my Android.mk file similar to your stlport
sample Android.mk like below

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

STLPORT_BASE := /Applications/android-ndk-wrappers-read-only/stlport

LOCAL_MODULE := zinnia
LOCAL_SRC_FILES := example.cpp \
zinnia-0.05/zinnia.cpp

LOCAL_CPP_EXTENSION := .cc
LOCAL_CFLAGS += -I$(STLPORT_BASE)/stlport \
-D__NEW__ \
-D__SGI_STL_INTERNAL_PAIR_H \
-DANDROID \
-DOS_ANDROID
LOCAL_LDLIBS += -L$(STLPORT_BASE)/build/lib/obj/gcc/so \
-lstlport

include $(BUILD_SHARED_LIBRARY)

When I ran it, it showed some "assertion fail" message, but at least
it generated libzinnia.so file.

Unknown-00-21-e9-db-a7-d3:android-ndk-1.5_r1 makoto$ make APP=zinnia
Android NDK: Building for application 'zinnia'
SharedLibrary : libzinnia.so
/Applications/android-ndk-1.5_r1/build/prebuilt/darwin-x86/arm-
eabi-4.2.1/bin/../lib/gcc/arm-eabi/4.2.1/../../../../arm-eabi/bin/ld:
BFD 2.17 assertion fail /Volumes/Android/git/android-ndk/out/arm-
eabi-4.2.1/toolchain/src/binutils-2.17/bfd/elf32-arm.c:2428
/Applications/android-ndk-1.5_r1/build/prebuilt/darwin-x86/arm-
eabi-4.2.1/bin/../lib/gcc/arm-eabi/4.2.1/../../../../arm-eabi/bin/ld:
BFD 2.17 assertion fail /Volumes/Android/git/android-ndk/out/arm-
eabi-4.2.1/toolchain/src/binutils-2.17/bfd/elf32-arm.c:2428
/Applications/android-ndk-1.5_r1/build/prebuilt/darwin-x86/arm-
eabi-4.2.1/bin/../lib/gcc/arm-eabi/4.2.1/../../../../arm-eabi/bin/ld:
BFD 2.17 assertion fail /Volumes/Android/git/android-ndk/out/arm-
eabi-4.2.1/toolchain/src/binutils-2.17/bfd/elf32-arm.c:2428
Install : libzinnia.so => apps/zinnia/project/libs/armeabi

Now I will try to see if I can invoke it from Java.

Makoto




On Aug 4, 10:08 pm, John Ripley <jrip...@google.com> wrote:
> I've been asked similar questions a few times now, so I decided to just
> check in a complete working NDK-based example. I also fixed up Darwin
> support (I hope - can't test it).
>
> Update your android-ndk-wrappers repository, then symlink the
> 'apps/hello-stl' and 'samples/hello-stl' directories into the NDK tree. Edit
> the Android.mk under samples/hello-stl to point STLPORT at the right
> directory. Build in the usual fashion. Make sure you built STLport already
> from the ndk-wrappers directory. Hope that helps!
>
> That's now a complete example of getting STLport working with the NDK, using
> the NDK build system.
>
> 2009/8/4 Makoto <inoue...@googlemail.com>
>
>
>
>
>
> > Hi, John.
>
> > Thank you very much for letting me know your code.
>
> > I downloaded, tweaked a bit (changed linux-x86 to darwin-x86, as I use
> > Mac), and ran setup.sh, which seemed working fine.
>
> >http://gist.github.com/160900
>
> > Then I tried to include iosteam, but did not find anywhere under
> > $NDK_DIR apart from "stlport" directory I manually copied before I
> > tried out your approach.
>
> > makoto-inoues-macbook:android-ndk-1.5_r1 makoto$ find . -name
> > '*iostream*' -print
> > ./sources/zinnia/stlport/iostream
> > ./sources/zinnia/stlport/iostream.h
> > ./sources/zinnia/stlport/stdiostream.h
> > ./sources/zinnia/stlport/stl/_iostream_string.h
> > ./sources/zinnia/stlport/using/h/iostream.h
> > ./sources/zinnia/stlport/using/iostream
>
> > Let me know if I am missing anything.
>
> > Thanks.
>
> > On Aug 2, 3:43 pm, John Ripley <jrip...@google.com> wrote:
> > > Hi Makoto,
>
> > > You can try using the version of STLport I've prepared here:
> >http://code.google.com/p/android-ndk-wrappers/(in<http://code.google.com/p/android-ndk-wrappers/%28in>no way an officially
> > > > > I managed to get...
>
> read more »

John Ripley

unread,
Aug 5, 2009, 6:53:16 PM8/5/09
to andro...@googlegroups.com
You've managed to crash gcc. Well done :)

Actually, I had that same problem - there was a subtle combination of flags which caused it. I'll try to reproduce how I managed it - but I'm busy the next few evenings - I'll see if I can find out what caused it.

Cheers,

John.

2009/8/5 Makoto <inou...@googlemail.com>
Reply all
Reply to author
Forward
0 new messages