[osg-users] Undefined reference when building osg for Android

149 views
Skip to first unread message

Julius Haertl

unread,
Nov 5, 2014, 7:17:43 PM11/5/14
to osg-...@lists.openscenegraph.org
Hello ,

I'm trying to build OpenSceneGraph for Android and getting started with the
osgViewer example application. After getting around the first errors, I'm quite
stuck with the following while building with ndk-build.
ndk-build keeps complaining about missing reference of rand and stat64.

jus@tp-e130:~/workspace/osgViewer$ $ANDROID_NDK/ndk-build
Android NDK: WARNING: APP_PLATFORM android-19 is larger than android:minSdkVersion 8 in ./AndroidManifest.xml
Android NDK: WARNING:jni/Android.mk:osgNativeLib: non-system libraries in linker flags: -lgnustl_static -losgdb_dds -losgdb_openflight -losgdb_tga -losgdb_rgb -losgdb_osgterrain -losgdb_osg -losgdb_ive -losgdb_deprecated_osgviewer -losgdb_deprecated_osgvolume -losgdb_deprecated_osgtext -losgdb_deprecated_osgterrain -losgdb_deprecated_osgsim -losgdb_deprecated_osgshadow -losgdb_deprecated_osgparticle -losgdb_deprecated_osgfx -losgdb_deprecated_osganimation -losgdb_deprecated_osg -losgdb_serializers_osgvolume -losgdb_serializers_osgtext -losgdb_serializers_osgterrain -losgdb_serializers_osgsim -losgdb_serializers_osgshadow -losgdb_serializers_osgparticle -losgdb_serializers_osgmanipulator -losgdb_serializers_osgfx -losgdb_serializers_osganimation -losgdb_serializers_osg -losgViewer -losgVolume -losgTerrain -losgText -losgShadow -losgSim -losgParticle -losgManipulator -losgGA -losgFX -losgDB -losgAnimation -losgUtil -losg -lOpenThreads /home/jus/workspace/osgViewer/obj/local/arm
eabi-v7a/libgnustl_static.a
Android NDK: This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
Android NDK: or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the
Android NDK: current module
Android NDK: WARNING:jni/Android.mk:osgNativeLib: non-system libraries in linker flags: -lgnustl_static -losgdb_dds -losgdb_openflight -losgdb_tga -losgdb_rgb -losgdb_osgterrain -losgdb_osg -losgdb_ive -losgdb_deprecated_osgviewer -losgdb_deprecated_osgvolume -losgdb_deprecated_osgtext -losgdb_deprecated_osgterrain -losgdb_deprecated_osgsim -losgdb_deprecated_osgshadow -losgdb_deprecated_osgparticle -losgdb_deprecated_osgfx -losgdb_deprecated_osganimation -losgdb_deprecated_osg -losgdb_serializers_osgvolume -losgdb_serializers_osgtext -losgdb_serializers_osgterrain -losgdb_serializers_osgsim -losgdb_serializers_osgshadow -losgdb_serializers_osgparticle -losgdb_serializers_osgmanipulator -losgdb_serializers_osgfx -losgdb_serializers_osganimation -losgdb_serializers_osg -losgViewer -losgVolume -losgTerrain -losgText -losgShadow -losgSim -losgParticle -losgManipulator -losgGA -losgFX -losgDB -losgAnimation -losgUtil -losg -lOpenThreads /home/jus/workspace/osgViewer/obj/local/arm
eabi-v7a/libgnustl_static.a
Android NDK: This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
Android NDK: or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the
Android NDK: current module
[armeabi] Compile++ thumb: osgNativeLib <= osgNativeLib.cpp
[armeabi] Compile++ thumb: osgNativeLib <= OsgMainApp.cpp
[armeabi] Compile++ thumb: osgNativeLib <= OsgAndroidNotifyHandler.cpp
[armeabi] SharedLibrary : libosgNativeLib.so
/home/jus/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/jus/Android/OpenSceneGraph-3.2.1/osginstall/obj/local/armeabi/libosgdb_deprecated_osgparticle.a(IO_SectorPlacer.o): in function osgParticle::SectorPlacer::place(osgParticle::Particle*) const:/home/jus/Android/OpenSceneGraph-3.2.1/include/osgParticle/range:65: error: undefined reference to 'rand'
/home/jus/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/jus/Android/OpenSceneGraph-3.2.1/osginstall/obj/local/armeabi/libosgdb_deprecated_osgparticle.a(IO_SectorPlacer.o): in function osgParticle::SectorPlacer::place(osgParticle::Particle*) const:/home/jus/Android/OpenSceneGraph-3.2.1/include/osgParticle/range:59: error: undefined reference to 'rand'
/home/jus/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/jus/Android/OpenSceneGraph-3.2.1/osginstall/obj/local/armeabi/libosgdb_deprecated_osgparticle.a(IO_RadialShooter.o): in function osgParticle::range<float>::get_random() const:/home/jus/Android/OpenSceneGraph-3.2.1/include/osgParticle/range:59: error: undefined reference to 'rand'
/home/jus/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/jus/Android/OpenSceneGraph-3.2.1/osginstall/obj/local/armeabi/libosgdb_deprecated_osgparticle.a(IO_RadialShooter.o): in function osgParticle::range<osg::Vec3f>::get_random() const:/home/jus/Android/OpenSceneGraph-3.2.1/include/osgParticle/range:59: error: undefined reference to 'rand'
/home/jus/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/jus/Android/OpenSceneGraph-3.2.1/osginstall/obj/local/armeabi/libosgDB.a(FileUtils.o): in function osgDB::fileType(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&):/home/jus/Android/OpenSceneGraph-3.2.1/src/osgDB/FileUtils.cpp:306: error: undefined reference to 'stat64'
/home/jus/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/jus/Android/OpenSceneGraph-3.2.1/osginstall/obj/local/armeabi/libosgDB.a(FileUtils.o): in function osgDB::makeDirectory(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&):/home/jus/Android/OpenSceneGraph-3.2.1/src/osgDB/FileUtils.cpp:153: error: undefined reference to 'stat64'
/home/jus/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/jus/Android/OpenSceneGraph-3.2.1/osginstall/obj/local/armeabi/libosgDB.a(FileUtils.o): in function osgDB::makeDirectory(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&):/home/jus/Android/OpenSceneGraph-3.2.1/src/osgDB/FileUtils.cpp:176: error: undefined reference to 'stat64'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/libosgNativeLib.so] Error 1


