Link error on Android - android

When compiling native code on android I am experiencing a problem :
CMakeFiles/test_v_job.dir/test_v_job.cpp.o:test_v_job.cpp:function
boost::detail::signal_handler::~signal_handler(): error: undefined
reference to 'sigaltstack'
CMakeFiles/test_v_job.dir/test_v_job.cpp.o:test_v_job.cpp:function
boost::detail::signal_handler::signal_handler(bool, int, bool, char*):
error: undefined reference to 'sigaltstack'
CMakeFiles/test_v_job.dir/test_v_job.cpp.o:test_v_job.cpp:function
boost::detail::signal_handler::signal_handler(bool, int, bool, char*):
error: undefined reference to 'sigaltstack' collect2: ld returned 1
exit status
signal.h header file is in the directory : C:\AndroidSDKS\android-ndk-r7-crystax\platforms\android-9\arch-arm\usr\include
What must be linked?

this error is caused probably by old platform of android-ndk,it should be compiled with at least android-9 or higher
it has nothing to do with boost libs
for example if you use ndk-build you schould add to Application.mk those lines:
APP_ABI := armeabi
APP_PLATFORM := android-9

To build the boost under ANDROID NDK I use github.com/MysticTreeGames/Boost-for-Android – e.proydakov

Related

Undefined reference to 'jniRegisterNativeMethods' Android NDK

I'm trying to build the .so file from available NDK project. But I encounter the
undefined reference to 'jniRegisterNativeMethods' error when I try to compile the code using cmd with ndk-build
Here I'm posting the block of that execution
Android NDK: WARNING:jni/Android.mk:gba: non-system libraries in linker flags: -lnativehelper
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++ arm : gba <= emulator.cpp
[armeabi] SharedLibrary : libgba.so
C:/sdk/android-ndk-r10e-windows-x86_64/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: error: cannot find -lnativehelper
jni/gbalib/nativehelper/JNIHelp.h:108: error: undefined reference to 'jniRegisterNativeMethods'
collect2.exe: error: ld returned 1 exit status
make.exe: *** [obj/local/armeabi/libgba.so] Error 1
E:\Android-Projects-Archieve\Library-Archives\gameboid>
I expect it to build an .so file called libgba.so Let me know in the comments if you need more info to look into this issue. Thanks in advance.

Android NDK error: undefined reference

