I am using https://github.com/lilac/Android-ImageMagick to build an ImageMagick library for Android. When trying to ndk-build ImageMagick I end up with the below errors.
primary0:AndroidMagickActivity primary0$ ~/ndk/ndk-build
SharedLibrary : libandroid-magick.so
/Users/primary0/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/libcoders.a(jpeg.o): in function ReadJPEGImage:jni/../ndk-modules/ImageMagick-6.7.3-0/coders/jpeg.c:988: error: undefined reference to 'jpeg_std_error'
/Users/primary0/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/libcoders.a(jpeg.o): in function ReadJPEGImage:jni/../ndk-modules/ImageMagick-6.7.3-0/coders/jpeg.c:995: error: undefined reference to 'jpeg_destroy_decompress'
/Users/primary0/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/libcoders.a(jpeg.o): in function ReadJPEGImage:jni/../ndk-modules/ImageMagick-6.7.3-0/coders/jpeg.c:1004: error: undefined reference to 'jpeg_CreateDecompress'
/Users/primary0/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/libcoders.a(jpeg.o): in function ReadJPEGImage:jni/../ndk-modules/ImageMagick-6.7.3-0/coders/jpeg.c:1006: error: undefined reference to 'jpeg_set_marker_processor'
/Users/primary0/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/libcoders.a(jpeg.o): in function ReadJPEGImage:jni/../ndk-modules/ImageMagick-6.7.3-0/coders/jpeg.c:1007: error: undefined reference to 'jpeg_set_marker_processor'
/Users/primary0/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/libcoders.a(jpeg.o): in function ReadJPEGImage:jni/../ndk-modules/ImageMagick-6.7.3-0/coders/jpeg.c:1008: error: undefined reference to 'jpeg_set_marker_
.
.
.
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/libandroid-magick.so] Error 1
primary0:AndroidMagickActivity primary0$
The header file that defines the constants listed in the error is included jpeg.c
#include "jpeglib.h"
Any of you guys have an idea why I'm getting the undefined reference error?
The linker is not looking for "constants" it's looking for jump addresses to call functions. Your code obviously uses functions which are not available in the object code. This can have various reasons. Either you did not tell the compiler to use a library which is availabe or (in your case more likely) you did not tell the compiler that jpeg.c also needs to be compiled for this shared object. But this is difficult to diagnose without seeing the makefile.
Taking a short look at the ndk-modules folder of the git repository I get the feeling you need to build multiple modules. Maybe you just do it in the wrong order. Try building jpeg first.
Related
I am trying to compile openssl for android and facing some issues. I am following the steps given in this link.
I am using NDK version r20 and OpenSSL 1.1.1c and on a linux machine.
I am facing two issues:
(1) I am able to compile libs for “android-arm” architecture but getting the below errors while compiling sample application.
./libcrypto.so: error: undefined reference to ‘sigdelset’
./libcrypto.so: error: undefined reference to ‘sigfillset’
./libcrypto.so: error: undefined reference to ‘tcgetattr’
./libcrypto.so: error: undefined reference to ‘tcsetattr’
apps/ocsp.o:ocsp.c:function ocsp_main: error: undefined reference to ‘signal’
apps/ocsp.o:ocsp.c:function ocsp_main: error: undefined reference to ‘signal’
apps/ocsp.o:ocsp.c:function ocsp_main: error: undefined reference to ‘signal’
apps/ocsp.o:ocsp.c:function ocsp_main: error: undefined reference to ‘signal’
apps/ocsp.o:ocsp.c:function process_responder: error: undefined reference to ‘__FD_SET_chk’
apps/ocsp.o:ocsp.c:function process_responder: error: undefined reference to ‘__FD_SET_chk’
apps/s_client.o:s_client.c:function s_client_main: error: undefined reference to ‘__FD_SET_chk’
apps/s_client.o:s_client.c:function s_client_main: error: undefined reference to ‘__FD_SET_chk’
apps/s_client.o:s_client.c:function s_client_main: error: undefined reference to ‘__FD_ISSET_chk’
apps/s_client.o:s_client.c:function s_client_main: error: undefined reference to ‘__FD_ISSET_chk’
apps/s_client.o:s_client.c:function s_client_main: error: undefined reference to ‘__FD_ISSET_chk’
apps/s_client.o:s_client.c:function s_client_main: error: undefined reference to ‘__FD_ISSET_chk’
apps/speed.o:speed.c:function speed_main: error: undefined reference to ‘atof’
apps/speed.o:speed.c:function speed_main: error: undefined reference to ‘atof’
apps/speed.o:speed.c:function speed_main: error: undefined reference to ‘atof’
apps/speed.o:speed.c:function speed_main: error: undefined reference to ‘atof’
clang: error: linker command failed with exit code 1 (use -v to see invocation)
(2) I am not able to compile for any other architecture. If I change architecture to “android-arm64” (or any other), I am getting the below errors while compiling library.
crypto/aes/aesv8-armx.S:5:1: error: Unknown arch name
.arch armv8-a+crypto
^
crypto/aes/aesv8-armx.S:17:2: error: invalid instruction, did you mean: stc, stm, str, swp, tst?
stp x29,x30,[sp,#-16]!
^
crypto/aes/aesv8-armx.S:18:6: error: operand must be a register in range [r0, r15]
add x29,sp,#0
^
crypto/aes/aesv8-armx.S:19:6: error: operand must be a register in range [r0, r12] or r14
mov x3,#-1
^
I am changing the architecture by changing the “architecture=android-arm” in the “file-launcher-sh”. Do I need to modify any other variables/macros?
You built openssl for a newer API level than your app, so the library is not compatible with your app. Here's how I build openssl with r20:
$ export ANDROID_NDK=/path/to/ndk
$ export PATH=$ANDROID_NDK/toolchains/llvm/prebuilt/$HOST/bin:$PATH
$ path/to/openssl/Configure android-$ARCH -D__ANDROID_API__=$MINSDKVERSION --prefix=$INSTALLPATH --openssldir=$INSTALLPATH shared
$ make SHLIB_EXT=.so install_sw
I just had to open new putty for each new architecture.
I think somehow few of the configurations/variables exported for one architecture are not getting updated when I re-run the script with new architecture.
Add the compiler flag "no-asm" to ./Configure
./Configure no-asm no-shared android-$ARCH -D__ANDROID_API__=$MINSDKVERSION --prefix=$INSTALLPATH --openssldir=$INSTALLPATH shared
I'm trying to cross-compile ncurses using android-ndk but compilation error shows halfway the process.
Command:
CC=~/my-toolchain/bin/arm-linux-androideabi-gcc ./configure --host=arm-linux-androideabi --prefix=/Android
Output:
** Configuration summary for NCURSES 6.0 20150808:
extended funcs: yes
xterm terminfo: xterm-new
bin directory: /Android/bin
lib directory: /Android/lib
include directory: /Android/include/ncurses
man directory: /Android/share/man
terminfo directory: /Android/share/terminfo
** Include-directory is not in a standard location
Command
make
Output
../objects/tic.o:tic.c:function usage: error: undefined reference to 'stderr'
../objects/tic.o:tic.c:function put_translate: error: undefined reference to 'stdout'
../objects/tic.o:tic.c:function copy_input: error: undefined reference to 'stderr'
../objects/tic.o:tic.c:function open_input: error: undefined reference to 'stdin'
../objects/tic.o:tic.c:function open_input: error: undefined reference to 'stderr'
../objects/tic.o:tic.c:function show_databases: error: undefined reference to 'stdout'
../objects/tic.o:tic.c:function show_databases: error: undefined reference to 'stderr'
../objects/dump_entry.o:dump_entry.c:function show_entry: error: undefined reference to 'stdout'
../objects/dump_entry.o:dump_entry.c:function compare_entry: error: undefined reference to 'stdout'
../lib/libncurses.a(lib_twait.o):lib_twait.c:function _nc_timed_wait: error: undefined reference to '__FD_SET_chk'
../lib/libncurses.a(lib_twait.o):lib_twait.c:function _nc_timed_wait: error: undefined reference to '__FD_SET_chk'
../lib/libncurses.a(lib_twait.o):lib_twait.c:function _nc_timed_wait: error: undefined reference to '__FD_ISSET_chk'
../lib/libncurses.a(lib_twait.o):lib_twait.c:function _nc_timed_wait: error: undefined reference to '__FD_ISSET_chk'
collect2: error: ld returned 1 exit status
Makefile:242: recipe for target 'tic' failed
make[1]: *** [tic] Error 1
make[1]: Leaving directory '/home/jrm/softether/src/curses/ncurses-6.0/progs'
Makefile:113: recipe for target 'all' failed
make: *** [all] Error 2
I don't have any idea about the error. I tried using google but i can't seem to find similar problems like mine.
The usual reason for this error is that you've compiled against android-23 or higher but are linking against something earlier. Another variation of that issue is when you have multiple libraries built against different API levels.
It looks like you are using a standalone toolchain? If that's correct, then I'd suspect your issue is either a prebuilt library that's part of libcurses (FWIR there aren't any of those, so unlikely) or that there's something funky going on in their build scripts that causes one of the two issues I mentioned. Tons of projects add their own Android specific hacks to their build scripts that always end up being the cause of these sorts of issues, so that wouldn't surprise me at all.
Should look at both the compilation command for tic.c and the link command for whatever library/executable is failing to link there. Make sure both are using the same API levels (look for things like $NDK/platforms/android-$API_LEVEL, -D__ANDROID_API__=$API_LEVEL, and -target arm-linux-androideabi$API_LEVEL).
btw, not ncurses 6, but I do have an example showing how to use standalone toolchains that had to build ncurses 5.9: https://github.com/DanAlbert/lua-ndk/blob/master/build_lua_with_libreadline.sh#L75. Might be worth taking a look to see if that helps at all.
I have troubles to run the GStreamer tutorials. I followed all tutorial steps, and run into an error.
My System:
android-ndk-r11c, gstreamer-sdk-android-arm-debug-2013.6
My System: Windows 10 - 64 bit
The Error:
C:\gstreamer-sdk-android-arm-debug-2013.6\share\gst-sdk\tutorials\android-tutorial-1>ndk-build
GStreamer : [GEN] => gst-build/gstreamer_android.c
GStreamer : [COMPILE] => gst-build/gstreamer_android.c
GStreamer : [LINK] => gst-build/libgstreamer_android.so
lex.priv_gst_parse_yy.c:1598: error: undefined reference to '__srget'
gutils.c:2406: error: undefined reference to 'issetugid'
localcharset.c:158: error: undefined reference to '__srget'
localcharset.c:167: error: undefined reference to '__srget'
./localcharset.c:195: error: undefined reference to '__srget'
/home/slomo/Projects/android/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.7/include-fixed/stdio.h:376: error: undefined reference to '__swbuf'
collect2.exe: error: ld returned 1 exit status
make: *** [buildsharedlibrary] Error 1
C:\gstreamer-sdk-android-arm-debug-2013.6\share\gst-sdk\tutorials\android-tutorial-1>
I tried:
Windows linkage problems : Due to problems related to the standard linker, Google’s Gold Linker is used to build GStreamer applications. Unfortunately, the Android NDK toolchain for Windows does not include the gold linker and the standard one has to be used.
If you observe linkage problems, you can replace the linker in your Android NDK with the gold one from this project. Download the android-ndk-r8b-ma-windows.7z file, extract \android-ndk-r8b\toolchains\arm-linux-androideabi-4.6\prebuilt\windows\arm-linux-androideabi\bin\ld.exe (only this file is needed) and overwrite the one in the same folder in your Android NDK installation.
No effect. Any ideas how to solve this?
I had similar problem before please give a try with ndk10b.It is always good to check in header files for __srget before move forward.
How to solve the compile error?
error: undefined reference to 'ntohl'
collect2: error: ld returned 1 exit status
I use the android-ndk-r10d.
When building with the Android NDK, ntohl and the other functions for converting between network and host byte order are #defines present in the header <sys/endian.h>. So including that header should fix your compilation error.
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).