I'm using OpenSceneGraph 3.2.1 with Android NDK r10c.
I hope somebody can help me with this issue.

Thanks,
Julius


_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Julius Haertl

unread,
Nov 13, 2014, 5:30:49 AM11/13/14
to OpenSceneGraph Users
Hello,

sorry for the bump, but I sill can't figure out, why I get this compilation
errors. It would be realy nice if someone could take a look at it and help me
out.

Thank you,
Julius
signature.asc

Rafa Gaitan

unread,
Nov 13, 2014, 6:20:56 AM11/13/14
to OpenSceneGraph Users
Hi Julius,

I got the same problem, and I was unable to fix it with the current build system for android. Thats why I realized the submission with the changes for building with the ToolChain. I didn't change the examples to use this new build system but maybe you could you try to build OSG using my submissions and see if still happens, I'm using osgAndroid (https://gitorious.org/osgandroid) and it works.

In case you try to use the submission and osgAndroid, you need to copy the libgnustl_static.a from the NDK (android-ndk-r10c/sources/cxx-stl/gnu-libstdc++/4.9/libs/<target-platform>/) to the installed OSG_SDK/lib.

If you find any problems building it, I'll try to fix it ASAP.

Regards,
Rafa.

--
Rafael Gaitán Linares
CTO at Mirage Technologies S.L - http://www.mirage-tech.com

Julius Haertl

unread,
Nov 13, 2014, 7:43:30 AM11/13/14
to OpenSceneGraph Users
Hi Rafa,

thanks for your advice so far. I will try building with the
toolchain/osgAndroid tomorrow and report back.

Kind regards,
Julius
signature.asc

Julius Haertl

unread,
Nov 13, 2014, 10:46:05 AM11/13/14
to OpenSceneGraph Users
Ok, the osg build works fine with the toolchain.

Now I'm getting errors about missing osg libs, when building
org.openscenegraph.android. This seems strage to me, as the .so files are in
/home/jus/working/osg/osg/build_gles1/lib/osgPlugins-3.3.3 and this path is
also setup to be used by the linker.

You can find the complete output of the ndk-build here: http://paste.cat/b2c707df

Thanks so far,
Julius


On Thu, Nov 13, 2014 at 12:20:52PM +0100, Rafa Gaitan wrote:

Rafa Gaitan

unread,
Nov 13, 2014, 11:51:16 AM11/13/14
to OpenSceneGraph Users
Hi Julius,

Seems that the ndk is not finding the libraries in the path. 

Are the generated .a files in this path? -L/home/jus/working/osg/osg/build_gles1/lib

Is OSG generated with armeabi?, I think the ndk sets the armeabi-v7 version by default, and osgAndroid is configured with armeabi in the Application.mk maybe that is giving some troubles.

Rafa.



Julius Haertl

unread,
Nov 18, 2014, 7:44:16 AM11/18/14
to OpenSceneGraph Users
On Thu, Nov 13, 2014 at 05:51:00PM +0100, Rafa Gaitan wrote:
> Hi Julius,
>
> Seems that the ndk is not finding the libraries in the path.
>
> Are the generated .a files in this path?
> -L/home/jus/working/osg/osg/build_gles1/lib
>
> Is OSG generated with armeabi?, I think the ndk sets the armeabi-v7 version
> by default, and osgAndroid is configured with armeabi in the Application.mk
> maybe that is giving some troubles.
>
> Rafa.

OK, now all the builds seem fine so far. I'm now trying to use the osgsimple
example application. Do i need to copy libs from the org.openscenegraph.android
project? Building of the example android app succeeded, but i get the following
runtime errors.

11-18 13:35:34.280: D/dalvikvm(7238): Added shared lib /data/app-lib/org.openscenegraph.osgsimple-1/libjniosg-gles1.so 0x42655be0
11-18 13:35:34.280: D/dalvikvm(7238): No JNI_OnLoad found in /data/app-lib/org.openscenegraph.osgsimple-1/libjniosg-gles1.so 0x42655be0, skipping init
...
11-18 13:35:34.300: I/org.openscenegraph.osg.viewer.JNIViewer(7238): Warning: dynamic library 'osgPlugins-3.3.3/osgdb_osg.so' does not exist (or isn't readable):
11-18 13:35:34.300: I/org.openscenegraph.osg.viewer.JNIViewer(7238): dlopen failed: library "osgPlugins-3.3.3/osgdb_osg.so" not found
11-18 13:35:34.300: I/org.openscenegraph.osg.viewer.JNIViewer(7238): DynamicLibrary::failed loading "osgPlugins-3.3.3/osgdb_osg.so"
11-18 13:35:34.300: E/org.openscenegraph.osg.db.JNIosgDB(7238): Error loading scene
...
11-18 13:35:34.310: E/AndroidRuntime(7238): FATAL EXCEPTION: main
11-18 13:35:34.310: E/AndroidRuntime(7238): Process: org.openscenegraph.osgsimple, PID: 7238
11-18 13:35:34.310: E/AndroidRuntime(7238): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.openscenegraph.osgsimple/org.openscenegraph.osgsimple.OSGActivity}: java.lang.NullPointerException: println needs a message

Thanks a lot,

Rafa Gaitan

unread,
Nov 18, 2014, 10:45:41 AM11/18/14
to OpenSceneGraph Users
Hi,

I'm using eclipse and as long as the jni library is compiled is automatically copied and deployed within the APK. Sometimes I need to do a refresh of the projects (F5), to actually detect the changes and the compiled libraries.

In fact, reading the log the JNI library is corerctly loaded, the problem there should be that you don't have uploaded the model to the device. I haven't implemented a mechanism to read data from the assets. You can take a look at the code, and change it accordingly but the example expects the cessna.osg model in the directory:

File externalStorage = Environment.getExternalStorageDirectory();
String path = externalStorage + "/osgAndroid/cessna.osg";

External storage usually is placed in /sdcard, but it depends on your device.

Regards,
Rafa.

Julius Haertl

unread,
Nov 18, 2014, 11:32:03 AM11/18/14
to OpenSceneGraph Users
On Tue, Nov 18, 2014 at 04:45:37PM +0100, Rafa Gaitan wrote:
> Hi,
>
> I'm using eclipse and as long as the jni library is compiled is
> automatically copied and deployed within the APK. Sometimes I need to do a
> refresh of the projects (F5), to actually detect the changes and the
> compiled libraries.
>
> In fact, reading the log the JNI library is corerctly loaded, the problem
> there should be that you don't have uploaded the model to the device. I
> haven't implemented a mechanism to read data from the assets. You can take
> a look at the code, and change it accordingly but the example expects the
> cessna.osg model in the directory:
>
> File externalStorage = Environment.getExternalStorageDirectory();
> String path = externalStorage + "/osgAndroid/cessna.osg";
>
> External storage usually is placed in /sdcard, but it depends on your
> device.
>
> Regards,
> Rafa.
>

Sorry for that silly question, seems obious, that it fails if there is no
example object to be loaded. Now everything works fine.

Thank you so much for the quick help.
Reply all
Reply to author
Forward
0 new messages