There have been some questions similar to mine, but it seems that their solutions don't work for me.
I'm trying to compile dumpsys source code using Android NDK. I have added a couple of lines to Android.mk to include the libraries.
The final Android.mk file looks like this:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
dumpsys.cpp
LOCAL_SHARED_LIBRARIES := \
libutils \
liblog \
libbinders
ANDROID_SRC="my android source directory"
LOCAL_C_INCLUDES := ${ANDROID_SRC}/frameworks/native/include \
${ANDROID_SRC}/system/core/include
#$(warning $(TARGET_C_INCLUDES))
LOCAL_MODULE:= dumpsys
TARGET_ARCH := arm
TARGET_ARCH_ABI := armeabi-v7a
include $(BUILD_EXECUTABLE)
when I execute ndk-build, I get the following errors:
/home/mahdi/university/androidsource/system/core/include/utils/TypeHelpers.h:144: error: undefined reference to 'android::String16::~String16()'
/home/mahdi/university/androidsource/system/core/include/utils/Vector.h:240: error: undefined reference to 'android::VectorImpl::finish_vector()'
/home/mahdi/university/androidsource/system/core/include/utils/Vector.h:241: error: undefined reference to 'android::VectorImpl::~VectorImpl()'
/home/mahdi/university/androidsource/system/core/include/utils/TypeHelpers.h:135: error: undefined reference to 'android::String16::String16()'
/home/mahdi/university/androidsource/system/core/include/utils/TypeHelpers.h:154: error: undefined reference to 'android::String16::String16(android::String16 const&)'
/home/mahdi/university/androidsource/system/core/include/utils/TypeHelpers.h:166: error: undefined reference to 'android::String16::String16(android::String16 const&)'
/home/mahdi/university/androidsource/system/core/include/utils/String16.h:178: error: undefined reference to 'strzcmp16'
/home/mahdi/university/androidsource/system/core/include/utils/StrongPointer.h:143: error: undefined reference to 'android::RefBase::decStrong(void const*) const'
jni/dumpsys.cpp:32: error: undefined reference to 'android::defaultServiceManager()'
jni/dumpsys.cpp:35: error: undefined reference to '__android_log_print'
/home/mahdi/university/androidsource/system/core/include/utils/Vector.h:224: error: undefined reference to 'android::VectorImpl::VectorImpl(unsigned int, unsigned int)'
/home/mahdi/university/androidsource/system/core/include/utils/Vector.h:224: error: undefined reference to 'android::VectorImpl::VectorImpl(unsigned int, unsigned int)'
/home/mahdi/university/androidsource/system/core/include/utils/Vector.h:245: error: undefined reference to 'android::VectorImpl::operator=(android::VectorImpl const&)'
/home/mahdi/university/androidsource/system/core/include/utils/Vector.h:378: error: undefined reference to 'android::VectorImpl::sort(int (*)(void const*, void const*))'
jni/dumpsys.cpp:49: error: undefined reference to 'android::String16::String16(char const*)'
/home/mahdi/university/androidsource/system/core/include/utils/Vector.h:338: error: undefined reference to 'android::VectorImpl::add(void const*)'
jni/dumpsys.cpp:49: error: undefined reference to 'android::String16::~String16()'
jni/dumpsys.cpp:51: error: undefined reference to 'android::String16::String16(char const*)'
/home/mahdi/university/androidsource/system/core/include/utils/Vector.h:338: error: undefined reference to 'android::VectorImpl::add(void const*)'
jni/dumpsys.cpp:51: error: undefined reference to 'android::String16::~String16()'
jni/dumpsys.cpp:53: error: undefined reference to 'android::String16::String16(char const*)'
/home/mahdi/university/androidsource/system/core/include/utils/Vector.h:338: error: undefined reference to 'android::VectorImpl::add(void const*)'
jni/dumpsys.cpp:53: error: undefined reference to 'android::String16::~String16()'
jni/dumpsys.cpp:66: error: undefined reference to 'android::operator<<(android::TextOutput&, android::String16 const&)'
jni/dumpsys.cpp:81: error: undefined reference to 'android::operator<<(android::TextOutput&, android::String16 const&)'
jni/dumpsys.cpp:89: error: undefined reference to 'android::operator<<(android::TextOutput&, android::String16 const&)'
/home/mahdi/university/androidsource/system/core/include/utils/StrongPointer.h:143: error: undefined reference to 'android::RefBase::decStrong(void const*) const'
jni/dumpsys.cpp:94: error: undefined reference to 'android::aerr'
jni/dumpsys.cpp:94: error: undefined reference to 'android::aout'
collect2: error: ld returned 1 exit status
How should I solve this issue?
Thanks in advance.
I'm working on a similar issue here.
Basically, dumpsys is an AOSP component and intended to be built with the AOSP toolchain. You will need to apply some tweaks to port it to NDK – including stuff from ${ANDROID_SRC} is the first step but not the whole story.
You've successfully included the headers and thus made the compiler happy. Now the linker is complaining because it cannot find the libraries you are linking against. The good news is that they are shared libraries, thus having the libraries around at build time isn't a strict requirement.
The NDK defines a stable API of libraries you can use, which is documented here. liblog is in that list and can be included by adding the following lines to Android.mk:
LOCAL_LDLIBS := \
-llog \
The other two libraries are not part of the stable API. This essentially means that even if your code works on a particular version of Android, it may break on any later version because the API may have changed – you might want to bear this in mind.
Since these libraries are shared, all ld does is check if they actually provide the functions you're using. This question and its accepted answer have instructions for getting rid of the related error messages:
One way is to use something like:
LOCAL_LDFLAGS := -Wl,--unresolved-symbols=ignore-all
However, this will bypass all checks – so if you try to use a function that is indeed absent from the library, ld has no chance of warning you.
The cleaner, but more work-intensive approach, is to provide stub libraries. A stub library is essentially a dummy library which defines the same symbols (functions etc.) as the "real" thing but has no implementation (functions simply return without doing anything). It's enough to make the linker happy, but the libraries are not shipped and their "real" counterparts are used at runtime.
You would need to get the source code for the two libraries, which reside in the following directories: libutils and libbinders
system/core/libutils
frameworks/native/libs/binder
Copy these two dirs into your project's jni dir. Then strip the code down:
* Edit Android.mk, removing all build targets other than BUILD_SHARED_LIBRARY.
* Edit the source code files, replacing all function bodies with a simple return. It doesn't matter what you return, as long as you get the code to compile.
Eventually you will probably need to prevent the stub libraries from getting included in your .apk (I have yet to figure out how to do that).

Sample Android NDK hello-gl2 unable to compile on Android Studio

I'm able to run the hello-jni of the samples provided in the NDK but I can't compile the hello-gl2 sample.
Could you help me? (I think is a problem linking with OpenGL)
This are the errors reported by Android Studio:
C:\AndroidstudioProjects\hello-gl2\app\src\main\jni\gl_code.cpp
Error:(39) undefined reference to `glGetError'
Error:(41) undefined reference to `__android_log_print'
Error:(40) undefined reference to `glGetError'
Error:(34) undefined reference to `glGetString'
Error:(35) undefined reference to `__android_log_print'
Error:(58) undefined reference to `glCreateShader'
Error:(60) undefined reference to `glShaderSource'
Error:(61) undefined reference to `glCompileShader'
Error:(63) undefined reference to `glGetShaderiv'
Error:(66) undefined reference to `glGetShaderiv'
Error:(70) undefined reference to `glGetShaderInfoLog'
Error:(72) undefined reference to `__android_log_print'
Error:(75) undefined reference to `glDeleteShader'
...
In your Android.mk file (in the /jni folder), there should be a LOCAL_LDLIBS line. Some of the libraries that come bundled with Android need to be indicated here. Try the following
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv1_CM
Or at least add the options -lEGL and -lGLESv1_CM. The first is the EGL library, and the second is the GLES library.
I don't know if the last one is the right version number for your project though.
Finally I used eclipse (for those that are dealing with the same problems) and with Eclipse all went fine.

Undefined Reference to android::LPAPlayer::*

I am having great difficulty with a step in compiling CyanogenMod 11(Android 4.4) for an unsupported device based on an MSM7x27A/Snapdragon S1 platform. When I attempt to build libstagefright, I come up with an undefined reference error to functions in android::LPAPlayer::*, including the constructor. The error I get is:
Copying: /home/dyngar-f/android/android/out/target/common/obj/JAVA_LIBRARIES/mms-common_intermediates/noproguard.classes.jar
frameworks/av/media/libstagefright/AwesomePlayer.cpp:1282: error: undefined reference to 'android::LPAPlayer::LPAPlayer(android::sp<android::MediaPlayerBase::AudioSink> const&, bool&, android::AwesomePlayer*)'
frameworks/av/media/libstagefright/AwesomePlayer.cpp:1306: error: undefined reference to 'android::LPAPlayer::mObjectsAlive'
frameworks/av/media/libstagefright/AwesomePlayer.cpp:1882: error: undefined reference to 'android::LPAPlayer::mObjectsAlive'
collect2: error: ld returned 1 exit statusbuild/core/shared_library.mk:81: recipe for target '/home/dyngar-f/android/android/out/target/product/schS738c/obj/SHARED_LIBRARIES/libstagefright_intermediates/LINKED/libstagefright.so' failed
make: *** [/home/dyngar-f/android/android/out/target/product/schS738c/obj/SHARED_LIBRARIES/libstagefright_intermediates/LINKED/libstagefright.so] Error 1make: *** Waiting for unfinished jobs....
I have searched high and low and I found no mention of this error that leads me to a solution to this problem, and I haven't arrived at a solution myself. Here are the references to this issue I have found from others:
Gist from CMartinBaughman
Mentioned in XDA Thread on this page there is also an answer that doesn't seem to work.
Can anyone guide me to a solution for this issue?
The error is coming from the linker which is unable to find the reference to LPAPlayer which is actually a customization in CyanogenMod sources. From the latest tree, Android.mk for libstagefright is not including LPAPlayer.cpp for all platforms.
To resolve your issue, please try by adding the following files in Android.mk between lines 114-117
#New lines included
ifeq ($(call is-chipset-in-board-platform,msm7x27),true)
LOCAL_SRC_FILES += LPAPlayer.cpp
LOCAL_CFLAGS += -DLEGACY_LPA -DUSE_LPA_MODE
endif
ifeq ($(call is-chipset-in-board-platform,msm7x30),true)
LOCAL_SRC_FILES += LPAPlayer.cpp
LOCAL_CFLAGS += -DLEGACY_LPA -DUSE_LPA_MODE
endif
The platform name may need to be modified to suit the actual name (Please refer to BoardConfig.mk).

Linker errors in Android NDK (undefined reference to `__cxa_end_cleanup')

I'm getting this output after adding in a set of code from a colleague:
./obj/local/armeabi/objs/jniWrapper/native.o: In function `_Vector_base':
D:/opt/android-ndk/sources/cxx-stl/stlport/stlport/stl/_vector.h:73: undefined reference to `__cxa_end_cleanup'
./obj/local/armeabi/objs/jniWrapper/native.o:(.ARM.extab.text._ZNSt6vectorIhSaIhEEC1ERKS1_[std::vector<unsigned char, std::allocator<unsigned char> >::vector(std::vector<unsigned char, std::allocator<unsigned char> > const&)]+0x0): undefined reference to `__gxx_personality_v0'
./obj/local/armeabi/objs/jniWrapper/native.o: In function `std::__node_alloc::deallocate(void*, unsigned int)':
D:/opt/android-ndk/sources/cxx-stl/stlport/stlport/stl/_alloc.h:161: undefined reference to `__cxa_end_cleanup'
./obj/local/armeabi/objs/jniWrapper/native.o:(.ARM.extab.text._ZNSt4priv12_String_baseIcSaIcEED2Ev[std::priv::_String_base<char, std::allocator<char> >::~_String_base()]+0x0): undefined reference to `__gxx_personality_v0'
./obj/local/armeabi/objs/jniWrapper/native.o: In function `basic_string':
D:/opt/android-ndk/sources/cxx-stl/stlport/stlport/stl/_string.c:643: undefined reference to `__cxa_end_cleanup'
This is caused because I don't have access to the correct STL.
To my knowledge there are only three I can choose from (stlport_static, stlport_shared, system) as set by APP_STL := stlport_static in Application.mk.
Is there another library available to the NDK?
After reading android-ndk/docs/CPLUSPLUS-SUPPORT.html I found that there a couple more libraries that I can link to:
C++ C++ Standard
Exceptions RTTI Library
system no no no
gabi++ no yes no
stlport no yes yes
gnustl yes yes yes
This stops my linker errors (and pushes the build onto a new set of errors :))
Application.mk
APP_STL := gnustl_static
Take a look here: Linux C++: Linker is outputting strange errors.
In Android's Application.mk this would be:
APP_CPPFLAGS := -frtti
You can fix this problem by adding the compiler option -lsupc++.
Edited:
The reason: your code is using C++ exception mechanism which compiler automatically generate try/catch/finally block hidden code which in turn call __cxa_end_cleanup somewhere.
lsupc++ means link to libsupc++.a
Another way to resolve this problem is add -fno-exceptions option to gcc which obviously means disable exception handler mechanism.
BTW, you should also add -fno-rtti to avoid other maybe-encountered compilation error, this is because
all android's C++ class is compiled without dynamic type info in class memory layout.
In a word, you shoud use one of these option combos:
1. -fno-rtti -fno-exceptions
2. -fno-rtti -lsupc++
In my case, the error undefined reference to __cxa_end_cleanup shows up when I add -fexceptions to the compiler options. When removing that option, the undefined ref goes away, but that means you have to clear your code from exception statements.
for me that meant adding -fno-rrti and -fno-exceptions then getting rid of "throw char*" in the code which took care of both.

Categories

Resources